LuaFunctions.cpp 388 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = spawn->GetZone()->GetClientBySpawn(player);
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  374. }
  375. else
  376. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if (!luaspell)
  1229. return 0;
  1230. Spawn* caster = luaspell->caster;
  1231. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1232. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1233. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1234. Spawn* target = lua_interface->GetSpawn(state, 4);
  1235. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1236. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1237. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1238. lua_interface->ResetFunctionStack(state);
  1239. boost::to_lower(heal_type);
  1240. if (caster && caster->IsEntity()) {
  1241. bool success = false;
  1242. luaspell->resisted = false;
  1243. if (target) {
  1244. float distance = caster->GetDistance(target, true);
  1245. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1246. success = true;
  1247. }
  1248. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1249. Spawn* target = 0;
  1250. ZoneServer* zone = luaspell->caster->GetZone();
  1251. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1253. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1254. float distance = caster->GetDistance(target, true);
  1255. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1256. }
  1257. }
  1258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1259. success = true;
  1260. }
  1261. if (success) {
  1262. if (caster->GetZone())
  1263. caster->GetZone()->TriggerCharSheetTimer();
  1264. }
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1272. if (!luaspell)
  1273. return 0;
  1274. Spawn* caster = luaspell->caster;
  1275. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1276. float percentage = lua_interface->GetFloatValue(state, 2);
  1277. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1278. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1279. Spawn* target = lua_interface->GetSpawn(state, 5);
  1280. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1281. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1282. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1283. lua_interface->ResetFunctionStack(state);
  1284. boost::to_lower(heal_type);
  1285. int32 min_heal = 0, max_heal = 0;
  1286. if (caster && caster->IsEntity() && target) {
  1287. if(percentage <= 0.0f)
  1288. {
  1289. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1290. return 0;
  1291. }
  1292. if(heal_type == "power")
  1293. {
  1294. if(current_value)
  1295. {
  1296. if(caster_value)
  1297. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1298. else
  1299. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1300. }
  1301. else
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(current_value)
  1312. {
  1313. if(caster_value)
  1314. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1315. else
  1316. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1317. }
  1318. else
  1319. {
  1320. if(caster_value)
  1321. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1322. else
  1323. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1324. }
  1325. }
  1326. bool success = false;
  1327. luaspell->resisted = false;
  1328. if (target) {
  1329. float distance = caster->GetDistance(target, true);
  1330. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1331. success = true;
  1332. }
  1333. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1334. Spawn* target = 0;
  1335. ZoneServer* zone = luaspell->caster->GetZone();
  1336. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1337. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1338. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1339. float distance = caster->GetDistance(target, true);
  1340. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1341. }
  1342. }
  1343. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1344. success = true;
  1345. }
  1346. if (success) {
  1347. if (caster->GetZone())
  1348. caster->GetZone()->TriggerCharSheetTimer();
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_AddItem(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. Spawn* spawn = lua_interface->GetSpawn(state);
  1357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1358. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1359. lua_interface->ResetFunctionStack(state);
  1360. // default of 1 quantity to add
  1361. if (quantity == 0)
  1362. quantity = 1;
  1363. if (spawn && spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client && item_id > 0) {
  1366. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1367. return 1;
  1368. }
  1369. }
  1370. lua_interface->SetBooleanValue(state, false);
  1371. return 1;
  1372. }
  1373. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1378. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1379. string location = lua_interface->GetStringValue(state, 4);
  1380. int16 item_count = lua_interface->GetInt16Value(state,5);
  1381. //devn00b: if we dont have a count, assume 1 item.
  1382. if(!item_count) {
  1383. item_count = 1;
  1384. }
  1385. lua_interface->ResetFunctionStack(state);
  1386. if (spawn && spawn->IsPlayer()) {
  1387. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1388. if (client && item_id > 0) {
  1389. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1390. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1391. else
  1392. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1393. if (send_messages) {
  1394. Item* item = master_item_list.GetItem(item_id);
  1395. if (item) {
  1396. if(item_count > 1) {
  1397. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1398. string popup_text1 = "You receive "+ item_count;
  1399. string popup_text2 = " " + item->name;
  1400. string popup_text = popup_text1 + popup_text2;
  1401. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1402. // return 1;
  1403. } else {
  1404. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1405. string popup_text = "You receive " + item->name;
  1406. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1407. }
  1408. }
  1409. }
  1410. return 1;
  1411. }
  1412. }
  1413. lua_interface->SetBooleanValue(state, false);
  1414. return 1;
  1415. }
  1416. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1417. Spawn* spawn = lua_interface->GetSpawn(state);
  1418. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1419. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1420. lua_interface->ResetFunctionStack(state);
  1421. // default of 1 to remove
  1422. if (quantity == 0)
  1423. quantity = 1;
  1424. Client* client;
  1425. Item* item;
  1426. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1427. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1428. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1429. if (client->RemoveItem(item, quantity)) {
  1430. lua_interface->SetBooleanValue(state, true);
  1431. return 1;
  1432. }
  1433. }
  1434. }
  1435. }
  1436. lua_interface->SetBooleanValue(state, false);
  1437. return 1;
  1438. }
  1439. int EQ2Emu_lua_HasItem(lua_State* state) {
  1440. Spawn* player = lua_interface->GetSpawn(state);
  1441. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1442. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1443. lua_interface->ResetFunctionStack(state);
  1444. if (player && player->IsPlayer()) {
  1445. bool hasItem = false;
  1446. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1447. if (!hasItem)
  1448. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1449. lua_interface->SetBooleanValue(state, hasItem);
  1450. return 1;
  1451. }
  1452. lua_interface->SetBooleanValue(state, false);
  1453. return 1;
  1454. }
  1455. int EQ2Emu_lua_Spawn(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. ZoneServer* zone = lua_interface->GetZone(state);
  1459. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1460. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1461. float x = lua_interface->GetFloatValue(state, 4);
  1462. float y = lua_interface->GetFloatValue(state, 5);
  1463. float z = lua_interface->GetFloatValue(state, 6);
  1464. float heading = lua_interface->GetFloatValue(state, 7);
  1465. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1466. Spawn* spawn = zone->GetSpawn(spawn_id);
  1467. if (!spawn)
  1468. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1469. else {
  1470. spawn->SetX(x);
  1471. spawn->SetZ(z);
  1472. spawn->SetY(y,true,true);
  1473. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1474. spawn->SetHeading(heading);
  1475. if (restricted_npc)
  1476. spawn->AddAllowAccessSpawn(spawn);
  1477. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1478. bool scriptActive = false;
  1479. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1480. scriptActive = true;
  1481. spawn->SetSpawnScript(string(spawn_script));
  1482. }
  1483. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1484. zone->AddSpawn(spawn);
  1485. if (scriptActive) {
  1486. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1487. }
  1488. lua_interface->ResetFunctionStack(state);
  1489. lua_interface->SetSpawnValue(state, spawn);
  1490. return 1;
  1491. }
  1492. }
  1493. else {
  1494. string output = "Invalid paramaters to LUA Spawn command: \n";
  1495. if (!zone)
  1496. output = output.append("\t").append("Missing zone reference. \n");
  1497. if (spawn_id == 0)
  1498. output = output.append("\t").append("Missing spawn_id.");
  1499. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1500. }
  1501. lua_interface->ResetFunctionStack(state);
  1502. return 0;
  1503. }
  1504. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1505. if (!lua_interface)
  1506. return 0;
  1507. ZoneServer* zone = lua_interface->GetZone(state);
  1508. lua_interface->ResetFunctionStack(state);
  1509. if (zone) {
  1510. lua_interface->SetStringValue(state, zone->GetZoneName());
  1511. return 1;
  1512. }
  1513. return 0;
  1514. }
  1515. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1516. if (!lua_interface)
  1517. return 0;
  1518. ZoneServer* zone = lua_interface->GetZone(state);
  1519. lua_interface->ResetFunctionStack(state);
  1520. if (zone) {
  1521. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1522. return 1;
  1523. }
  1524. return 0;
  1525. }
  1526. int EQ2Emu_lua_GetZone(lua_State* state) {
  1527. if (!lua_interface)
  1528. return 0;
  1529. int32 zone_id = lua_interface->GetInt32Value(state);
  1530. ZoneServer* zone = 0;
  1531. if (zone_id > 0)
  1532. zone = zone_list.Get(zone_id);
  1533. else {
  1534. string zone_name = lua_interface->GetStringValue(state);
  1535. if (zone_name.length() > 0) {
  1536. zone = zone_list.Get(zone_name.c_str());
  1537. }
  1538. else {
  1539. Spawn* spawn = lua_interface->GetSpawn(state);
  1540. if (spawn)
  1541. zone = spawn->GetZone();
  1542. }
  1543. }
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetZoneValue(state, zone);
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_AddHate(lua_State* state) {
  1552. Spawn* entity = lua_interface->GetSpawn(state);
  1553. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1554. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1555. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1556. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1557. if (entity && entity->IsEntity() && amount != 0) {
  1558. if (luaspell) {
  1559. ZoneServer* zone = luaspell->caster->GetZone();
  1560. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1561. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1562. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1563. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1564. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1565. if (send_packet)
  1566. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1567. }
  1568. }
  1569. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1570. }
  1571. else if (npc && npc->IsNPC() && npc->GetZone())
  1572. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1573. }
  1574. lua_interface->ResetFunctionStack(state);
  1575. return 0;
  1576. }
  1577. int EQ2Emu_lua_Zone(lua_State* state) {
  1578. if (!lua_interface)
  1579. return 0;
  1580. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1581. ZoneServer* zone = lua_interface->GetZone(state);
  1582. Spawn* player = lua_interface->GetSpawn(state, 2);
  1583. Client* client = 0;
  1584. if (player && player->IsPlayer())
  1585. client = player->GetZone()->GetClientBySpawn(player);
  1586. float x = lua_interface->GetFloatValue(state, 3);
  1587. float y = lua_interface->GetFloatValue(state, 4);
  1588. float z = lua_interface->GetFloatValue(state, 5);
  1589. float heading = lua_interface->GetFloatValue(state, 6);
  1590. if (zone && client) {
  1591. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1592. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1593. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1594. {
  1595. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1596. return 0;
  1597. }
  1598. if (x != 0 || y != 0 || z != 0) {
  1599. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1600. player->SetX(x);
  1601. player->SetY(y);
  1602. player->SetZ(z);
  1603. player->SetHeading(heading);
  1604. client->Zone(zone->GetZoneName(), false);
  1605. }
  1606. else
  1607. client->Zone(zone->GetZoneName());
  1608. }
  1609. else
  1610. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1611. lua_interface->ResetFunctionStack(state);
  1612. return 0;
  1613. }
  1614. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1615. if (!lua_interface)
  1616. return 0;
  1617. Spawn* spawn = lua_interface->GetSpawn(state);
  1618. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1619. if (spawn && spawn2)
  1620. spawn->AddAllowAccessSpawn(spawn2);
  1621. lua_interface->ResetFunctionStack(state);
  1622. return 0;
  1623. }
  1624. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1625. if (!lua_interface)
  1626. return 0;
  1627. Spawn* target = lua_interface->GetSpawn(state);
  1628. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1629. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1630. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1631. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1632. lua_interface->ResetFunctionStack(state);
  1633. if (!target) {
  1634. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1635. return 0;
  1636. }
  1637. if (!target->IsEntity()) {
  1638. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1639. return 0;
  1640. }
  1641. if (spell_id <= 0) {
  1642. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1643. return 0;
  1644. }
  1645. if (caster && !caster->IsEntity()) {
  1646. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1647. return 0;
  1648. }
  1649. if (spell_tier == 0)
  1650. spell_tier = 1;
  1651. if (!caster)
  1652. caster = target;
  1653. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* target = lua_interface->GetSpawn(state);
  1660. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1661. if (!luaspell)
  1662. return 0;
  1663. Spawn* caster = luaspell->caster;
  1664. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1665. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1666. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1667. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1668. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1669. //lua_interface->ResetFunctionStack(state);
  1670. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1671. vector<int16> faction_req;
  1672. vector<int16> race_req;
  1673. int32 class_req = 0;
  1674. int32 i = 0;
  1675. int8 f = 0;
  1676. int8 r = 0;
  1677. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1678. if (class_id < 100) {
  1679. class_req += pow(2.0, double(class_id - 1));
  1680. }
  1681. else if (class_id > 100 && class_id < 1000) {
  1682. race_req.push_back(class_id);
  1683. r++;
  1684. }
  1685. else {
  1686. faction_req.push_back(class_id);
  1687. f++;
  1688. }
  1689. i++;
  1690. }
  1691. lua_interface->ResetFunctionStack(state);
  1692. if (caster && caster->IsEntity()) {
  1693. bool race_match = false;
  1694. bool success = false;
  1695. luaspell->resisted = false;
  1696. if (luaspell->targets.size() > 0) {
  1697. ZoneServer* zone = luaspell->caster->GetZone();
  1698. Spawn* target = 0;
  1699. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1700. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1701. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1702. if (race_req.size() > 0) {
  1703. for (int8 i = 0; i < race_req.size(); i++) {
  1704. if (target->GetLuaRaceId() == race_req[i]) {
  1705. race_match = true;
  1706. }
  1707. }
  1708. }
  1709. else
  1710. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1711. if (race_match == true) {
  1712. float distance = caster->GetDistance(target, true);
  1713. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1714. }
  1715. }
  1716. }
  1717. success = true;
  1718. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1719. }
  1720. else if (target) {
  1721. //check class and race/faction here
  1722. if (race_req.size() > 0) {
  1723. for (int8 i = 0; i < race_req.size(); i++) {
  1724. if (target->GetLuaRaceId() == race_req[i]) {
  1725. race_match = true;
  1726. }
  1727. }
  1728. }
  1729. else
  1730. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1731. if (race_match == true) {
  1732. float distance = caster->GetDistance(target, true);
  1733. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1734. success = true;
  1735. }
  1736. }
  1737. if (success) {
  1738. Spell* spell = luaspell->spell;
  1739. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1740. ((Player*)caster)->InCombat(true);
  1741. if (caster->GetZone())
  1742. caster->GetZone()->TriggerCharSheetTimer();
  1743. }
  1744. }
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1749. if (!lua_interface)
  1750. return 0;
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1753. lua_interface->ResetFunctionStack(state);
  1754. if (spawn && value != 0) {
  1755. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1756. spawn->SetPower(spawn->GetTotalPower());
  1757. else
  1758. spawn->SetPower(spawn->GetPower() + value);
  1759. }
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1767. lua_interface->ResetFunctionStack(state);
  1768. if (spawn && value != 0) {
  1769. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1770. spawn->SetHP(spawn->GetTotalHP());
  1771. else
  1772. spawn->SetHP(spawn->GetHP() + value);
  1773. }
  1774. return 0;
  1775. }
  1776. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1777. if (!lua_interface)
  1778. return 0;
  1779. Spawn* spawn = lua_interface->GetSpawn(state);
  1780. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1781. lua_interface->ResetFunctionStack(state);
  1782. if (spawn && value != 0) {
  1783. spawn->SetPower(spawn->GetPower() + value);
  1784. if (value > spawn->GetTotalHPBase())
  1785. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn && value != 0) {
  1796. spawn->SetHP(spawn->GetHP() + value);
  1797. if (value > spawn->GetTotalHPBase())
  1798. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1799. }
  1800. return 0;
  1801. }
  1802. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1803. if (!lua_interface)
  1804. return 0;
  1805. Spawn* spawn = lua_interface->GetSpawn(state);
  1806. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1807. lua_interface->ResetFunctionStack(state);
  1808. if (spawn) {
  1809. spawn->SetHP(value);
  1810. if (value > spawn->GetTotalHPBase())
  1811. spawn->SetTotalHP(value);
  1812. }
  1813. return 0;
  1814. }
  1815. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1816. if (!lua_interface)
  1817. return 0;
  1818. Spawn* spawn = lua_interface->GetSpawn(state);
  1819. float value = lua_interface->GetFloatValue(state, 2);
  1820. lua_interface->ResetFunctionStack(state);
  1821. if (spawn && spawn->IsEntity() && value > 0)
  1822. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1823. if (spawn->IsPlayer())
  1824. ((Player*)spawn)->SetCharSheetChanged(true);
  1825. return 0;
  1826. }
  1827. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1828. if (!lua_interface)
  1829. return 0;
  1830. Spawn* spawn = lua_interface->GetSpawn(state);
  1831. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1832. lua_interface->ResetFunctionStack(state);
  1833. if (spawn && spawn->IsEntity() && value > 0)
  1834. ((Entity*)spawn)->SetTotalHPBase(value);
  1835. return 0;
  1836. }
  1837. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1838. if (!lua_interface)
  1839. return 0;
  1840. Spawn* spawn = lua_interface->GetSpawn(state);
  1841. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1842. lua_interface->ResetFunctionStack(state);
  1843. if (spawn && value > 0) {
  1844. spawn->SetPower(value);
  1845. if (value > spawn->GetTotalPowerBase())
  1846. spawn->SetTotalPower(value);
  1847. }
  1848. return 0;
  1849. }
  1850. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1851. if (!lua_interface)
  1852. return 0;
  1853. Spawn* spawn = lua_interface->GetSpawn(state);
  1854. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1858. return 0;
  1859. }
  1860. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1861. if (!lua_interface)
  1862. return 0;
  1863. Spawn* spawn = lua_interface->GetSpawn(state);
  1864. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1865. lua_interface->ResetFunctionStack(state);
  1866. if (spawn && spawn->IsEntity() && value > 0)
  1867. ((Entity*)spawn)->SetTotalPowerBase(value);
  1868. return 0;
  1869. }
  1870. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1871. if (!lua_interface)
  1872. return 0;
  1873. Spawn* spawn = lua_interface->GetSpawn(state);
  1874. float x = lua_interface->GetFloatValue(state, 2);
  1875. float y = lua_interface->GetFloatValue(state, 3);
  1876. float z = lua_interface->GetFloatValue(state, 4);
  1877. float heading = lua_interface->GetFloatValue(state, 5);
  1878. lua_interface->ResetFunctionStack(state);
  1879. if (spawn) {
  1880. spawn->SetX(x);
  1881. spawn->SetY(y);
  1882. spawn->SetZ(z);
  1883. if (heading != 0)
  1884. spawn->SetHeading(heading);
  1885. spawn->SetSpawnOrigX(spawn->GetX());
  1886. spawn->SetSpawnOrigY(spawn->GetY());
  1887. spawn->SetSpawnOrigZ(spawn->GetZ());
  1888. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1889. if (spawn->IsPlayer()) {
  1890. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1891. if (client) {
  1892. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1893. client->QueuePacket(packet);
  1894. }
  1895. }
  1896. }
  1897. return 0;
  1898. }
  1899. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1900. if (!lua_interface)
  1901. return 0;
  1902. Spawn* spawn = lua_interface->GetSpawn(state);
  1903. float value = lua_interface->GetFloatValue(state, 2);
  1904. lua_interface->ResetFunctionStack(state);
  1905. if (spawn) {
  1906. spawn->SetHeading(value);
  1907. if (spawn->IsPlayer()) {
  1908. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1909. if (client) {
  1910. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1911. client->QueuePacket(packet);
  1912. }
  1913. }
  1914. }
  1915. return 0;
  1916. }
  1917. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1918. if (!lua_interface)
  1919. return 0;
  1920. Spawn* spawn = lua_interface->GetSpawn(state);
  1921. int16 value = lua_interface->GetInt16Value(state, 2);
  1922. lua_interface->ResetFunctionStack(state);
  1923. if (spawn)
  1924. spawn->SetModelType(value);
  1925. return 0;
  1926. }
  1927. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1928. if (!lua_interface)
  1929. return 0;
  1930. Spawn* spawn = lua_interface->GetSpawn(state);
  1931. int8 value = lua_interface->GetInt8Value(state, 2);
  1932. lua_interface->ResetFunctionStack(state);
  1933. if (spawn) {
  1934. if (spawn->IsPlayer())
  1935. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1936. else
  1937. spawn->SetAdventureClass(value);
  1938. }
  1939. return 0;
  1940. }
  1941. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1942. if (!lua_interface)
  1943. return 0;
  1944. Spawn* spawn = lua_interface->GetSpawn(state);
  1945. int8 value = lua_interface->GetInt8Value(state, 2);
  1946. lua_interface->ResetFunctionStack(state);
  1947. if (spawn) {
  1948. spawn->SetTradeskillClass(value);
  1949. if (spawn->IsEntity()) {
  1950. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1951. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1952. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1953. }
  1954. if (spawn->IsPlayer())
  1955. ((Player*)spawn)->SetCharSheetChanged(true);
  1956. }
  1957. return 0;
  1958. }
  1959. int EQ2Emu_lua_SetMount(lua_State* state) {
  1960. if (!lua_interface)
  1961. return 0;
  1962. Spawn* spawn = lua_interface->GetSpawn(state);
  1963. int16 value = lua_interface->GetInt16Value(state, 2);
  1964. if (spawn && spawn->IsEntity()) {
  1965. ((Entity*)spawn)->SetMount(value);
  1966. EQ2_Color color;
  1967. color.red = 255;
  1968. color.green = 255;
  1969. color.blue = 255;
  1970. ((Entity*)spawn)->SetMountColor(&color);
  1971. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1972. }
  1973. return 0;
  1974. }
  1975. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1976. if (!lua_interface)
  1977. return 0;
  1978. Spawn* spawn = lua_interface->GetSpawn(state);
  1979. EQ2_Color mount_color;
  1980. EQ2_Color saddle_color;
  1981. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1982. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1983. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1984. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1985. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1986. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1987. if (spawn && spawn->IsEntity()) {
  1988. ((Entity*)spawn)->SetMountColor(&mount_color);
  1989. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1990. }
  1991. return 0;
  1992. }
  1993. int EQ2Emu_lua_GetMount(lua_State* state) {
  1994. if (!lua_interface)
  1995. return 0;
  1996. Spawn* spawn = lua_interface->GetSpawn(state);
  1997. if (spawn && spawn->IsEntity()) {
  1998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1999. return 1;
  2000. }
  2001. return 0;
  2002. }
  2003. int EQ2Emu_lua_GetRace(lua_State* state) {
  2004. if (!lua_interface)
  2005. return 0;
  2006. Spawn* spawn = lua_interface->GetSpawn(state);
  2007. if (spawn)
  2008. {
  2009. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2010. lua_interface->SetInt32Value(state, spawn->GetRace());
  2011. return 1;
  2012. }
  2013. return 0;
  2014. }
  2015. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2016. if (!lua_interface)
  2017. return 0;
  2018. Spawn* spawn = lua_interface->GetSpawn(state);
  2019. if (spawn) {
  2020. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2021. return 1;
  2022. }
  2023. return 0;
  2024. }
  2025. int EQ2Emu_lua_GetClass(lua_State* state) {
  2026. Spawn* spawn = lua_interface->GetSpawn(state);
  2027. if (spawn) {
  2028. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2029. return 1;
  2030. }
  2031. return 0;
  2032. }
  2033. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2034. Spawn* spawn = lua_interface->GetSpawn(state);
  2035. if (spawn) {
  2036. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2037. return 1;
  2038. }
  2039. return 0;
  2040. }
  2041. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2042. if (!lua_interface)
  2043. return 0;
  2044. Spawn* spawn = lua_interface->GetSpawn(state);
  2045. float value = lua_interface->GetFloatValue(state, 2);
  2046. lua_interface->ResetFunctionStack(state);
  2047. if (spawn) {
  2048. spawn->SetSpeed(value);
  2049. if(spawn->IsEntity())
  2050. ((Entity*)spawn)->SetSpeed(value);
  2051. if (spawn->IsPlayer()) {
  2052. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2053. if (client) {
  2054. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2055. if (packet) {
  2056. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2057. packet->setDataByName("speed", value);
  2058. packet->setDataByName("size", 0.51);
  2059. EQ2Packet* app = packet->serialize();
  2060. client->QueuePacket(app);
  2061. safe_delete(packet);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. return 0;
  2067. }
  2068. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2069. if (!lua_interface)
  2070. return 0;
  2071. Spawn* spawn = lua_interface->GetSpawn(state);
  2072. const int16 type = lua_interface->GetInt16Value(state, 2);
  2073. const float value = lua_interface->GetFloatValue(state, 3);
  2074. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2075. int64 class_req = 0;
  2076. int32 class_id = 0;
  2077. vector<int16> faction_req;
  2078. vector<int16> race_req;
  2079. int32 i = 0;
  2080. int8 f = 0;
  2081. int8 r = 0;
  2082. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2083. if (class_id < 100) {
  2084. class_req += pow(2.0, double(class_id - 1));
  2085. }
  2086. else if (class_id > 100 && class_id < 1000) {
  2087. race_req.push_back(class_id);
  2088. r++;
  2089. }
  2090. else {
  2091. faction_req.push_back(class_id);
  2092. f++;
  2093. }
  2094. i++;
  2095. }
  2096. if (value != 0 && type >= 0) {
  2097. if (luaspell && luaspell->spell && luaspell->caster) {
  2098. ZoneServer* zone = luaspell->caster->GetZone();
  2099. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2100. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2101. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2102. if (target) {
  2103. if (target->IsPlayer()) {
  2104. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2105. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2106. if (((Player*)target)->GetGroupMemberInfo())
  2107. ((Player*)target)->UpdateGroupMemberInfo();
  2108. ((Player*)target)->SetCharSheetChanged(true);
  2109. }
  2110. else if (target->IsNPC())
  2111. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2112. else
  2113. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2114. }
  2115. }
  2116. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2117. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2118. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2119. }
  2120. else if (spawn && spawn->IsEntity()) {
  2121. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2122. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2123. if (spawn->IsPlayer())
  2124. ((Player*)spawn)->SetCharSheetChanged(true);
  2125. }
  2126. else
  2127. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2128. }
  2129. else
  2130. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2131. return 0;
  2132. }
  2133. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2134. if (!lua_interface)
  2135. return 0;
  2136. Spawn* spawn = lua_interface->GetSpawn(state);
  2137. int16 type = lua_interface->GetInt16Value(state, 2);
  2138. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2139. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2140. if (!spawn) {
  2141. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2142. return 0;
  2143. }
  2144. if (!spawn->IsEntity()) {
  2145. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2146. return 0;
  2147. }
  2148. if (value == 0) {
  2149. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2150. return 0;
  2151. }
  2152. if (!luaspell || !luaspell->spell) {
  2153. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  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. spell_id = luaspell->spell->GetSpellID();
  2243. ZoneServer* zone = luaspell->caster->GetZone();
  2244. Spawn* target = 0;
  2245. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2246. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2247. target = zone->GetSpawnByID(luaspell->targets[i]);
  2248. if (target && target->Alive()) {
  2249. if (target->IsPlayer()) {
  2250. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2251. Client* client = target->GetZone()->GetClientBySpawn(target);
  2252. if (client) {
  2253. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2254. if (packet)
  2255. client->QueuePacket(packet);
  2256. }
  2257. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2258. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2259. }
  2260. else if (target->IsNPC()) {
  2261. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2262. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2263. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2264. }
  2265. else
  2266. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2267. }
  2268. }
  2269. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2270. }
  2271. else if (spawn) {
  2272. if (spawn->IsPlayer()) {
  2273. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2274. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2275. if (client) {
  2276. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2277. if (packet)
  2278. client->QueuePacket(packet);
  2279. }
  2280. }
  2281. else if (spawn->IsNPC())
  2282. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2283. else
  2284. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2285. }
  2286. }
  2287. else
  2288. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2289. return 0;
  2290. }
  2291. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2292. if (!lua_interface)
  2293. return 0;
  2294. Spawn* spawn = lua_interface->GetSpawn(state);
  2295. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2296. if (spawn && spawn->IsPlayer()) {
  2297. int32 spell_id = 0;
  2298. if (luaspell && luaspell->spell) {
  2299. spell_id = luaspell->spell->GetSpellID();
  2300. ZoneServer* zone = luaspell->caster->GetZone();
  2301. Spawn* target = 0;
  2302. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2303. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2304. target = zone->GetSpawnByID(luaspell->targets[i]);
  2305. if (target) {
  2306. if (target->IsPlayer()) {
  2307. ((Player*)target)->RemoveSkillBonus(spell_id);
  2308. Client* client = target->GetZone()->GetClientBySpawn(target);
  2309. if (client) {
  2310. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2311. if (packet)
  2312. client->QueuePacket(packet);
  2313. }
  2314. }
  2315. else if (target->IsNPC())
  2316. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2317. else
  2318. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2319. }
  2320. }
  2321. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2322. }
  2323. else if (spawn) {
  2324. if (spawn->IsPlayer()) {
  2325. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2326. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2327. if (client) {
  2328. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2329. if (packet)
  2330. client->QueuePacket(packet);
  2331. }
  2332. }
  2333. else if (spawn->IsNPC())
  2334. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2335. else
  2336. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2337. }
  2338. }
  2339. return 0;
  2340. }
  2341. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2342. if (!lua_interface)
  2343. return 0;
  2344. Spawn* spawn = lua_interface->GetSpawn(state);
  2345. int8 type = lua_interface->GetInt32Value(state, 2);
  2346. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2347. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2348. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2349. ZoneServer* zone = luaspell->caster->GetZone();
  2350. Spawn* target = 0;
  2351. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2352. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2353. target = zone->GetSpawnByID(luaspell->targets[i]);
  2354. if (target && target->IsEntity()) {
  2355. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2356. ((Entity*)target)->AddMezSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2359. if (target->IsNPC())
  2360. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2361. }
  2362. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2363. ((Entity*)target)->AddStifleSpell(luaspell);
  2364. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2365. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2366. if (target->IsNPC())
  2367. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2370. ((Entity*)target)->AddDazeSpell(luaspell);
  2371. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2372. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2373. if (target->IsNPC())
  2374. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2375. }
  2376. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2379. ((Entity*)target)->AddStunSpell(luaspell);
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2384. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2385. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2386. ((Entity*)target)->AddRootSpell(luaspell);
  2387. if (target->IsNPC())
  2388. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2391. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2392. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2393. ((Entity*)target)->AddFearSpell(luaspell);
  2394. if (target->IsNPC())
  2395. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2396. }
  2397. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2398. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2399. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2400. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2401. }
  2402. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2403. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2404. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2405. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2406. }
  2407. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2408. ((Entity*)target)->AddSnareSpell(luaspell);
  2409. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2410. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2411. if (target->IsNPC())
  2412. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2413. }
  2414. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2415. ((Entity*)target)->AddFlightSpell(luaspell);
  2416. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2417. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2418. }
  2419. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2420. ((Entity*)target)->AddGlideSpell(luaspell);
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2423. }
  2424. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2425. ((Entity*)target)->AddSafefallSpell(luaspell);
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2428. }
  2429. else
  2430. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2431. }
  2432. else
  2433. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2434. }
  2435. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2436. }
  2437. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2438. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2439. ((Entity*)spawn)->AddMezSpell(luaspell);
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2442. }
  2443. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2444. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2445. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2446. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2447. }
  2448. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2449. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2450. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2451. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2452. }
  2453. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2454. ((Entity*)spawn)->AddStunSpell(luaspell);
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2459. ((Entity*)spawn)->AddRootSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2464. ((Entity*)spawn)->AddFearSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2467. }
  2468. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2469. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2470. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2471. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2472. }
  2473. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2474. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2475. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2476. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2477. }
  2478. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2479. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2480. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2481. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2482. }
  2483. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2484. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2485. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2486. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2487. }
  2488. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2489. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2490. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2491. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2492. }
  2493. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2494. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2495. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2496. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2497. }
  2498. else
  2499. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2500. }
  2501. else
  2502. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2503. return 0;
  2504. }
  2505. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2506. if (!lua_interface)
  2507. return 0;
  2508. Spawn* spawn = lua_interface->GetSpawn(state);
  2509. int8 type = lua_interface->GetInt8Value(state, 2);
  2510. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2511. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2512. if (spawn && spawn->IsEntity()) {
  2513. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2514. ZoneServer* zone = luaspell->caster->GetZone();
  2515. Spawn* target = 0;
  2516. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2517. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2518. target = zone->GetSpawnByID(luaspell->targets[i]);
  2519. if (target) {
  2520. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2521. ((Entity*)target)->RemoveMezSpell(luaspell);
  2522. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2523. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2524. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2525. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2526. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2527. ((Entity*)target)->RemoveStunSpell(luaspell);
  2528. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2529. ((Entity*)target)->RemoveRootSpell(luaspell);
  2530. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2531. ((Entity*)target)->RemoveFearSpell(luaspell);
  2532. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2533. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2534. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2535. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2536. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2537. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2538. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2539. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2540. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2541. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2542. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2543. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2544. else
  2545. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2546. }
  2547. }
  2548. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2549. }
  2550. else if (only_remove_spawn) {
  2551. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2552. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2554. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2556. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2558. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2560. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2561. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2562. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2563. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2564. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2565. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2566. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2567. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2568. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2569. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2570. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2571. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2572. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2573. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2574. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2575. else
  2576. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2577. }
  2578. }
  2579. return 0;
  2580. }
  2581. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2582. if (!lua_interface)
  2583. return 0;
  2584. Spawn* spawn = lua_interface->GetSpawn(state);
  2585. int8 type = lua_interface->GetInt8Value(state, 2);
  2586. bool hasEffect = false;
  2587. if (!spawn)
  2588. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2589. else if (!spawn->IsEntity())
  2590. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2591. else if (type < CONTROL_MAX_EFFECTS)
  2592. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2593. else
  2594. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2595. lua_interface->SetBooleanValue(state, hasEffect);
  2596. return 1;
  2597. }
  2598. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. float distance = 0.0f;
  2603. if (!spawn)
  2604. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2605. else if (!spawn->IsNPC())
  2606. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2607. else
  2608. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2609. lua_interface->SetFloatValue(state, distance);
  2610. return 1;
  2611. }
  2612. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. float distance = 0.0f;
  2617. if (!spawn)
  2618. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2619. else if (!spawn->IsNPC())
  2620. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2621. else
  2622. distance = ((NPC*)spawn)->GetAggroRadius();
  2623. lua_interface->SetFloatValue(state, distance);
  2624. return 1;
  2625. }
  2626. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2627. if (!lua_interface)
  2628. return 0;
  2629. Spawn* spawn = lua_interface->GetSpawn(state);
  2630. float distance = lua_interface->GetFloatValue(state, 2);
  2631. bool override = lua_interface->GetBooleanValue(state, 3);
  2632. bool result = false;
  2633. lua_interface->ResetFunctionStack(state);
  2634. if (!spawn)
  2635. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2636. else if (!spawn->IsNPC())
  2637. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2638. else
  2639. {
  2640. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2641. result = true;
  2642. }
  2643. lua_interface->SetBooleanValue(state, result);
  2644. return 1;
  2645. }
  2646. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2647. if (!lua_interface)
  2648. return 0;
  2649. Spawn* spawn = lua_interface->GetSpawn(state);
  2650. int16 value = lua_interface->GetInt16Value(state, 2);
  2651. if (spawn && spawn->IsEntity()) {
  2652. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2653. if (spawn->IsPlayer())
  2654. ((Player*)spawn)->SetCharSheetChanged(true);
  2655. }
  2656. return 0;
  2657. }
  2658. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2659. if (!lua_interface)
  2660. return 0;
  2661. Spawn* spawn = lua_interface->GetSpawn(state);
  2662. int16 value = lua_interface->GetInt16Value(state, 2);
  2663. if (spawn && spawn->IsEntity()) {
  2664. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2665. if (spawn->IsPlayer())
  2666. ((Player*)spawn)->SetCharSheetChanged(true);
  2667. }
  2668. return 0;
  2669. }
  2670. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. int16 value = lua_interface->GetInt16Value(state, 2);
  2675. if (spawn && spawn->IsEntity()) {
  2676. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2677. if (spawn->IsPlayer())
  2678. ((Player*)spawn)->SetCharSheetChanged(true);
  2679. }
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int16 value = lua_interface->GetInt16Value(state, 2);
  2687. if (spawn && spawn->IsEntity()) {
  2688. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2689. if (spawn->IsPlayer())
  2690. ((Player*)spawn)->SetCharSheetChanged(true);
  2691. }
  2692. return 0;
  2693. }
  2694. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2695. if (!lua_interface)
  2696. return 0;
  2697. Spawn* spawn = lua_interface->GetSpawn(state);
  2698. int16 value = lua_interface->GetInt16Value(state, 2);
  2699. if (spawn && spawn->IsEntity()) {
  2700. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2701. if (spawn->IsPlayer())
  2702. ((Player*)spawn)->SetCharSheetChanged(true);
  2703. }
  2704. return 0;
  2705. }
  2706. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2707. if (!lua_interface)
  2708. return 0;
  2709. Spawn* spawn = lua_interface->GetSpawn(state);
  2710. int8 value = lua_interface->GetInt8Value(state, 2);
  2711. if (spawn && spawn->IsEntity()) {
  2712. ((Entity*)spawn)->SetDeity(value);
  2713. if (spawn->IsPlayer())
  2714. ((Player*)spawn)->SetCharSheetChanged(true);
  2715. }
  2716. lua_interface->ResetFunctionStack(state);
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn && spawn->IsEntity()) {
  2724. int8 deity = ((Entity*)spawn)->GetDeity();
  2725. lua_interface->SetInt32Value(state, deity);
  2726. return 1;
  2727. }
  2728. return 0;
  2729. }
  2730. int EQ2Emu_lua_SetInt(lua_State* state) {
  2731. if (!lua_interface)
  2732. return 0;
  2733. Spawn* spawn = lua_interface->GetSpawn(state);
  2734. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2735. if (spawn && spawn->IsEntity()) {
  2736. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2737. if (spawn->IsPlayer())
  2738. ((Player*)spawn)->SetCharSheetChanged(true);
  2739. }
  2740. return 0;
  2741. }
  2742. int EQ2Emu_lua_SetWis(lua_State* state) {
  2743. if (!lua_interface)
  2744. return 0;
  2745. Spawn* spawn = lua_interface->GetSpawn(state);
  2746. float value = lua_interface->GetFloatValue(state, 2);
  2747. if (spawn && spawn->IsEntity()) {
  2748. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2749. if (spawn->IsPlayer())
  2750. ((Player*)spawn)->SetCharSheetChanged(true);
  2751. }
  2752. return 0;
  2753. }
  2754. int EQ2Emu_lua_SetSta(lua_State* state) {
  2755. if (!lua_interface)
  2756. return 0;
  2757. Spawn* spawn = lua_interface->GetSpawn(state);
  2758. float value = lua_interface->GetFloatValue(state, 2);
  2759. if (spawn && spawn->IsEntity()) {
  2760. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2761. if (spawn->IsPlayer())
  2762. ((Player*)spawn)->SetCharSheetChanged(true);
  2763. }
  2764. return 0;
  2765. }
  2766. int EQ2Emu_lua_SetStr(lua_State* state) {
  2767. if (!lua_interface)
  2768. return 0;
  2769. Spawn* spawn = lua_interface->GetSpawn(state);
  2770. float value = lua_interface->GetFloatValue(state, 2);
  2771. if (spawn && spawn->IsEntity()) {
  2772. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2773. if (spawn->IsPlayer())
  2774. ((Player*)spawn)->SetCharSheetChanged(true);
  2775. }
  2776. return 0;
  2777. }
  2778. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2779. if (!lua_interface)
  2780. return 0;
  2781. Spawn* spawn = lua_interface->GetSpawn(state);
  2782. float value = lua_interface->GetFloatValue(state, 2);
  2783. if (spawn && spawn->IsEntity()) {
  2784. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2785. if (spawn->IsPlayer())
  2786. ((Player*)spawn)->SetCharSheetChanged(true);
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Spawn* spawn = lua_interface->GetSpawn(state);
  2794. if (spawn) {
  2795. lua_interface->SetInt32Value(state, spawn->GetHP());
  2796. return 1;
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. if (spawn) {
  2805. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2806. return 1;
  2807. }
  2808. return 0;
  2809. }
  2810. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2811. if (!lua_interface)
  2812. return 0;
  2813. Spawn* spawn = lua_interface->GetSpawn(state);
  2814. if (spawn) {
  2815. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2816. return 1;
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_GetName(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. if (spawn) {
  2825. lua_interface->SetStringValue(state, spawn->GetName());
  2826. return 1;
  2827. }
  2828. return 0;
  2829. }
  2830. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2831. Spawn* spawn = lua_interface->GetSpawn(state);
  2832. if (spawn) {
  2833. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. if (spawn) {
  2843. lua_interface->SetInt32Value(state, spawn->GetPower());
  2844. return 1;
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn) {
  2863. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2873. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2874. if (spawn && spawn2) {
  2875. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2876. lua_interface->SetFloatValue(state, distance);
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetX(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. if (spawn) {
  2886. lua_interface->SetFloatValue(state, spawn->GetX());
  2887. return 1;
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_GetY(lua_State* state) {
  2892. if (!lua_interface)
  2893. return 0;
  2894. Spawn* spawn = lua_interface->GetSpawn(state);
  2895. if (spawn) {
  2896. lua_interface->SetFloatValue(state, spawn->GetY());
  2897. return 1;
  2898. }
  2899. return 0;
  2900. }
  2901. int EQ2Emu_lua_GetZ(lua_State* state) {
  2902. if (!lua_interface)
  2903. return 0;
  2904. Spawn* spawn = lua_interface->GetSpawn(state);
  2905. if (spawn) {
  2906. lua_interface->SetFloatValue(state, spawn->GetZ());
  2907. return 1;
  2908. }
  2909. return 0;
  2910. }
  2911. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2912. if (!lua_interface)
  2913. return 0;
  2914. Spawn* spawn = lua_interface->GetSpawn(state);
  2915. if (spawn) {
  2916. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2917. return 1;
  2918. }
  2919. return 0;
  2920. }
  2921. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2922. if (!lua_interface)
  2923. return 0;
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. if (spawn) {
  2926. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2927. return 1;
  2928. }
  2929. return 0;
  2930. }
  2931. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2932. if (!lua_interface)
  2933. return 0;
  2934. Spawn* spawn = lua_interface->GetSpawn(state);
  2935. if (spawn) {
  2936. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2937. return 1;
  2938. }
  2939. return 0;
  2940. }
  2941. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2942. if (!lua_interface)
  2943. return 0;
  2944. Spawn* spawn = lua_interface->GetSpawn(state);
  2945. if (spawn && spawn->IsEntity()) {
  2946. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2947. return 1;
  2948. }
  2949. return 0;
  2950. }
  2951. int EQ2Emu_lua_GetInt(lua_State* state) {
  2952. if (!lua_interface)
  2953. return 0;
  2954. Spawn* spawn = lua_interface->GetSpawn(state);
  2955. if (spawn && spawn->IsEntity()) {
  2956. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2957. return 1;
  2958. }
  2959. return 0;
  2960. }
  2961. int EQ2Emu_lua_GetWis(lua_State* state) {
  2962. if (!lua_interface)
  2963. return 0;
  2964. Spawn* spawn = lua_interface->GetSpawn(state);
  2965. if (spawn && spawn->IsEntity()) {
  2966. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2967. return 1;
  2968. }
  2969. return 0;
  2970. }
  2971. int EQ2Emu_lua_GetSta(lua_State* state) {
  2972. if (!lua_interface)
  2973. return 0;
  2974. Spawn* spawn = lua_interface->GetSpawn(state);
  2975. if (spawn && spawn->IsEntity()) {
  2976. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2977. return 1;
  2978. }
  2979. return 0;
  2980. }
  2981. int EQ2Emu_lua_GetStr(lua_State* state) {
  2982. if (!lua_interface)
  2983. return 0;
  2984. Spawn* spawn = lua_interface->GetSpawn(state);
  2985. if (spawn && spawn->IsEntity()) {
  2986. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2987. return 1;
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Spawn* spawn = lua_interface->GetSpawn(state);
  2995. if (spawn && spawn->IsEntity()) {
  2996. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2997. return 1;
  2998. }
  2999. return 0;
  3000. }
  3001. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3002. if (!lua_interface)
  3003. return 0;
  3004. Spawn* spawn = lua_interface->GetSpawn(state);
  3005. if (spawn && spawn->IsEntity()) {
  3006. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3007. return 1;
  3008. }
  3009. return 0;
  3010. }
  3011. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3012. if (!lua_interface)
  3013. return 0;
  3014. Spawn* spawn = lua_interface->GetSpawn(state);
  3015. if (spawn && spawn->IsEntity()) {
  3016. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3017. return 1;
  3018. }
  3019. return 0;
  3020. }
  3021. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3022. if (!lua_interface)
  3023. return 0;
  3024. Spawn* spawn = lua_interface->GetSpawn(state);
  3025. if (spawn && spawn->IsEntity()) {
  3026. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3027. return 1;
  3028. }
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Spawn* spawn = lua_interface->GetSpawn(state);
  3035. if (spawn && spawn->IsEntity()) {
  3036. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3037. return 1;
  3038. }
  3039. return 0;
  3040. }
  3041. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3042. if (!lua_interface)
  3043. return 0;
  3044. Spawn* spawn = lua_interface->GetSpawn(state);
  3045. if (spawn && spawn->IsEntity()) {
  3046. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3047. return 1;
  3048. }
  3049. return 0;
  3050. }
  3051. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3052. if (!lua_interface)
  3053. return 0;
  3054. Spawn* player = lua_interface->GetSpawn(state);
  3055. if (!player || !player->IsPlayer()) {
  3056. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3057. return 0;
  3058. }
  3059. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3060. if (quest_id <= 0) {
  3061. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3062. return 0;
  3063. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3064. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3065. return 0;
  3066. }
  3067. int32 step = lua_interface->GetInt32Value(state, 3);
  3068. if (step > 0) {
  3069. Client* client = player->GetZone()->GetClientBySpawn(player);
  3070. if (client)
  3071. client->AddPendingQuestUpdate(quest_id, step);
  3072. } else {
  3073. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3074. }
  3075. return 0;
  3076. }
  3077. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3078. Spawn* player = lua_interface->GetSpawn(state);
  3079. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3080. int32 step = lua_interface->GetInt32Value(state, 3);
  3081. int32 progress = lua_interface->GetInt32Value(state, 4);
  3082. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3083. Client* client = player->GetZone()->GetClientBySpawn(player);
  3084. if (client)
  3085. client->AddPendingQuestUpdate(quest_id, step, progress);
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* player = lua_interface->GetSpawn(state);
  3093. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3094. if (player && player->IsPlayer() && quest_id > 0) {
  3095. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* player = lua_interface->GetSpawn(state);
  3104. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3105. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3106. if (player && player->IsPlayer() && quest_id > 0) {
  3107. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3108. return 1;
  3109. }
  3110. return 0;
  3111. }
  3112. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3113. if (!lua_interface)
  3114. return 0;
  3115. Spawn* player = lua_interface->GetSpawn(state);
  3116. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3117. if (player && player->IsPlayer() && quest_id > 0) {
  3118. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3119. return 1;
  3120. }
  3121. return 0;
  3122. }
  3123. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3124. if (!lua_interface)
  3125. return 0;
  3126. Quest* quest = lua_interface->GetQuest(state);
  3127. string name = lua_interface->GetStringValue(state, 2);
  3128. string type = lua_interface->GetStringValue(state, 3);
  3129. string zone = lua_interface->GetStringValue(state, 4);
  3130. int16 level = lua_interface->GetInt16Value(state, 5);
  3131. string description = lua_interface->GetStringValue(state, 6);
  3132. bool load = true;
  3133. if (!quest) {
  3134. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3135. load = false;
  3136. }
  3137. if (load && name.length() == 0) {
  3138. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3139. load = false;
  3140. }
  3141. if (load && type.length() == 0) {
  3142. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3143. load = false;
  3144. }
  3145. if (load && zone.length() == 0) {
  3146. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3147. load = false;
  3148. }
  3149. if (load && description.length() == 0) {
  3150. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3151. load = false;
  3152. }
  3153. if (load && level == 0) {
  3154. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3155. load = false;
  3156. }
  3157. if (load)
  3158. quest->RegisterQuest(name, type, zone, level, description);
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Quest* quest = lua_interface->GetQuest(state);
  3165. if (quest) {
  3166. int8 level = lua_interface->GetInt16Value(state, 2);
  3167. quest->SetPrereqLevel(level);
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Quest* quest = lua_interface->GetQuest(state);
  3175. if (quest) {
  3176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3177. quest->AddPrereqQuest(quest_id);
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Quest* quest = lua_interface->GetQuest(state);
  3185. if (quest) {
  3186. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3187. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3188. if (quantity == 0)
  3189. quantity = 1;
  3190. Item* master_item = master_item_list.GetItem(item_id);
  3191. if (master_item) {
  3192. Item* item = new Item(master_item);
  3193. item->details.count = quantity;
  3194. quest->AddPrereqItem(item);
  3195. }
  3196. }
  3197. return 0;
  3198. }
  3199. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3200. if (!lua_interface)
  3201. return 0;
  3202. Spawn* player = lua_interface->GetSpawn(state);
  3203. if(!player || !player->IsPlayer()) {
  3204. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3205. return 0;
  3206. }
  3207. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3208. if (quest_id > 0) {
  3209. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3210. return 1;
  3211. } else {
  3212. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3213. }
  3214. return 0;
  3215. }
  3216. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3217. if (!lua_interface)
  3218. return 0;
  3219. Quest* quest = lua_interface->GetQuest(state);
  3220. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3221. lua_interface->ResetFunctionStack(state);
  3222. if (quest && spawn_id > 0)
  3223. quest->SetQuestReturnNPC(spawn_id);
  3224. return 0;
  3225. }
  3226. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3227. if (!lua_interface)
  3228. return 0;
  3229. Spawn* spawn = lua_interface->GetSpawn(state);
  3230. int32 time = lua_interface->GetInt32Value(state, 2);
  3231. string function = lua_interface->GetStringValue(state, 3);
  3232. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3233. Spawn* player = lua_interface->GetSpawn(state, 5);
  3234. lua_interface->ResetFunctionStack(state);
  3235. if (!spawn) {
  3236. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3237. return 0;
  3238. }
  3239. if (time <= 0) {
  3240. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3241. return 0;
  3242. }
  3243. if (function.length() == 0) {
  3244. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3245. return 0;
  3246. }
  3247. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3248. if ( time < 10)
  3249. time = 10;
  3250. timer->timer = Timer::GetCurrentTime2() + time;
  3251. timer->function = function;
  3252. timer->spawn = spawn->GetID();
  3253. timer->player = player ? player->GetID() : 0;
  3254. if (max_count == 0)
  3255. max_count = 1;
  3256. timer->max_count = max_count;
  3257. timer->current_count = 0;
  3258. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3259. return 0;
  3260. }
  3261. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3262. if (!lua_interface)
  3263. return 0;
  3264. Spawn* spawn = lua_interface->GetSpawn(state);
  3265. string function = lua_interface->GetStringValue(state, 2);
  3266. lua_interface->ResetFunctionStack(state);
  3267. if (!spawn) {
  3268. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3269. return 0;
  3270. }
  3271. if(!spawn->GetZone()) {
  3272. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3273. return 0;
  3274. }
  3275. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Spawn* player = lua_interface->GetSpawn(state);
  3282. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3283. lua_interface->ResetFunctionStack(state);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3297. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3298. if (quest)
  3299. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3300. return 1;
  3301. }
  3302. return 0;
  3303. }
  3304. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3305. if (!lua_interface)
  3306. return 0;
  3307. Spawn* player = lua_interface->GetSpawn(state);
  3308. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3309. lua_interface->ResetFunctionStack(state);
  3310. if (player && player->IsPlayer() && quest_id > 0) {
  3311. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3312. return 1;
  3313. }
  3314. return 0;
  3315. }
  3316. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3317. if (!lua_interface)
  3318. return 0;
  3319. Spawn* npc = lua_interface->GetSpawn(state);
  3320. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3321. lua_interface->ResetFunctionStack(state);
  3322. if (npc && !npc->IsPlayer() && quest_id > 0)
  3323. npc->AddProvidedQuest(quest_id);
  3324. return 0;
  3325. }
  3326. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3327. if (!lua_interface)
  3328. return 0;
  3329. Spawn* npc = lua_interface->GetSpawn(state);
  3330. Spawn* player = lua_interface->GetSpawn(state, 2);
  3331. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3332. bool forced = lua_interface->GetBooleanValue(state, 4);
  3333. lua_interface->ResetFunctionStack(state);
  3334. /* NPC is allowed to be null */
  3335. if (player && player->IsPlayer() && quest_id > 0) {
  3336. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3337. if (master_quest) {
  3338. Client* client = player->GetZone()->GetClientBySpawn(player);
  3339. if (!client) {
  3340. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3341. }
  3342. Quest* quest = new Quest(master_quest);
  3343. if (!quest) {
  3344. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3345. }
  3346. if (client && quest) {
  3347. if (npc)
  3348. quest->SetQuestGiver(npc->GetDatabaseID());
  3349. else
  3350. quest->SetQuestGiver(0);
  3351. client->AddPendingQuest(quest, forced);
  3352. }
  3353. }
  3354. else {
  3355. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3356. }
  3357. }
  3358. else {
  3359. 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);
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3368. lua_interface->ResetFunctionStack(state);
  3369. if (quest) {
  3370. quest->AddPrereqClass(class_id);
  3371. }
  3372. return 0;
  3373. }
  3374. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3375. if (!lua_interface)
  3376. return 0;
  3377. Quest* quest = lua_interface->GetQuest(state);
  3378. int8 race = lua_interface->GetInt8Value(state, 2);
  3379. lua_interface->ResetFunctionStack(state);
  3380. if (quest) {
  3381. quest->AddPrereqRace(race);
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Quest* quest = lua_interface->GetQuest(state);
  3389. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3390. lua_interface->ResetFunctionStack(state);
  3391. if (quest) {
  3392. quest->AddPrereqModelType(model_type);
  3393. }
  3394. return 0;
  3395. }
  3396. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3397. if (!lua_interface)
  3398. return 0;
  3399. Quest* quest = lua_interface->GetQuest(state);
  3400. int8 level = lua_interface->GetInt8Value(state, 2);
  3401. lua_interface->ResetFunctionStack(state);
  3402. if (!quest) {
  3403. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3404. return 0;
  3405. }
  3406. quest->SetPrereqTSLevel(level);
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3410. if (!lua_interface)
  3411. return 0;
  3412. Quest* quest = lua_interface->GetQuest(state);
  3413. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3414. lua_interface->ResetFunctionStack(state);
  3415. if (!quest) {
  3416. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3417. return 0;
  3418. }
  3419. quest->AddPrereqTradeskillClass(class_id);
  3420. return 0;
  3421. }
  3422. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3423. if (!lua_interface)
  3424. return 0;
  3425. Quest* quest = lua_interface->GetQuest(state);
  3426. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3427. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3428. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3429. lua_interface->ResetFunctionStack(state);
  3430. if (quest) {
  3431. quest->AddPrereqFaction(faction_id, min, max);
  3432. }
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3440. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3441. lua_interface->ResetFunctionStack(state);
  3442. if (quest) {
  3443. if (quantity == 0)
  3444. quantity = 1;
  3445. Item* master_item = master_item_list.GetItem(item_id);
  3446. if (master_item) {
  3447. Item* item = new Item(master_item);
  3448. item->details.count = quantity;
  3449. quest->AddSelectableRewardItem(item);
  3450. }
  3451. }
  3452. return 0;
  3453. }
  3454. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3455. if (!lua_interface)
  3456. return 0;
  3457. Quest* quest = lua_interface->GetQuest(state);
  3458. if (quest) {
  3459. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3460. vector<Item*>* items = quest->GetRewardItems();
  3461. if (items) {
  3462. vector<Item*>::iterator itr;
  3463. for (itr = items->begin(); itr != items->end(); itr++) {
  3464. if (*itr && (*itr)->details.item_id == item_id) {
  3465. lua_interface->SetBooleanValue(state, true);
  3466. return 1;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. lua_interface->SetBooleanValue(state, false);
  3472. return 1;
  3473. }
  3474. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Quest* quest = lua_interface->GetQuest(state);
  3478. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3479. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3480. lua_interface->ResetFunctionStack(state);
  3481. if (quest) {
  3482. if (quantity == 0)
  3483. quantity = 1;
  3484. Item* master_item = master_item_list.GetItem(item_id);
  3485. if (master_item) {
  3486. Item* item = new Item(master_item);
  3487. item->details.count = quantity;
  3488. quest->AddRewardItem(item);
  3489. }
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. int32 copper = lua_interface->GetInt32Value(state, 2);
  3498. int32 silver = lua_interface->GetInt32Value(state, 3);
  3499. int32 gold = lua_interface->GetInt32Value(state, 4);
  3500. int32 plat = lua_interface->GetInt32Value(state, 5);
  3501. lua_interface->ResetFunctionStack(state);
  3502. if (quest) {
  3503. quest->AddRewardCoins(copper, silver, gold, plat);
  3504. }
  3505. return 0;
  3506. }
  3507. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3508. if (!lua_interface)
  3509. return 0;
  3510. Quest* quest = lua_interface->GetQuest(state);
  3511. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3512. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3513. lua_interface->ResetFunctionStack(state);
  3514. if (quest && faction_id > 0 && amount != 0)
  3515. quest->AddRewardFaction(faction_id, amount);
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. int32 status = lua_interface->GetInt32Value(state, 2);
  3523. lua_interface->ResetFunctionStack(state);
  3524. if (quest) {
  3525. quest->SetRewardStatus(status);
  3526. }
  3527. return 0;
  3528. }
  3529. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3530. if (!lua_interface)
  3531. return 0;
  3532. Quest* quest = lua_interface->GetQuest(state);
  3533. int32 status = lua_interface->GetInt32Value(state, 2);
  3534. lua_interface->ResetFunctionStack(state);
  3535. if (quest) {
  3536. quest->SetStatusTmpReward(status);
  3537. }
  3538. return 0;
  3539. }
  3540. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3541. if (!lua_interface)
  3542. return 0;
  3543. Quest* quest = lua_interface->GetQuest(state);
  3544. int64 coins = lua_interface->GetInt64Value(state, 2);
  3545. lua_interface->ResetFunctionStack(state);
  3546. if (quest) {
  3547. quest->SetCoinTmpReward(coins);
  3548. }
  3549. return 0;
  3550. }
  3551. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. string comment = lua_interface->GetStringValue(state, 2);
  3556. lua_interface->ResetFunctionStack(state);
  3557. if (quest) {
  3558. quest->SetRewardComment(comment);
  3559. }
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int32 exp = lua_interface->GetInt32Value(state, 2);
  3567. lua_interface->ResetFunctionStack(state);
  3568. if (quest) {
  3569. quest->SetRewardXP(exp);
  3570. }
  3571. return 0;
  3572. }
  3573. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int32 step = lua_interface->GetInt32Value(state, 2);
  3576. string description = lua_interface->GetStringValue(state, 3);
  3577. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3578. float percentage = lua_interface->GetFloatValue(state, 5);
  3579. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3580. int16 icon = lua_interface->GetInt16Value(state, 7);
  3581. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3582. if (quest) {
  3583. const char* taskgroup = 0;
  3584. if (str_taskgroup.length() > 0)
  3585. taskgroup = str_taskgroup.c_str();
  3586. int32 id = 0;
  3587. vector<int32>* ids = 0;
  3588. int i = 0;
  3589. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3590. if (ids == 0)
  3591. ids = new vector<int32>;
  3592. ids->push_back(id);
  3593. i++;
  3594. }
  3595. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3596. if (quest_step && icon && quantity > 0)
  3597. quest_step->SetIcon(icon);
  3598. if (quest->GetPlayer()) {
  3599. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3600. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3601. }
  3602. }
  3603. lua_interface->ResetFunctionStack(state);
  3604. return 0;
  3605. }
  3606. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3607. {
  3608. if (!lua_interface)
  3609. return 0;
  3610. Quest* quest = lua_interface->GetQuest(state);
  3611. int32 step = lua_interface->GetInt32Value(state, 2);
  3612. string description = lua_interface->GetStringValue(state, 3);
  3613. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3614. float percentage = lua_interface->GetFloatValue(state, 5);
  3615. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3616. int16 icon = lua_interface->GetInt16Value(state, 7);
  3617. if (quest) {
  3618. const char* taskgroup = 0;
  3619. if (str_taskgroup.length() > 0)
  3620. taskgroup = str_taskgroup.c_str();
  3621. int32 id = 0;
  3622. vector<int32>* ids = 0;
  3623. int i = 0;
  3624. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3625. if (ids == 0)
  3626. ids = new vector<int32>;
  3627. ids->push_back(id);
  3628. i++;
  3629. }
  3630. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3631. if (quest_step && icon > 0 && quantity > 0)
  3632. quest_step->SetIcon(icon);
  3633. if (quest->GetPlayer()) {
  3634. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3635. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3636. }
  3637. safe_delete(ids);
  3638. }
  3639. lua_interface->ResetFunctionStack(state);
  3640. return 0;
  3641. }
  3642. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3643. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3644. }
  3645. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3646. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3647. }
  3648. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3649. if (!lua_interface)
  3650. return 0;
  3651. Quest* quest = lua_interface->GetQuest(state);
  3652. int32 step = lua_interface->GetInt32Value(state, 2);
  3653. string description = lua_interface->GetStringValue(state, 3);
  3654. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3655. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3656. int16 icon = lua_interface->GetInt16Value(state, 6);
  3657. if (quest) {
  3658. const char* taskgroup = 0;
  3659. if (str_taskgroup.length() > 0)
  3660. taskgroup = str_taskgroup.c_str();
  3661. int32 npc_id = 0;
  3662. vector<int32>* ids = 0;
  3663. int i = 0;
  3664. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3665. if (ids == 0)
  3666. ids = new vector<int32>;
  3667. ids->push_back(npc_id);
  3668. i++;
  3669. }
  3670. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3671. if (quest_step && icon > 0)
  3672. quest_step->SetIcon(icon);
  3673. if (quest->GetPlayer()) {
  3674. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3675. if(client)
  3676. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3677. }
  3678. safe_delete(ids);
  3679. }
  3680. lua_interface->ResetFunctionStack(state);
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 step = lua_interface->GetInt32Value(state, 2);
  3688. string description = lua_interface->GetStringValue(state, 3);
  3689. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3690. float percentage = lua_interface->GetFloatValue(state, 5);
  3691. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3692. int16 icon = lua_interface->GetInt16Value(state, 7);
  3693. if (quest) {
  3694. const char* taskgroup = 0;
  3695. if (str_taskgroup.length() > 0)
  3696. taskgroup = str_taskgroup.c_str();
  3697. int32 item_id = 0;
  3698. vector<int32>* ids = 0;
  3699. int i = 0;
  3700. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3701. if (ids == 0)
  3702. ids = new vector<int32>;
  3703. ids->push_back(item_id);
  3704. i++;
  3705. }
  3706. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3707. if (quest_step && icon > 0 && quantity > 0)
  3708. quest_step->SetIcon(icon);
  3709. if (quest->GetPlayer()) {
  3710. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3711. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3712. }
  3713. safe_delete(ids);
  3714. }
  3715. lua_interface->ResetFunctionStack(state);
  3716. return 0;
  3717. }
  3718. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3719. if (!lua_interface)
  3720. return 0;
  3721. Quest* quest = lua_interface->GetQuest(state);
  3722. int32 step = lua_interface->GetInt32Value(state, 2);
  3723. string description = lua_interface->GetStringValue(state, 3);
  3724. float max_variation = lua_interface->GetFloatValue(state, 4);
  3725. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3726. int16 icon = lua_interface->GetInt16Value(state, 6);
  3727. if (quest) {
  3728. const char* taskgroup = 0;
  3729. if (str_taskgroup.length() > 0)
  3730. taskgroup = str_taskgroup.c_str();
  3731. vector<Location>* locations = 0;
  3732. int8 i = 7;
  3733. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3734. while (true) {
  3735. Location loc;
  3736. loc.x = lua_interface->GetFloatValue(state, i);
  3737. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3738. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3739. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3740. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3741. break;
  3742. if (locations == 0)
  3743. locations = new vector<Location>;
  3744. locations->push_back(loc);
  3745. i += 4;
  3746. }
  3747. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3748. if (quest_step && icon > 0)
  3749. quest_step->SetIcon(icon);
  3750. if (quest->GetPlayer()) {
  3751. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3752. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3753. }
  3754. }
  3755. lua_interface->ResetFunctionStack(state);
  3756. return 0;
  3757. }
  3758. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3759. if (!lua_interface)
  3760. return 0;
  3761. Quest* quest = lua_interface->GetQuest(state);
  3762. int32 step = lua_interface->GetInt32Value(state, 2);
  3763. string description = lua_interface->GetStringValue(state, 3);
  3764. float max_variation = lua_interface->GetFloatValue(state, 4);
  3765. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3766. int16 icon = lua_interface->GetInt16Value(state, 6);
  3767. if (quest) {
  3768. const char* taskgroup = 0;
  3769. if (str_taskgroup.length() > 0)
  3770. taskgroup = str_taskgroup.c_str();
  3771. vector<Location>* locations = 0;
  3772. int8 i = 7;
  3773. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3774. while (true) {
  3775. Location loc;
  3776. loc.x = lua_interface->GetFloatValue(state, i);
  3777. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3778. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3779. loc.zone_id = 0;
  3780. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3781. break;
  3782. if (locations == 0)
  3783. locations = new vector<Location>;
  3784. locations->push_back(loc);
  3785. i += 3;
  3786. }
  3787. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3788. if (quest_step && icon > 0)
  3789. quest_step->SetIcon(icon);
  3790. if (quest->GetPlayer()) {
  3791. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3792. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3793. }
  3794. }
  3795. lua_interface->ResetFunctionStack(state);
  3796. return 0;
  3797. }
  3798. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3799. if (!lua_interface)
  3800. return 0;
  3801. Quest* quest = lua_interface->GetQuest(state);
  3802. int32 step = lua_interface->GetInt32Value(state, 2);
  3803. string description = lua_interface->GetStringValue(state, 3);
  3804. float max_variation = lua_interface->GetFloatValue(state, 4);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3806. int16 icon = lua_interface->GetInt16Value(state, 6);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. vector<Location>* locations = 0;
  3812. int i = 7;
  3813. while (true) {
  3814. Location loc;
  3815. loc.x = lua_interface->GetFloatValue(state, i);
  3816. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3817. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3818. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3819. break;
  3820. if (locations == 0)
  3821. locations = new vector<Location>;
  3822. locations->push_back(loc);
  3823. i += 3;
  3824. }
  3825. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3826. if (quest_step && icon > 0)
  3827. quest_step->SetIcon(icon);
  3828. if (quest->GetPlayer()) {
  3829. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3830. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3831. }
  3832. }
  3833. lua_interface->ResetFunctionStack(state);
  3834. return 0;
  3835. }
  3836. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3837. Quest* quest = lua_interface->GetQuest(state);
  3838. int32 step = lua_interface->GetInt32Value(state, 2);
  3839. string description = lua_interface->GetStringValue(state, 3);
  3840. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3841. float percentage = lua_interface->GetFloatValue(state, 5);
  3842. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3843. int16 icon = lua_interface->GetInt16Value(state, 7);
  3844. if (quest) {
  3845. const char* taskgroup = 0;
  3846. if (str_taskgroup.length() > 0)
  3847. taskgroup = str_taskgroup.c_str();
  3848. int32 spell_id = 0;
  3849. vector<int32>* ids = 0;
  3850. int i = 0;
  3851. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3852. if (ids == 0)
  3853. ids = new vector<int32>;
  3854. ids->push_back(spell_id);
  3855. i++;
  3856. }
  3857. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3858. if (quest_step && icon > 0 && quantity > 0)
  3859. quest_step->SetIcon(icon);
  3860. if (quest->GetPlayer()) {
  3861. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3862. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3863. }
  3864. safe_delete(ids);
  3865. }
  3866. lua_interface->ResetFunctionStack(state);
  3867. return 0;
  3868. }
  3869. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3870. if (!lua_interface)
  3871. return 0;
  3872. Quest* quest = lua_interface->GetQuest(state);
  3873. int32 step = lua_interface->GetInt32Value(state, 2);
  3874. string description = lua_interface->GetStringValue(state, 3);
  3875. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3876. float percentage = lua_interface->GetFloatValue(state, 5);
  3877. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3878. int16 icon = lua_interface->GetInt16Value(state, 7);
  3879. if (quest) {
  3880. const char* taskgroup = 0;
  3881. if (str_taskgroup.length() > 0)
  3882. taskgroup = str_taskgroup.c_str();
  3883. int32 item_id = 0;
  3884. vector<int32>* ids = 0;
  3885. int i = 0;
  3886. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3887. if (ids == 0)
  3888. ids = new vector<int32>;
  3889. ids->push_back(item_id);
  3890. i++;
  3891. }
  3892. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3893. if (quest_step && icon > 0 && quantity > 0)
  3894. quest_step->SetIcon(icon);
  3895. if (quest->GetPlayer()) {
  3896. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3897. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3898. }
  3899. safe_delete(ids);
  3900. }
  3901. lua_interface->ResetFunctionStack(state);
  3902. return 0;
  3903. }
  3904. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3905. if (!lua_interface)
  3906. return 0;
  3907. Quest* quest = lua_interface->GetQuest(state);
  3908. int32 step = lua_interface->GetInt32Value(state, 2);
  3909. string description = lua_interface->GetStringValue(state, 3);
  3910. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3911. float percentage = lua_interface->GetFloatValue(state, 5);
  3912. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3913. int16 icon = lua_interface->GetInt16Value(state, 7);
  3914. if (quest) {
  3915. const char* taskgroup = 0;
  3916. if (str_taskgroup.length() > 0)
  3917. taskgroup = str_taskgroup.c_str();
  3918. int32 item_id = 0;
  3919. vector<int32>* ids = 0;
  3920. int i = 0;
  3921. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3922. if (ids == 0)
  3923. ids = new vector<int32>;
  3924. ids->push_back(item_id);
  3925. i++;
  3926. }
  3927. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3928. if (quest_step && icon > 0 && quantity > 0)
  3929. quest_step->SetIcon(icon);
  3930. if (quest->GetPlayer()) {
  3931. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3932. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3933. }
  3934. safe_delete(ids);
  3935. }
  3936. lua_interface->ResetFunctionStack(state);
  3937. return 0;
  3938. }
  3939. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3940. if (!lua_interface)
  3941. return 0;
  3942. Quest* quest = lua_interface->GetQuest(state);
  3943. string action = lua_interface->GetStringValue(state, 2);
  3944. lua_interface->ResetFunctionStack(state);
  3945. if (quest) {
  3946. if (action.length() > 0)
  3947. quest->SetCompleteAction(action);
  3948. }
  3949. return 0;
  3950. }
  3951. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3952. if (!lua_interface)
  3953. return 0;
  3954. Quest* quest = lua_interface->GetQuest(state);
  3955. int32 step = lua_interface->GetInt32Value(state, 2);
  3956. string action = lua_interface->GetStringValue(state, 3);
  3957. lua_interface->ResetFunctionStack(state);
  3958. if (quest) {
  3959. if (step > 0 && action.length() > 0)
  3960. quest->AddCompleteAction(step, action);
  3961. }
  3962. return 0;
  3963. }
  3964. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3965. if (!lua_interface)
  3966. return 0;
  3967. Quest* quest = lua_interface->GetQuest(state);
  3968. int32 step = lua_interface->GetInt32Value(state, 2);
  3969. string action = lua_interface->GetStringValue(state, 3);
  3970. lua_interface->ResetFunctionStack(state);
  3971. if (quest) {
  3972. if (step > 0 && action.length() > 0)
  3973. quest->AddProgressAction(step, action);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3978. if (!lua_interface)
  3979. return 0;
  3980. Quest* quest = lua_interface->GetQuest(state);
  3981. string description = lua_interface->GetStringValue(state, 2);
  3982. lua_interface->ResetFunctionStack(state);
  3983. if (quest && description.length() > 0)
  3984. quest->SetDescription(description);
  3985. return 0;
  3986. }
  3987. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3988. if (!lua_interface)
  3989. return 0;
  3990. Quest* quest = lua_interface->GetQuest(state);
  3991. string description = lua_interface->GetStringValue(state, 2);
  3992. lua_interface->ResetFunctionStack(state);
  3993. if (quest && description.length() > 0)
  3994. quest->SetCompletedDescription(description);
  3995. return 0;
  3996. }
  3997. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3998. if (!lua_interface)
  3999. return 0;
  4000. Quest* quest = lua_interface->GetQuest(state);
  4001. int32 step = lua_interface->GetInt32Value(state, 2);
  4002. string description = lua_interface->GetStringValue(state, 3);
  4003. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4004. lua_interface->ResetFunctionStack(state);
  4005. if (quest && step > 0 && description.length() > 0) {
  4006. quest->SetTaskGroupDescription(step, description, display_bullets);
  4007. /* if (quest->GetPlayer()) {
  4008. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4009. if (client)
  4010. client->SendQuestUpdateStep(quest, step, false);
  4011. }*/
  4012. }
  4013. return 0;
  4014. }
  4015. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4016. if (!lua_interface)
  4017. return 0;
  4018. Quest* quest = lua_interface->GetQuest(state);
  4019. int32 step = lua_interface->GetInt32Value(state, 2);
  4020. string description = lua_interface->GetStringValue(state, 3);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest && step > 0 && description.length() > 0) {
  4023. quest->SetStepDescription(step, description);
  4024. /*if (quest->GetPlayer()) {
  4025. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4026. if (client)
  4027. client->SendQuestUpdateStepImmediately(quest, step);
  4028. }*/
  4029. }
  4030. return 0;
  4031. }
  4032. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4033. Quest* quest = lua_interface->GetQuest(state);
  4034. string zone = lua_interface->GetStringValue(state, 2);
  4035. lua_interface->ResetFunctionStack(state);
  4036. if (quest && zone.length() > 0)
  4037. quest->SetZone(zone);
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4041. if (!lua_interface)
  4042. return 0;
  4043. Quest* quest = lua_interface->GetQuest(state);
  4044. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4045. lua_interface->ResetFunctionStack(state);
  4046. if (quest && spawn) {
  4047. if (spawn->IsPlayer()) {
  4048. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4049. if (client)
  4050. {
  4051. client->AddPendingQuestAcceptReward(quest);
  4052. client->AddPendingQuestReward(quest);
  4053. }
  4054. }
  4055. }
  4056. return 0;
  4057. }
  4058. int EQ2Emu_lua_Harvest(lua_State* state) {
  4059. if (!lua_interface)
  4060. return 0;
  4061. Spawn* player = lua_interface->GetSpawn(state);
  4062. Spawn* node = lua_interface->GetSpawn(state, 2);
  4063. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4064. Client* client = player->GetZone()->GetClientBySpawn(player);
  4065. if (client) {
  4066. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4067. ((GroundSpawn*)node)->ProcessHarvest(client);
  4068. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4069. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4070. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4071. }
  4072. }
  4073. }
  4074. else if (player && player->IsPlayer()) {
  4075. Client* client = player->GetZone()->GetClientBySpawn(player);
  4076. if (client)
  4077. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4078. }
  4079. lua_interface->ResetFunctionStack(state);
  4080. return 0;
  4081. }
  4082. int EQ2Emu_lua_Bind(lua_State* state) {
  4083. if (!lua_interface)
  4084. return 0;
  4085. Spawn* spawn = lua_interface->GetSpawn(state);
  4086. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4087. float x = lua_interface->GetFloatValue(state, 3);
  4088. float y = lua_interface->GetFloatValue(state, 4);
  4089. float z = lua_interface->GetFloatValue(state, 5);
  4090. float h = lua_interface->GetFloatValue(state, 6);
  4091. lua_interface->ResetFunctionStack(state);
  4092. if (!spawn) {
  4093. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4094. return 0;
  4095. }
  4096. if (!spawn->IsPlayer()) {
  4097. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4098. return 0;
  4099. }
  4100. if (zone_id == 0) {
  4101. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4102. if (!client) {
  4103. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4104. return 0;
  4105. }
  4106. if (!client->Bind())
  4107. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4108. }
  4109. else {
  4110. Player* player = (Player*)spawn;
  4111. player->GetPlayerInfo()->SetBindZone(zone_id);
  4112. player->GetPlayerInfo()->SetBindX(x);
  4113. player->GetPlayerInfo()->SetBindY(y);
  4114. player->GetPlayerInfo()->SetBindZ(z);
  4115. player->GetPlayerInfo()->SetBindHeading(h);
  4116. }
  4117. return 0;
  4118. }
  4119. int EQ2Emu_lua_Gate(lua_State* state) {
  4120. if (!lua_interface)
  4121. return 0;
  4122. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4123. Spawn* spawn = lua_interface->GetSpawn(state);
  4124. lua_interface->ResetFunctionStack(state);
  4125. if (spawn) {
  4126. if (spawn->IsPlayer()) {
  4127. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4128. if (client) {
  4129. if (!client->Gate((spell != nullptr) ? true : false))
  4130. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4131. }
  4132. }
  4133. }
  4134. return 0;
  4135. }
  4136. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4137. if (!lua_interface)
  4138. return 0;
  4139. bool ret = false;
  4140. Spawn* spawn = lua_interface->GetSpawn(state);
  4141. lua_interface->ResetFunctionStack(state);
  4142. if (spawn) {
  4143. if (spawn->IsPlayer()) {
  4144. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4145. if (client)
  4146. ret = client->BindAllowed();
  4147. }
  4148. }
  4149. lua_interface->SetBooleanValue(state, ret);
  4150. return 1;
  4151. }
  4152. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4153. if (!lua_interface)
  4154. return 0;
  4155. bool ret = false;
  4156. Spawn* spawn = lua_interface->GetSpawn(state);
  4157. lua_interface->ResetFunctionStack(state);
  4158. if (spawn) {
  4159. if (spawn->IsPlayer()) {
  4160. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4161. if (client)
  4162. ret = client->GateAllowed();
  4163. }
  4164. }
  4165. lua_interface->SetBooleanValue(state, ret);
  4166. return 1;
  4167. }
  4168. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4169. Spawn* spawn = lua_interface->GetSpawn(state);
  4170. lua_interface->ResetFunctionStack(state);
  4171. if (spawn) {
  4172. lua_interface->SetBooleanValue(state, spawn->Alive());
  4173. return 1;
  4174. }
  4175. return 0;
  4176. }
  4177. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4178. if (!lua_interface)
  4179. return 0;
  4180. Spawn* spawn = lua_interface->GetSpawn(state);
  4181. lua_interface->ResetFunctionStack(state);
  4182. if (spawn && spawn->IsEntity()) {
  4183. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4184. return 1;
  4185. }
  4186. return 0;
  4187. }
  4188. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4189. Spawn* spawn = lua_interface->GetSpawn(state);
  4190. string message = lua_interface->GetStringValue(state, 2);
  4191. string color_str = lua_interface->GetStringValue(state, 3);
  4192. lua_interface->ResetFunctionStack(state);
  4193. int8 color = CHANNEL_NARRATIVE;
  4194. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4195. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4196. if (client) {
  4197. if (color_str.length() > 0) {
  4198. // leave for backwards compat, but all future should just use the number
  4199. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4200. color = CHANNEL_COLOR_RED;
  4201. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4202. color = CHANNEL_COLOR_YELLOW;
  4203. else
  4204. {
  4205. // use a number to specify the channel as per Commands/Commands.h defines
  4206. color = (int8)atoul(color_str.c_str());
  4207. }
  4208. }
  4209. client->SimpleMessage(color, message.c_str());
  4210. }
  4211. }
  4212. return 0;
  4213. }
  4214. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4215. Spawn* spawn = lua_interface->GetSpawn(state);
  4216. string message = lua_interface->GetStringValue(state, 2);
  4217. int8 red = lua_interface->GetInt8Value(state, 3);
  4218. int8 green = lua_interface->GetInt8Value(state, 4);
  4219. int8 blue = lua_interface->GetInt8Value(state, 5);
  4220. lua_interface->ResetFunctionStack(state);
  4221. if (!spawn) {
  4222. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4223. return 0;
  4224. }
  4225. int32 words = ::CountWordsInString(message.c_str());
  4226. if (words < 5)
  4227. words = 5;
  4228. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4229. if (client)
  4230. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4231. return 0;
  4232. }
  4233. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4234. Spawn* spawn = lua_interface->GetSpawn(state);
  4235. int8 param = lua_interface->GetInt8Value(state, 2);
  4236. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4237. int8 value = lua_interface->GetInt8Value(state, 4);
  4238. lua_interface->ResetFunctionStack(state);
  4239. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4240. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4241. if (client) {
  4242. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4243. switch (param) {
  4244. case 1: {
  4245. packet->setDataByName("parameter1", param_value);
  4246. break;
  4247. }
  4248. case 2: {
  4249. packet->setDataByName("parameter2", param_value);
  4250. break;
  4251. }
  4252. case 3: {
  4253. packet->setDataByName("parameter3", param_value);
  4254. break;
  4255. }
  4256. case 4: {
  4257. packet->setDataByName("parameter4", param_value);
  4258. break;
  4259. }
  4260. case 5: {
  4261. packet->setDataByName("parameter5", param_value);
  4262. break;
  4263. }
  4264. }
  4265. packet->setDataByName("value", value);
  4266. client->QueuePacket(packet->serialize());
  4267. safe_delete(packet);
  4268. }
  4269. }
  4270. return 0;
  4271. }
  4272. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4273. Spawn* spawn = lua_interface->GetSpawn(state);
  4274. lua_interface->ResetFunctionStack(state);
  4275. if (spawn && spawn->IsPlayer()) {
  4276. if (((Player*)spawn)->GetIsTracking())
  4277. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4278. else
  4279. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4280. }
  4281. return 0;
  4282. }
  4283. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4284. Spawn* player = lua_interface->GetSpawn(state);
  4285. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4286. string name = lua_interface->GetStringValue(state, 3);
  4287. float distance = lua_interface->GetFloatValue(state, 4);
  4288. string command = lua_interface->GetStringValue(state, 5);
  4289. string error_text = lua_interface->GetStringValue(state, 6);
  4290. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4291. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4292. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4293. lua_interface->ResetFunctionStack(state);
  4294. if (spawn) {
  4295. if (distance == 0)
  4296. distance = 10.0f;
  4297. if (command.length() == 0)
  4298. command = name;
  4299. if (command.length() < 1 && name.length() < 1)
  4300. {
  4301. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4302. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4303. spawn->RemovePrimaryCommands();
  4304. }
  4305. else
  4306. {
  4307. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4308. }
  4309. }
  4310. return 0;
  4311. }
  4312. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4313. if (!lua_interface)
  4314. return 0;
  4315. Spawn* player = lua_interface->GetSpawn(state);
  4316. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4317. int16 tier = lua_interface->GetInt16Value(state, 3);
  4318. lua_interface->ResetFunctionStack(state);
  4319. if (player && player->IsPlayer()) {
  4320. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4321. return 1;
  4322. }
  4323. return 0;
  4324. }
  4325. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4326. if (!lua_interface)
  4327. return 0;
  4328. Spawn* player = lua_interface->GetSpawn(state);
  4329. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4330. int16 tier = lua_interface->GetInt16Value(state, 3);
  4331. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4332. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4333. bool add_to_hotbar = true;
  4334. if (num_args > 4) {
  4335. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4336. }
  4337. lua_interface->ResetFunctionStack(state);
  4338. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4339. if (player && spell && player->IsPlayer()) {
  4340. Client* client = player->GetClient();
  4341. if (client) {
  4342. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4343. {
  4344. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4345. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4346. client->GetPlayer()->UnlockSpell(spell);
  4347. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4348. }
  4349. else
  4350. {
  4351. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4352. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4353. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4354. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4355. client->GetPlayer()->UnlockSpell(spell);
  4356. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4357. }
  4358. //if (client ) {
  4359. // ((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);
  4360. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4361. if (outapp)
  4362. client->QueuePacket(outapp);
  4363. }
  4364. }
  4365. return 0;
  4366. }
  4367. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4368. if (!lua_interface)
  4369. return 0;
  4370. Spawn* player = lua_interface->GetSpawn(state);
  4371. lua_interface->ResetFunctionStack(state);
  4372. if (player && player->IsPlayer()) {
  4373. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4374. return 1;
  4375. }
  4376. return 0;
  4377. }
  4378. int EQ2Emu_lua_Attack(lua_State* state) {
  4379. if (lua_interface) {
  4380. Spawn* npc = lua_interface->GetSpawn(state);
  4381. Spawn* player = lua_interface->GetSpawn(state, 2);
  4382. lua_interface->ResetFunctionStack(state);
  4383. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4384. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4385. }
  4386. return 0;
  4387. }
  4388. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4389. if (lua_interface) {
  4390. Spawn* target = lua_interface->GetSpawn(state);
  4391. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4392. lua_interface->ResetFunctionStack(state);
  4393. if (target && target->GetZone())
  4394. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4395. }
  4396. return 0;
  4397. }
  4398. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4399. Spawn* player;
  4400. if (lua_interface) {
  4401. player = lua_interface->GetSpawn(state);
  4402. lua_interface->ResetFunctionStack(state);
  4403. if (player && player->IsPlayer()) {
  4404. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4405. return 1;
  4406. }
  4407. }
  4408. return 0;
  4409. }
  4410. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4411. Spawn* player;
  4412. Client* client;
  4413. if (lua_interface) {
  4414. player = lua_interface->GetSpawn(state);
  4415. lua_interface->ResetFunctionStack(state);
  4416. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4417. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4418. client->HandInCollections();
  4419. }
  4420. return 0;
  4421. }
  4422. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4423. Spawn* widget;
  4424. if (lua_interface) {
  4425. widget = lua_interface->GetSpawn(state);
  4426. lua_interface->ResetFunctionStack(state);
  4427. if (widget && widget->IsWidget())
  4428. ((Widget*)widget)->HandleUse(nullptr, "");
  4429. }
  4430. return 0;
  4431. }
  4432. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4433. Spawn* spawn = 0;
  4434. int32 primary_list = 0;
  4435. int32 secondary_list = 0;
  4436. if (lua_interface) {
  4437. spawn = lua_interface->GetSpawn(state);
  4438. primary_list = lua_interface->GetInt32Value(state, 2);
  4439. secondary_list = lua_interface->GetInt32Value(state, 3);
  4440. lua_interface->ResetFunctionStack(state);
  4441. if (!spawn->IsNPC()) {
  4442. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4443. return 0;
  4444. }
  4445. NPC* npc = (NPC*)spawn;
  4446. npc->SetPrimarySpellList(primary_list);
  4447. npc->SetSecondarySpellList(secondary_list);
  4448. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4449. }
  4450. return 0;
  4451. }
  4452. int EQ2Emu_lua_GetPet(lua_State* state) {
  4453. if (!lua_interface)
  4454. return 0;
  4455. Spawn* spawn = lua_interface->GetSpawn(state);
  4456. lua_interface->ResetFunctionStack(state);
  4457. if (spawn) {
  4458. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4459. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4460. return 1;
  4461. }
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4466. if (!lua_interface)
  4467. return 0;
  4468. Spawn* spawn = lua_interface->GetSpawn(state);
  4469. lua_interface->ResetFunctionStack(state);
  4470. if (spawn) {
  4471. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4472. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4473. return 1;
  4474. }
  4475. }
  4476. return 0;
  4477. }
  4478. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4479. if (!lua_interface)
  4480. return 0;
  4481. Spawn* spawn = lua_interface->GetSpawn(state);
  4482. lua_interface->ResetFunctionStack(state);
  4483. if (spawn) {
  4484. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4485. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4486. return 1;
  4487. }
  4488. }
  4489. return 0;
  4490. }
  4491. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4492. if (!lua_interface)
  4493. return 0;
  4494. Spawn* spawn = lua_interface->GetSpawn(state);
  4495. lua_interface->ResetFunctionStack(state);
  4496. if (spawn) {
  4497. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4498. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4499. return 1;
  4500. }
  4501. }
  4502. return 0;
  4503. }
  4504. int EQ2Emu_lua_Charm(lua_State* state) {
  4505. if (!lua_interface)
  4506. return 0;
  4507. Spawn* owner = lua_interface->GetSpawn(state);
  4508. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4509. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4510. lua_interface->ResetFunctionStack(state);
  4511. if (!luaspell) {
  4512. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4513. return 0;
  4514. }
  4515. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4516. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4517. pet->SetPet(true);
  4518. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4519. ((NPC*)pet)->SetOwner((Entity*)owner);
  4520. // If owner is player and player does not have a summoned pet set the players charsheet
  4521. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4522. Player* player = (Player*)owner;
  4523. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4524. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4525. player->GetInfoStruct()->set_pet_movement(2);
  4526. player->GetInfoStruct()->set_pet_behavior(3);
  4527. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4528. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4529. // Make sure the values get sent to the client
  4530. player->SetCharSheetChanged(true);
  4531. }
  4532. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4533. pet->SetSpawnScript("");
  4534. // Set faction to the same as the owner
  4535. pet->SetFactionID(owner->GetFactionID());
  4536. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4537. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4538. // Clear hate list
  4539. ((NPC*)pet)->Brain()->ClearHate();
  4540. // Set the brain to a pet brain
  4541. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4542. }
  4543. return 0;
  4544. }
  4545. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4546. if (!lua_interface)
  4547. return 0;
  4548. Spawn* spawn = lua_interface->GetSpawn(state);
  4549. lua_interface->ResetFunctionStack(state);
  4550. if (!spawn) {
  4551. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4552. return 0;
  4553. }
  4554. vector<Spawn*> groupMembers;
  4555. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4556. groupMembers = *spawn->GetSpawnGroup();
  4557. }
  4558. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4559. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4560. deque<GroupMemberInfo*>::iterator itr;
  4561. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4562. if (group)
  4563. {
  4564. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4565. deque<GroupMemberInfo*>* members = group->GetMembers();
  4566. GroupMemberInfo* info = 0;
  4567. for (itr = members->begin(); itr != members->end(); itr++) {
  4568. info = *itr;
  4569. if (info->client)
  4570. groupMembers.push_back(info->client->GetPlayer());
  4571. }
  4572. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4573. }
  4574. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4575. }
  4576. else
  4577. return 0;
  4578. lua_createtable(state, groupMembers.size(), 0);
  4579. int newTable = lua_gettop(state);
  4580. for (int32 i = 0; i < groupMembers.size(); i++) {
  4581. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4582. lua_rawseti(state, newTable, i + 1);
  4583. }
  4584. return 1;
  4585. }
  4586. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4587. if (!lua_interface)
  4588. return 0;
  4589. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4590. lua_interface->SetOptionWindowValue(state, option_window);
  4591. return 1;
  4592. }
  4593. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4597. if (option_window) {
  4598. OptionWindowOption option_window_option;
  4599. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4600. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4601. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4602. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4603. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4604. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4605. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4606. option_window->push_back(option_window_option);
  4607. }
  4608. return 0;
  4609. }
  4610. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4611. if (!lua_interface)
  4612. return 0;
  4613. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4614. Spawn* player = lua_interface->GetSpawn(state, 2);
  4615. string window_title = lua_interface->GetStringValue(state, 3);
  4616. string cancel_command = lua_interface->GetStringValue(state, 4);
  4617. Client* client = player->GetZone()->GetClientBySpawn(player);
  4618. if (option_window && window_title.length() > 0 && client) {
  4619. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4620. if (!packet)
  4621. return 0;
  4622. packet->setDataByName("title_text", window_title.c_str());
  4623. if (cancel_command.length() > 0)
  4624. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4625. packet->setArrayLengthByName("num_selections", option_window->size());
  4626. vector<OptionWindowOption>::iterator itr;
  4627. int8 i = 0;
  4628. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4629. OptionWindowOption opt = *itr;
  4630. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4631. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4632. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4633. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4634. if (opt.optionCommand.length() > 0)
  4635. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4636. if (opt.optionConfirmTitle.length() > 0)
  4637. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4638. i++;
  4639. }
  4640. client->QueuePacket(packet->serialize());
  4641. safe_delete(option_window);
  4642. safe_delete(packet);
  4643. }
  4644. return 0;
  4645. }
  4646. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4647. if (!lua_interface)
  4648. return 0;
  4649. Spawn* spawn = lua_interface->GetSpawn(state);
  4650. if (spawn) {
  4651. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4652. return 1;
  4653. }
  4654. else
  4655. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4656. return 0;
  4657. }
  4658. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4659. if (!lua_interface)
  4660. return 0;
  4661. Spawn* spawn = lua_interface->GetSpawn(state);
  4662. if (spawn) {
  4663. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4664. return 1;
  4665. }
  4666. else
  4667. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4671. if (!lua_interface)
  4672. return 0;
  4673. Spawn* spawn = lua_interface->GetSpawn(state);
  4674. if (spawn) {
  4675. int8 class_id = spawn->GetTradeskillClass();
  4676. // Need to add 42 for the offset in the array
  4677. class_id += 44;
  4678. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4679. return 1;
  4680. }
  4681. else
  4682. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4686. if (!lua_interface)
  4687. return 0;
  4688. Spawn* spawn = lua_interface->GetSpawn(state);
  4689. int16 level = lua_interface->GetInt8Value(state, 2);
  4690. if (spawn) {
  4691. if (spawn->IsPlayer())
  4692. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4693. else
  4694. spawn->SetTSLevel(level);
  4695. }
  4696. else
  4697. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4698. return 0;
  4699. }
  4700. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4701. if (!lua_interface)
  4702. return 0;
  4703. Spawn* spawn = lua_interface->GetSpawn(state);
  4704. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4705. if (spawn) {
  4706. spawn->SetAttackable(attackable);
  4707. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4708. }
  4709. return 0;
  4710. }
  4711. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4712. // Check to see if we have a valid lua_interface
  4713. if (!lua_interface)
  4714. return 0;
  4715. // Get the spawn that is getting the pet
  4716. Spawn* spawn = lua_interface->GetSpawn(state);
  4717. // Get the DB ID of the pet
  4718. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4719. // The max level the pet can gain
  4720. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4721. // Get the spell that this command was called from
  4722. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4723. // Check to make sure the spawn pointer is valid
  4724. if (!spawn) {
  4725. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4726. return 0;
  4727. }
  4728. // Check to make sure the spawn is an entity
  4729. if (!spawn->IsEntity()) {
  4730. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4731. return 0;
  4732. }
  4733. // Check to make sure the spawn doesn't already have a pet of this type
  4734. if (((Entity*)spawn)->GetPet()) {
  4735. if (spawn->IsPlayer()) {
  4736. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4737. if (client)
  4738. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4739. }
  4740. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4741. return 0;
  4742. }
  4743. // Check to see if the DB ID for the pet is set
  4744. if (pet_id == 0) {
  4745. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4746. return 0;
  4747. }
  4748. // Check to see if the pointer to the spell is valid
  4749. if (!luaspell) {
  4750. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4751. return 0;
  4752. }
  4753. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4754. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4755. if (!pet) {
  4756. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4757. return 0;
  4758. }
  4759. // Check to make sure the pet is an npc
  4760. if (!pet->IsNPC()) {
  4761. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4762. return 0;
  4763. }
  4764. // Spawn the pet at the same location as the owner
  4765. pet->SetX(spawn->GetX());
  4766. pet->SetY(spawn->GetY());
  4767. pet->SetZ(spawn->GetZ());
  4768. pet->SetLocation(spawn->GetLocation());
  4769. pet->SetHeading(spawn->GetHeading());
  4770. spawn->GetZone()->AddSpawn(pet);
  4771. /*
  4772. const char* spawn_script = world.GetSpawnScript(pet_id);
  4773. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4774. spawn->SetSpawnScript(string(spawn_script));
  4775. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4776. }*/
  4777. // Get a random pet name
  4778. string random_pet_name;
  4779. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4780. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4781. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4782. // If player set various values for the char sheet (pet window)
  4783. if (spawn->IsPlayer()) {
  4784. Player* player = (Player*)spawn;
  4785. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4786. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4787. player->GetInfoStruct()->set_pet_movement(2);
  4788. player->GetInfoStruct()->set_pet_behavior(3);
  4789. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4790. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4791. // Make sure the values get sent to the client
  4792. player->SetCharSheetChanged(true);
  4793. }
  4794. // Set the pets name
  4795. pet->SetName(random_pet_name.c_str());
  4796. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4797. if (max_level > 0)
  4798. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4799. else
  4800. pet->SetLevel(spawn->GetLevel());
  4801. // Set the max level this pet can reach
  4802. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4803. // Set the faction of the pet to the same faction as the owner
  4804. pet->SetFactionID(spawn->GetFactionID());
  4805. // Set the spawn as a pet
  4806. pet->SetPet(true);
  4807. // Give a pointer of the owner to the pet
  4808. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4809. // Give a pointer of the pet to the owner
  4810. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4811. // Set the pet type
  4812. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4813. // Set the spell id used to create this pet
  4814. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4815. // Set the spell tier used to create this pet
  4816. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4817. // Set the pets spawn type to 6
  4818. pet->SetSpawnType(6);
  4819. // Set the pets brain
  4820. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4821. // Check to see if the pet has a subtitle
  4822. if (strlen(pet->GetSubTitle()) > 0) {
  4823. // Add the players name to the front of the sub title
  4824. string pet_subtitle;
  4825. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4826. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4827. // Set the pets subtitle to the new one
  4828. pet->SetSubTitle(pet_subtitle.c_str());
  4829. }
  4830. // Add the "Pet Options" entity command to the pet
  4831. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4832. // Set the pet as the return value for this function
  4833. lua_interface->SetSpawnValue(state, pet);
  4834. return 1;
  4835. }
  4836. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4837. if (!lua_interface)
  4838. return 0;
  4839. Spawn* spawn = lua_interface->GetSpawn(state);
  4840. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4841. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4842. if (!spawn) {
  4843. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. if (!spawn->IsEntity()) {
  4847. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (((Entity*)spawn)->GetDeityPet()) {
  4851. if (spawn->IsPlayer()) {
  4852. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4853. if (client)
  4854. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4855. }
  4856. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4857. return 0;
  4858. }
  4859. if (pet_id == 0) {
  4860. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4861. return 0;
  4862. }
  4863. if (!luaspell) {
  4864. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4868. if (!pet) {
  4869. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4870. return 0;
  4871. }
  4872. if (!pet->IsNPC()) {
  4873. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4874. return 0;
  4875. }
  4876. pet->SetX(spawn->GetX());
  4877. pet->SetY(spawn->GetY());
  4878. pet->SetZ(spawn->GetZ());
  4879. pet->SetLocation(spawn->GetLocation());
  4880. pet->SetHeading(spawn->GetHeading());
  4881. spawn->GetZone()->AddSpawn(pet);
  4882. string random_pet_name;
  4883. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4884. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4885. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4886. pet->SetName(random_pet_name.c_str());
  4887. pet->SetLevel(spawn->GetLevel());
  4888. pet->SetFactionID(spawn->GetFactionID());
  4889. pet->SetPet(true);
  4890. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4891. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4892. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4893. pet->SetSpawnType(6);
  4894. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4895. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4896. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4897. if (strlen(pet->GetSubTitle()) > 0) {
  4898. string pet_subtitle;
  4899. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4900. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4901. pet->SetSubTitle(pet_subtitle.c_str());
  4902. }
  4903. // deity and cosmetic pets are not attackable
  4904. pet->SetAttackable(false);
  4905. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4906. lua_interface->SetSpawnValue(state, pet);
  4907. return 1;
  4908. }
  4909. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4910. if (!lua_interface)
  4911. return 0;
  4912. Spawn* spawn = lua_interface->GetSpawn(state);
  4913. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4914. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4915. if (!spawn) {
  4916. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4917. return 0;
  4918. }
  4919. if (!spawn->IsEntity()) {
  4920. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4921. return 0;
  4922. }
  4923. if (((Entity*)spawn)->GetCosmeticPet()) {
  4924. if (spawn->IsPlayer()) {
  4925. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4926. if (client)
  4927. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4928. }
  4929. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4930. return 0;
  4931. }
  4932. if (pet_id == 0) {
  4933. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4934. return 0;
  4935. }
  4936. if (!luaspell) {
  4937. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4941. if (!pet) {
  4942. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4943. return 0;
  4944. }
  4945. if (!pet->IsNPC()) {
  4946. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4947. return 0;
  4948. }
  4949. pet->SetX(spawn->GetX());
  4950. pet->SetY(spawn->GetY());
  4951. pet->SetZ(spawn->GetZ());
  4952. pet->SetLocation(spawn->GetLocation());
  4953. pet->SetHeading(spawn->GetHeading());
  4954. spawn->GetZone()->AddSpawn(pet);
  4955. string random_pet_name;
  4956. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4957. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4958. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4959. pet->SetName(random_pet_name.c_str());
  4960. pet->SetLevel(spawn->GetLevel());
  4961. pet->SetFactionID(spawn->GetFactionID());
  4962. pet->SetPet(true);
  4963. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4964. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4965. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4966. pet->SetSpawnType(6);
  4967. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4968. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4969. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4970. if (strlen(pet->GetSubTitle()) > 0) {
  4971. string pet_subtitle;
  4972. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4973. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4974. pet->SetSubTitle(pet_subtitle.c_str());
  4975. }
  4976. pet->SetAttackable(false);
  4977. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4978. lua_interface->SetSpawnValue(state, pet);
  4979. return 1;
  4980. }
  4981. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4982. if (!lua_interface)
  4983. return 0;
  4984. Spawn* spawn = lua_interface->GetSpawn(state);
  4985. if (!spawn) {
  4986. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4987. return 0;
  4988. }
  4989. if (!spawn->IsPet()) {
  4990. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4991. return 0;
  4992. }
  4993. if (!((NPC*)spawn)->IsDismissing())
  4994. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4995. return 0;
  4996. }
  4997. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4998. if (!lua_interface)
  4999. return 0;
  5000. Quest* quest = lua_interface->GetQuest(state);
  5001. if (!quest) {
  5002. 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));
  5003. return 0;
  5004. }
  5005. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5006. if (feather_color > 0)
  5007. quest->SetFeatherColor(feather_color);
  5008. return 0;
  5009. }
  5010. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5011. if (!lua_interface)
  5012. return 0;
  5013. Spawn* spawn = lua_interface->GetSpawn(state);
  5014. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5015. if (!spawn) {
  5016. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5017. return 0;
  5018. }
  5019. if (!spawn2) {
  5020. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5021. return 0;
  5022. }
  5023. spawn->RemoveSpawnAccess(spawn2);
  5024. return 0;
  5025. }
  5026. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5027. if (!lua_interface)
  5028. return 0;
  5029. ZoneServer* zone = lua_interface->GetZone(state);
  5030. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5031. if (!zone) {
  5032. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5033. return 0;
  5034. }
  5035. if (location_id == 0) {
  5036. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5037. return 0;
  5038. }
  5039. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5040. if (!location) {
  5041. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5042. return 0;
  5043. }
  5044. Spawn* spawn = 0;
  5045. if (location->entities[0]) {
  5046. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5047. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5048. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5049. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5050. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5051. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5052. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5053. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5054. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5055. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5056. if(spawn && spawn->IsOmittedByDBFlag())
  5057. {
  5058. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5059. safe_delete(spawn);
  5060. spawn = 0;
  5061. return 0;
  5062. }
  5063. if (spawn) {
  5064. const char* script = 0;
  5065. for (int x = 0; x < 3; x++) {
  5066. switch (x) {
  5067. case 0:
  5068. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5069. break;
  5070. case 1:
  5071. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5072. break;
  5073. case 2:
  5074. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5075. break;
  5076. }
  5077. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5078. spawn->SetSpawnScript(string(script));
  5079. break;
  5080. }
  5081. }
  5082. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5083. lua_interface->SetSpawnValue(state, spawn);
  5084. return 1;
  5085. }
  5086. else {
  5087. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5088. safe_delete(spawn);
  5089. }
  5090. }
  5091. return 0;
  5092. }
  5093. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5094. if (!lua_interface)
  5095. return 0;
  5096. Spawn* caster = lua_interface->GetSpawn(state);
  5097. Spawn* target = lua_interface->GetSpawn(state, 2);
  5098. int32 id = lua_interface->GetInt32Value(state, 3);
  5099. string command = lua_interface->GetStringValue(state, 4);
  5100. if (!caster) {
  5101. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5102. return 0;
  5103. }
  5104. if (!target) {
  5105. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5106. return 0;
  5107. }
  5108. if (!caster->IsPlayer()) {
  5109. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5110. return 0;
  5111. }
  5112. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5113. if (!entity_command) {
  5114. 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());
  5115. return 0;
  5116. }
  5117. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5118. if (!client) {
  5119. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5120. return 0;
  5121. }
  5122. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5123. return 0;
  5124. }
  5125. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5126. if (!lua_interface)
  5127. return 0;
  5128. Spawn* spawn = lua_interface->GetSpawn(state);
  5129. if (!spawn) {
  5130. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5131. return 0;
  5132. }
  5133. if (!spawn->IsNPC()) {
  5134. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5135. return 0;
  5136. }
  5137. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5138. return 0;
  5139. }
  5140. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5141. if (!lua_interface)
  5142. return 0;
  5143. Spawn* spawn = lua_interface->GetSpawn(state);
  5144. int16 tick = lua_interface->GetInt16Value(state, 2);
  5145. if (!spawn) {
  5146. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5147. return 0;
  5148. }
  5149. if (!spawn->IsNPC()) {
  5150. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5151. return 0;
  5152. }
  5153. if (tick < 20) {
  5154. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5155. return 0;
  5156. }
  5157. ((NPC*)spawn)->Brain()->SetTick(tick);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Spawn* spawn = lua_interface->GetSpawn(state);
  5164. Spawn* target = lua_interface->GetSpawn(state, 2);
  5165. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5166. if (!spawn) {
  5167. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5168. return 0;
  5169. }
  5170. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5171. spawn->SetFollowTarget(target, follow_distance);
  5172. return 0;
  5173. }
  5174. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5175. if (!lua_interface)
  5176. return 0;
  5177. Spawn* spawn = lua_interface->GetSpawn(state);
  5178. if (!spawn) {
  5179. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5180. return 0;
  5181. }
  5182. Spawn* target = spawn->GetFollowTarget();
  5183. if (target) {
  5184. lua_interface->SetSpawnValue(state, target);
  5185. return 1;
  5186. }
  5187. return 0;
  5188. }
  5189. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5190. if (!lua_interface)
  5191. return 0;
  5192. Spawn* spawn = lua_interface->GetSpawn(state);
  5193. if (!spawn) {
  5194. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5195. return 0;
  5196. }
  5197. if (spawn->following)
  5198. spawn->following = false;
  5199. else
  5200. spawn->following = true;
  5201. return 0;
  5202. }
  5203. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5204. if (!lua_interface)
  5205. return 0;
  5206. Spawn* spawn = lua_interface->GetSpawn(state);
  5207. if (!spawn) {
  5208. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5209. return 0;
  5210. }
  5211. lua_interface->SetBooleanValue(state, spawn->following);
  5212. return 1;
  5213. }
  5214. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5215. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5216. // I will attempt to explain how this function works for future refrence
  5217. // Fist lets make sure lua_interface is valid, if not return out
  5218. if (!lua_interface)
  5219. return 0;
  5220. // Next we grab the first 2 params same as we usually would
  5221. Spawn* spawn = lua_interface->GetSpawn(state);
  5222. string var = lua_interface->GetStringValue(state, 2);
  5223. // 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
  5224. // 1 = Spawn
  5225. // 2 = Zone
  5226. // 3 = Item
  5227. // 4 = Quest
  5228. // 5 = String
  5229. // 6 = nil (null)
  5230. int8 dataType = 0;
  5231. // Define pointers for each potential type
  5232. Spawn* spawnVal = 0;
  5233. ZoneServer* zone = 0;
  5234. Item* item = 0;
  5235. Quest* quest = 0;
  5236. string val;
  5237. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5238. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5239. // options window are also light user data be we do not handle those.
  5240. // We check with lua_islightuserdata(lua_State*, index)
  5241. if (lua_islightuserdata(state, 3)) {
  5242. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5243. // and convert it to LUAUserData*
  5244. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5245. // Check to make sure the data we got is valid, if not give an error
  5246. if (!data || !data->IsCorrectlyInitialized()) {
  5247. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5248. }
  5249. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5250. else if (data->IsSpawn()) {
  5251. spawnVal = data->spawn;
  5252. dataType = 1;
  5253. }
  5254. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5255. else if (data->IsZone()) {
  5256. zone = data->zone;
  5257. dataType = 2;
  5258. }
  5259. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5260. else if (data->IsItem()) {
  5261. item = data->item;
  5262. dataType = 3;
  5263. }
  5264. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5265. else if (data->IsQuest()) {
  5266. quest = data->quest;
  5267. dataType = 4;
  5268. }
  5269. }
  5270. // Wasn't light user data, check if it is nil(null)
  5271. else if (lua_isnil(state, 3)) {
  5272. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5273. dataType = 6;
  5274. }
  5275. // Wasn't light user data or nil (null), must be a string
  5276. else {
  5277. // Set the string and dataType variable
  5278. val = lua_interface->GetStringValue(state, 3);
  5279. dataType = 5;
  5280. }
  5281. // We now have all the params, lets check to make sure they are valid
  5282. if (!spawn) {
  5283. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. if (var.length() == 0) {
  5287. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5288. return 0;
  5289. }
  5290. if (dataType == 0) {
  5291. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5292. return 0;
  5293. }
  5294. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5295. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5296. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5297. switch (dataType) {
  5298. case 1:
  5299. // 1 = Spawn
  5300. spawn->AddTempVariable(var, spawnVal);
  5301. break;
  5302. case 2:
  5303. // 2 = Zone
  5304. spawn->AddTempVariable(var, zone);
  5305. break;
  5306. case 3:
  5307. // 3 = Item
  5308. spawn->AddTempVariable(var, item);
  5309. break;
  5310. case 4:
  5311. // 4 = Quest
  5312. spawn->AddTempVariable(var, quest);
  5313. break;
  5314. case 5:
  5315. // 5 = String
  5316. spawn->AddTempVariable(var, val);
  5317. break;
  5318. case 6:
  5319. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5320. spawn->DeleteTempVariable(var);
  5321. break;
  5322. }
  5323. // And we are done so return out
  5324. return 0;
  5325. }
  5326. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5327. if (!lua_interface)
  5328. return 0;
  5329. Spawn* spawn = lua_interface->GetSpawn(state);
  5330. string var = lua_interface->GetStringValue(state, 2);
  5331. if (!spawn) {
  5332. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5333. return 0;
  5334. }
  5335. if (var.length() == 0) {
  5336. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5337. return 0;
  5338. }
  5339. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5340. int8 type = spawn->GetTempVariableType(var);
  5341. Spawn* spawn2 = 0;
  5342. ZoneServer* zone = 0;
  5343. Item* item = 0;
  5344. Quest* quest = 0;
  5345. // Set the lua function return value based on the type of data the variable contains
  5346. switch (type) {
  5347. case 1:
  5348. spawn2 = spawn->GetTempVariableSpawn(var);
  5349. if (!spawn2)
  5350. return 0;
  5351. lua_interface->SetSpawnValue(state, spawn2);
  5352. break;
  5353. case 2:
  5354. zone = spawn->GetTempVariableZone(var);
  5355. if (!zone)
  5356. return 0;
  5357. lua_interface->SetZoneValue(state, zone);
  5358. break;
  5359. case 3:
  5360. item = spawn->GetTempVariableItem(var);
  5361. if (!item)
  5362. return 0;
  5363. lua_interface->SetItemValue(state, item);
  5364. break;
  5365. case 4:
  5366. quest = spawn->GetTempVariableQuest(var);
  5367. if (!quest)
  5368. return 0;
  5369. lua_interface->SetQuestValue(state, quest);
  5370. break;
  5371. case 5:
  5372. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5373. break;
  5374. default:
  5375. // Not a valid type then the variable was not set so return out
  5376. return 0;
  5377. }
  5378. // Return value was set so return out
  5379. return 1;
  5380. }
  5381. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5382. {
  5383. if (!lua_interface)
  5384. return 0;
  5385. Quest* quest = lua_interface->GetQuest(state);
  5386. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5387. string description = lua_interface->GetStringValue(state, 3);
  5388. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5389. if (!quest) {
  5390. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5391. lua_interface->SetBooleanValue(state, false);
  5392. return 1;
  5393. }
  5394. if (!spawn) {
  5395. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5396. lua_interface->SetBooleanValue(state, false);
  5397. return 1;
  5398. }
  5399. if (!spawn->IsPlayer()) {
  5400. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5401. lua_interface->SetBooleanValue(state, false);
  5402. return 1;
  5403. }
  5404. if (item_id == 0) {
  5405. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5406. lua_interface->SetBooleanValue(state, false);
  5407. return 1;
  5408. }
  5409. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5410. if (!client) {
  5411. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5412. lua_interface->SetBooleanValue(state, false);
  5413. return 1;
  5414. }
  5415. Item* item = master_item_list.GetItem(item_id);
  5416. if (!item) {
  5417. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5418. lua_interface->SetBooleanValue(state, false);
  5419. return 1;
  5420. }
  5421. Item* firstItem = new Item(item);
  5422. quest->AddTmpRewardItem(firstItem);
  5423. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5424. bool itemsAddedSuccessfully = true;
  5425. if(num_args > 4)
  5426. {
  5427. for(int8 n=5;n<num_args+1;n++)
  5428. {
  5429. int32 new_item = lua_interface->GetInt32Value(state, n);
  5430. Item* tmpItem = master_item_list.GetItem(new_item);
  5431. if(tmpItem)
  5432. {
  5433. Item* newTmpItem = new Item(tmpItem);
  5434. quest->AddTmpRewardItem(newTmpItem);
  5435. }
  5436. else
  5437. itemsAddedSuccessfully = false;
  5438. }
  5439. }
  5440. client->AddPendingQuestAcceptReward(quest);
  5441. client->DisplayQuestComplete(quest, true, description);
  5442. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5443. return 1;
  5444. }
  5445. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5446. if (!lua_interface)
  5447. return 0;
  5448. Quest* quest = lua_interface->GetQuest(state);
  5449. if (!quest) {
  5450. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5451. return 0;
  5452. }
  5453. quest->SetRepeatable(true);
  5454. return 0;
  5455. }
  5456. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5457. if (!lua_interface)
  5458. return 0;
  5459. Spawn* spawn = lua_interface->GetSpawn(state);
  5460. if (!spawn) {
  5461. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5465. string ret = classes.GetClassNameCase(base_class);
  5466. if (ret.length() > 0) {
  5467. lua_interface->SetStringValue(state, ret.c_str());
  5468. return 1;
  5469. }
  5470. return 0;
  5471. }
  5472. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5473. if (!lua_interface)
  5474. return 0;
  5475. Spawn* player = lua_interface->GetSpawn(state);
  5476. if (player && player->IsPlayer()) {
  5477. Client* client = player->GetClient();
  5478. if (client)
  5479. client->SendWaypoints();
  5480. }
  5481. return 0;
  5482. }
  5483. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* player = lua_interface->GetSpawn(state);
  5487. string name = lua_interface->GetStringValue(state, 2);
  5488. int32 type = lua_interface->GetInt32Value(state, 3);
  5489. if (type == 0)
  5490. type = 2;
  5491. if (name.length() > 0) {
  5492. if (player && player->IsPlayer()) {
  5493. Client* client = player->GetClient();
  5494. if (client)
  5495. client->AddWaypoint(name, type);
  5496. }
  5497. }
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. Spawn* player = lua_interface->GetSpawn(state);
  5504. string name = lua_interface->GetStringValue(state, 2);
  5505. if (name.length() > 0) {
  5506. if (player && player->IsPlayer()) {
  5507. Client* client = player->GetClient();
  5508. if (client)
  5509. client->RemoveWaypoint(name);
  5510. }
  5511. }
  5512. return 0;
  5513. }
  5514. int EQ2Emu_lua_AddWard(lua_State* state) {
  5515. if (!lua_interface)
  5516. return 0;
  5517. int32 damage = lua_interface->GetInt32Value(state);
  5518. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5519. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5520. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5521. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5522. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5523. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5524. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5525. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5526. bool ward_was_added = false;
  5527. ZoneServer* zone = spell->caster->GetZone();
  5528. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5529. for (int32 i = 0; i < spell->targets.size(); i++) {
  5530. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5531. if (!target)
  5532. continue;
  5533. if (target->IsEntity()) {
  5534. // If the ward is already active remove it
  5535. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5536. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5537. // Create new ward info
  5538. WardInfo* ward = new WardInfo;
  5539. ward->Spell = spell;
  5540. ward->BaseDamage = damage;
  5541. ward->DamageLeft = damage;
  5542. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5543. ward->keepWard = keepWard;
  5544. ward->WardType = wardType;
  5545. if (damageAbsorptionPercent > 100)
  5546. damageAbsorptionPercent = 100;
  5547. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5548. if (damageAbsorptionMaxHealthPercent > 100)
  5549. damageAbsorptionMaxHealthPercent = 100;
  5550. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5551. ward->RedirectDamagePercent = redirectDamagePercent;
  5552. ward->LastRedirectDamage = 0;
  5553. ward->LastAbsorbedDamage = 0;
  5554. ward->HitCount = 0;
  5555. spell->num_triggers = maxHitCount;
  5556. spell->had_triggers = true;
  5557. spell->cancel_after_all_triggers = false;
  5558. ward->MaxHitCount = maxHitCount;
  5559. if (wardType == WARD_TYPE_MAGICAL)
  5560. ward->DamageType = damageTypes;
  5561. // Add the ward to the entity
  5562. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5563. ward_was_added = true;
  5564. }
  5565. }
  5566. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5567. if (ward_was_added && spell->caster->IsPlayer()) {
  5568. spell->had_dmg_remaining = true;
  5569. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5570. }
  5571. return 0;
  5572. }
  5573. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5574. if (!lua_interface)
  5575. return 0;
  5576. int32 amount = lua_interface->GetInt32Value(state);
  5577. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5578. WardInfo* ward = 0;
  5579. ZoneServer* zone = spell->caster->GetZone();
  5580. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5581. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5582. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5583. ward = target->GetWard(spell->spell->GetSpellID());
  5584. if (target && ward) {
  5585. ward->DamageLeft += amount;
  5586. if (ward->DamageLeft > ward->BaseDamage)
  5587. ward->DamageLeft = ward->BaseDamage;
  5588. for (int32 i = 0; i < spell->targets.size(); i++) {
  5589. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5590. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5591. }
  5592. }
  5593. }
  5594. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5595. if (ward && spell->caster->IsPlayer())
  5596. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5597. return 0;
  5598. }
  5599. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5600. if (!lua_interface)
  5601. return 0;
  5602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5603. if (!spell) {
  5604. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5605. return 0;
  5606. }
  5607. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5608. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5609. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5610. if (ward) {
  5611. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5612. return 1;
  5613. }
  5614. }
  5615. return 0;
  5616. }
  5617. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5618. if (!lua_interface)
  5619. return 0;
  5620. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5621. if (!spell) {
  5622. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5623. return 0;
  5624. }
  5625. string type = lua_interface->GetStringValue(state, 2);
  5626. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5627. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5628. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5629. if (ward) {
  5630. if (boost::iequals(type, "damageleft"))
  5631. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5632. else if (boost::iequals(type, "basedamage"))
  5633. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5634. else if (boost::iequals(type, "keepward"))
  5635. lua_interface->SetBooleanValue(state, ward->keepWard);
  5636. else if (boost::iequals(type, "wardtype"))
  5637. lua_interface->SetInt32Value(state, ward->WardType);
  5638. else if (boost::iequals(type, "dmgabsorptionpct"))
  5639. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5640. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5641. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5642. else if (boost::iequals(type, "redirectdamagepercent"))
  5643. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5644. else if (boost::iequals(type, "lastredirectdamage"))
  5645. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5646. else if (boost::iequals(type, "lastabsorbeddamage"))
  5647. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5648. else if (boost::iequals(type, "hitcount"))
  5649. lua_interface->SetInt32Value(state, ward->HitCount);
  5650. else if (boost::iequals(type, "maxhitcount"))
  5651. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5652. else
  5653. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5654. return 1;
  5655. }
  5656. }
  5657. return 0;
  5658. }
  5659. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5660. if (!lua_interface)
  5661. return 0;
  5662. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5663. ZoneServer* zone = spell->caster->GetZone();
  5664. Spawn* target = 0;
  5665. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5666. for (int32 i = 0; i < spell->targets.size(); i++) {
  5667. target = zone->GetSpawnByID(spell->targets.at(i));
  5668. if (target && target->IsEntity()) {
  5669. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5670. }
  5671. }
  5672. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5673. return 0;
  5674. }
  5675. int EQ2Emu_lua_Interrupt(lua_State* state)
  5676. {
  5677. if (!lua_interface)
  5678. return 0;
  5679. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5680. Spawn* target = lua_interface->GetSpawn(state, 2);
  5681. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5682. if (!caster)
  5683. {
  5684. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. if (!target)
  5688. {
  5689. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5690. return 0;
  5691. }
  5692. if (!spell) {
  5693. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5694. return 0;
  5695. }
  5696. if (!target->IsEntity() && !spell)
  5697. {
  5698. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5699. return 0;
  5700. }
  5701. if (!target && spell) {
  5702. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5703. for (int8 i = 0; i < spell->targets.size(); i++) {
  5704. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5705. if (!target || !target->IsEntity())
  5706. continue;
  5707. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5708. }
  5709. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5710. }
  5711. else
  5712. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5713. return 0;
  5714. }
  5715. int EQ2Emu_lua_Stealth(lua_State* state) {
  5716. if (!lua_interface)
  5717. return 0;
  5718. int8 type = lua_interface->GetInt8Value(state);
  5719. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5720. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5721. if (!spell) {
  5722. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5723. return 0;
  5724. }
  5725. ZoneServer* zone = spell->caster->GetZone();
  5726. if (spawn) {
  5727. if (spawn->IsEntity()) {
  5728. if (type == 1) {
  5729. ((Entity*)spawn)->AddStealthSpell(spell);
  5730. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5731. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5732. }
  5733. else if (type == 2) {
  5734. ((Entity*)spawn)->AddInvisSpell(spell);
  5735. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5736. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5737. }
  5738. return 0;
  5739. }
  5740. else {
  5741. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5742. return 0;
  5743. }
  5744. }
  5745. else {
  5746. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5747. for (int32 i = 0; i < spell->targets.size(); i++) {
  5748. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5749. if (!spawn || !spawn->IsEntity())
  5750. continue;
  5751. if (type == 1) {
  5752. ((Entity*)spawn)->AddStealthSpell(spell);
  5753. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5754. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5755. }
  5756. else if (type == 2) {
  5757. ((Entity*)spawn)->AddInvisSpell(spell);
  5758. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5759. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5760. }
  5761. else {
  5762. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5763. break;
  5764. }
  5765. }
  5766. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5767. }
  5768. return 0;
  5769. }
  5770. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5771. if (!lua_interface)
  5772. return 0;
  5773. Spawn* spawn = lua_interface->GetSpawn(state);
  5774. if (!spawn) {
  5775. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5776. return 0;
  5777. }
  5778. if (spawn->IsEntity()) {
  5779. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5780. return 1;
  5781. }
  5782. else
  5783. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5784. return 0;
  5785. }
  5786. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5787. if (!lua_interface)
  5788. return 0;
  5789. Spawn* spawn = lua_interface->GetSpawn(state);
  5790. if (!spawn) {
  5791. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5792. return 0;
  5793. }
  5794. if (spawn->IsEntity()) {
  5795. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5796. return 1;
  5797. }
  5798. else
  5799. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5800. return 0;
  5801. }
  5802. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5803. if (!lua_interface)
  5804. return 0;
  5805. Spawn* player = lua_interface->GetSpawn(state);
  5806. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5807. lua_interface->ResetFunctionStack(state);
  5808. if (!player->IsPlayer()) {
  5809. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5810. return 0;
  5811. }
  5812. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5813. return 1;
  5814. }
  5815. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5816. if (!lua_interface)
  5817. return 0;
  5818. Spawn* player = lua_interface->GetSpawn(state);
  5819. int8 slot = lua_interface->GetInt8Value(state, 2);
  5820. lua_interface->ResetFunctionStack(state);
  5821. if (!player) {
  5822. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5823. return 0;
  5824. }
  5825. if (!player->IsPlayer()) {
  5826. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5827. return 0;
  5828. }
  5829. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5830. if (!item) {
  5831. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5832. return 0;
  5833. }
  5834. lua_interface->SetItemValue(state, item);
  5835. return 1;
  5836. }
  5837. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5838. if (!lua_interface)
  5839. return 0;
  5840. Spawn* player = lua_interface->GetSpawn(state);
  5841. int32 id = lua_interface->GetInt32Value(state, 2);
  5842. lua_interface->ResetFunctionStack(state);
  5843. if (!player) {
  5844. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5845. return 0;
  5846. }
  5847. if (!player->IsPlayer()) {
  5848. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5849. return 0;
  5850. }
  5851. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5852. if (!item) {
  5853. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. lua_interface->SetItemValue(state, item);
  5857. return 1;
  5858. }
  5859. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Spawn* spawn = lua_interface->GetSpawn(state);
  5863. int8 slot = lua_interface->GetInt8Value(state, 2);
  5864. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5865. lua_interface->ResetFunctionStack(state);
  5866. if (!spawn) {
  5867. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. if (!spawn->IsEntity()) {
  5871. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5872. return 0;
  5873. }
  5874. Item* item = master_item_list.GetItem(item_id);
  5875. if (!item) {
  5876. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5877. return 0;
  5878. }
  5879. Item* copy = new Item(item);
  5880. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5881. if(result)
  5882. {
  5883. ((Entity*)spawn)->SetEquipment(copy, slot);
  5884. spawn->vis_changed = true;
  5885. if(spawn->IsPlayer())
  5886. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5887. }
  5888. else
  5889. {
  5890. safe_delete(copy);
  5891. }
  5892. lua_interface->SetBooleanValue(state, result);
  5893. return 1;
  5894. }
  5895. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5896. if (!lua_interface)
  5897. return 0;
  5898. Spawn* spawn = lua_interface->GetSpawn(state);
  5899. int8 slot = lua_interface->GetInt8Value(state, 2);
  5900. Item* item = lua_interface->GetItem(state, 3);
  5901. lua_interface->ResetFunctionStack(state);
  5902. if (!spawn) {
  5903. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!spawn->IsEntity()) {
  5907. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. if (!item) {
  5911. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5912. return 0;
  5913. }
  5914. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5915. if(result)
  5916. {
  5917. ((Entity*)spawn)->SetEquipment(item, slot);
  5918. spawn->vis_changed = true;
  5919. if(spawn->IsPlayer())
  5920. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5921. }
  5922. lua_interface->SetBooleanValue(state, result);
  5923. return 1;
  5924. }
  5925. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5926. if (!lua_interface)
  5927. return 0;
  5928. Spawn* spawn = lua_interface->GetSpawn(state);
  5929. int8 slot = lua_interface->GetInt8Value(state, 2);
  5930. 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
  5931. lua_interface->ResetFunctionStack(state);
  5932. if (!spawn) {
  5933. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. if (!spawn->IsEntity()) {
  5937. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5938. return 0;
  5939. }
  5940. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5941. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5942. spawn->vis_changed = true;
  5943. if(spawn->IsPlayer())
  5944. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5945. lua_interface->SetBooleanValue(state, true);
  5946. return 1;
  5947. }
  5948. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5949. if (!lua_interface)
  5950. return 0;
  5951. Spawn* spawn = lua_interface->GetSpawn(state);
  5952. int8 slot = lua_interface->GetInt8Value(state, 2);
  5953. int16 type = lua_interface->GetInt16Value(state, 3);
  5954. int8 r = lua_interface->GetInt8Value(state, 4);
  5955. int8 g = lua_interface->GetInt8Value(state, 5);
  5956. int8 b = lua_interface->GetInt8Value(state, 6);
  5957. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5958. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5959. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5960. lua_interface->ResetFunctionStack(state);
  5961. if (!spawn) {
  5962. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5963. return 0;
  5964. }
  5965. if (!spawn->IsEntity()) {
  5966. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5970. spawn->vis_changed = true;
  5971. lua_interface->SetBooleanValue(state, true);
  5972. return 1;
  5973. }
  5974. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5975. if (!lua_interface)
  5976. return 0;
  5977. Spawn* player = lua_interface->GetSpawn(state);
  5978. int32 id = lua_interface->GetInt32Value(state, 2);
  5979. int8 count = lua_interface->GetInt8Value(state, 3);
  5980. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5981. lua_interface->ResetFunctionStack(state);
  5982. if (!player) {
  5983. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5984. return 0;
  5985. }
  5986. if (!player->IsPlayer()) {
  5987. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5988. return 0;
  5989. }
  5990. if (!count)
  5991. count = 1;
  5992. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5993. if (!item) {
  5994. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. lua_interface->SetItemValue(state, item);
  5998. return 1;
  5999. }
  6000. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6001. if (!lua_interface)
  6002. return 0;
  6003. Spawn* spawn = lua_interface->GetSpawn(state);
  6004. int32 anim = lua_interface->GetInt32Value(state, 2);
  6005. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6006. int8 type = lua_interface->GetInt8Value(state, 4);
  6007. if (!spawn) {
  6008. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. if (spawn2) {
  6012. if (spawn2->IsPlayer()) {
  6013. if (type != 1 && type != 2)
  6014. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6015. else
  6016. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6017. return 0;
  6018. }
  6019. else {
  6020. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6021. return 0;
  6022. }
  6023. }
  6024. else
  6025. spawn->GetZone()->PlayAnimation(spawn, anim);
  6026. return 0;
  6027. }
  6028. int EQ2Emu_lua_IsPet(lua_State* state) {
  6029. if (!lua_interface)
  6030. return 0;
  6031. Spawn* spawn = lua_interface->GetSpawn(state);
  6032. if (!spawn) {
  6033. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6037. return 1;
  6038. }
  6039. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6040. if (!lua_interface)
  6041. return 0;
  6042. Spawn* spawn = lua_interface->GetSpawn(state);
  6043. if (!spawn) {
  6044. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. if (!spawn->IsNPC()) {
  6048. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6049. return 0;
  6050. }
  6051. if (((NPC*)spawn)->GetOwner()) {
  6052. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6053. return 1;
  6054. }
  6055. return 0;
  6056. }
  6057. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. Spawn* spawn = lua_interface->GetSpawn(state);
  6061. Spawn* target = lua_interface->GetSpawn(state, 2);
  6062. if (!spawn) {
  6063. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. if (!spawn) {
  6067. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6068. return 0;
  6069. }
  6070. spawn->SetTarget(target);
  6071. return 0;
  6072. }
  6073. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6074. if (!lua_interface)
  6075. return 0;
  6076. Spawn* spawn = lua_interface->GetSpawn(state);
  6077. bool val = lua_interface->GetBooleanValue(state, 2);
  6078. if (!spawn) {
  6079. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. if (!spawn->IsEntity()) {
  6083. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. ((Entity*)spawn)->InCombat(val);
  6087. if (val) {
  6088. spawn->ClearRunningLocations();
  6089. spawn->CalculateRunningLocation(true);
  6090. }
  6091. return 0;
  6092. }
  6093. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6094. if (!lua_interface)
  6095. return 0;
  6096. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6097. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6098. if (!spawn1) {
  6099. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!spawn2) {
  6103. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6107. return 1;
  6108. }
  6109. int EQ2Emu_lua_Runback(lua_State* state) {
  6110. if (!lua_interface)
  6111. return 0;
  6112. Spawn* spawn = lua_interface->GetSpawn(state);
  6113. if (!spawn) {
  6114. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6115. return 0;
  6116. }
  6117. if (!spawn->IsNPC()) {
  6118. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6119. return 0;
  6120. }
  6121. ((NPC*)spawn)->Runback();
  6122. return 0;
  6123. }
  6124. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6125. if (!lua_interface)
  6126. return 0;
  6127. Spawn* spawn = lua_interface->GetSpawn(state);
  6128. if (!spawn) {
  6129. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. if (!spawn->IsNPC()) {
  6133. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6137. return 1;
  6138. }
  6139. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6140. if (!lua_interface)
  6141. return 0;
  6142. Spawn* spawn = lua_interface->GetSpawn(state);
  6143. if (!spawn) {
  6144. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. if (!spawn->IsEntity()) {
  6148. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6149. return 0;
  6150. }
  6151. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6152. return 1;
  6153. }
  6154. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6155. if (!lua_interface)
  6156. return 0;
  6157. Spawn* spawn = lua_interface->GetSpawn(state);
  6158. if (!spawn) {
  6159. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if (!spawn->IsEntity()) {
  6163. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6167. return 1;
  6168. }
  6169. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6170. if (!lua_interface)
  6171. return 0;
  6172. Spawn* spawn = lua_interface->GetSpawn(state);
  6173. if (!spawn) {
  6174. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6175. return 0;
  6176. }
  6177. if (!spawn->IsEntity()) {
  6178. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6182. return 1;
  6183. }
  6184. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6185. if (!lua_interface)
  6186. return 0;
  6187. Spawn* spawn = lua_interface->GetSpawn(state);
  6188. if (!spawn) {
  6189. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. if (!spawn->IsEntity()) {
  6193. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6197. return 1;
  6198. }
  6199. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6200. if (!lua_interface)
  6201. return 0;
  6202. Spawn* spawn = lua_interface->GetSpawn(state);
  6203. Spawn* target = lua_interface->GetSpawn(state, 2);
  6204. float distance = lua_interface->GetFloatValue(state, 3);
  6205. if (!spawn) {
  6206. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6207. return 0;
  6208. }
  6209. if (!target) {
  6210. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6211. return 0;
  6212. }
  6213. if (!spawn->IsNPC()) {
  6214. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6215. return 0;
  6216. }
  6217. if (!target->IsEntity()) {
  6218. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6219. return 0;
  6220. }
  6221. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6222. return 1;
  6223. }
  6224. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6225. if (!lua_interface)
  6226. return 0;
  6227. Spawn* spawn = lua_interface->GetSpawn(state);
  6228. Spawn* target = lua_interface->GetSpawn(state, 2);
  6229. float distance = lua_interface->GetFloatValue(state, 3);
  6230. if (!spawn) {
  6231. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6232. return 0;
  6233. }
  6234. if (!target) {
  6235. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (!spawn->IsNPC()) {
  6239. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. if (!target->IsEntity()) {
  6243. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6247. return 0;
  6248. }
  6249. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6250. if (!lua_interface)
  6251. return 0;
  6252. Spawn* spawn = lua_interface->GetSpawn(state);
  6253. if (!spawn) {
  6254. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6255. return 0;
  6256. }
  6257. if (!spawn->IsNPC()) {
  6258. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6259. return 0;
  6260. }
  6261. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6262. return 1;
  6263. }
  6264. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6265. if (!lua_interface)
  6266. return 0;
  6267. Spawn* spawn = lua_interface->GetSpawn(state);
  6268. if (!spawn) {
  6269. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!spawn->IsNPC()) {
  6273. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6277. return 1;
  6278. }
  6279. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6280. if (!lua_interface)
  6281. return 0;
  6282. Spawn* spawn = lua_interface->GetSpawn(state);
  6283. if (!spawn) {
  6284. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6285. return 0;
  6286. }
  6287. if (!spawn->IsNPC()) {
  6288. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6289. return 0;
  6290. }
  6291. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6292. if (hated) {
  6293. lua_interface->SetSpawnValue(state, hated);
  6294. return 1;
  6295. }
  6296. return 0;
  6297. }
  6298. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6299. if (!lua_interface)
  6300. return 0;
  6301. Spawn* spawn = lua_interface->GetSpawn(state);
  6302. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6303. if (!spawn) {
  6304. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6305. return 0;
  6306. }
  6307. if (!spawn->IsNPC()) {
  6308. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6309. return 0;
  6310. }
  6311. if (!hated) {
  6312. ((NPC*)spawn)->Brain()->ClearHate();
  6313. return 0;
  6314. }
  6315. else
  6316. {
  6317. if (!hated->IsEntity()) {
  6318. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6319. return 0;
  6320. }
  6321. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6322. return 0;
  6323. }
  6324. return 0;
  6325. }
  6326. int EQ2Emu_lua_ClearEncounter(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 ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6332. return 0;
  6333. }
  6334. if (!spawn->IsNPC()) {
  6335. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. ((NPC*)spawn)->Brain()->ClearEncounter();
  6339. return 0;
  6340. }
  6341. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6342. if (!lua_interface)
  6343. return 0;
  6344. Spawn* spawn = lua_interface->GetSpawn(state);
  6345. if (!spawn) {
  6346. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. if (!spawn->IsNPC()) {
  6350. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. // Temp list to store hate list
  6354. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6355. if (encounterList->size() == 0) {
  6356. safe_delete(encounterList);
  6357. return 0;
  6358. }
  6359. lua_createtable(state, encounterList->size(), 0);
  6360. int newTable = lua_gettop(state);
  6361. for (int32 i = 0; i < encounterList->size(); i++) {
  6362. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6363. if (temp)
  6364. lua_interface->SetSpawnValue(state, temp);
  6365. lua_rawseti(state, newTable, i + 1);
  6366. }
  6367. safe_delete(encounterList);
  6368. return 1;
  6369. }
  6370. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6371. if (!lua_interface)
  6372. return 0;
  6373. Spawn* spawn = lua_interface->GetSpawn(state);
  6374. if (!spawn) {
  6375. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. if (!spawn->IsNPC()) {
  6379. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6380. return 0;
  6381. }
  6382. // Temp list to store hate list
  6383. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6384. if (hateList->size() == 0) {
  6385. safe_delete(hateList);
  6386. return 0;
  6387. }
  6388. lua_createtable(state, hateList->size(), 0);
  6389. int newTable = lua_gettop(state);
  6390. for (int32 i = 0; i < hateList->size(); i++) {
  6391. lua_interface->SetSpawnValue(state, hateList->at(i));
  6392. lua_rawseti(state, newTable, i + 1);
  6393. }
  6394. safe_delete(hateList);
  6395. return 1;
  6396. }
  6397. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6398. if (!lua_interface)
  6399. return 0;
  6400. Spawn* spawn = lua_interface->GetSpawn(state);
  6401. if (!spawn) {
  6402. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6403. return 0;
  6404. }
  6405. if (spawn->IsPlayer()) {
  6406. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6407. lua_interface->SetBooleanValue(state, true);
  6408. else
  6409. lua_interface->SetBooleanValue(state, false);
  6410. return 1;
  6411. }
  6412. else {
  6413. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6414. return 1;
  6415. }
  6416. }
  6417. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6418. if (!lua_interface)
  6419. return 0;
  6420. Quest* quest = lua_interface->GetQuest(state);
  6421. if (!quest) {
  6422. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6423. return 0;
  6424. }
  6425. quest->SetCompletedFlag(true);
  6426. return 0;
  6427. }
  6428. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6429. if (!lua_interface)
  6430. return 0;
  6431. Spawn* spawn = lua_interface->GetSpawn(state);
  6432. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6433. int8 tier = lua_interface->GetInt8Value(state, 3);
  6434. if (!spawn) {
  6435. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6436. return 0;
  6437. }
  6438. if (!spawn->IsEntity()) {
  6439. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6440. return 0;
  6441. }
  6442. if (spellID == 0) {
  6443. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6447. if (effect) {
  6448. if (tier > 0) {
  6449. // If a tier was passed chec to see if it is the same as the effect
  6450. if (tier == effect->tier)
  6451. lua_interface->SetBooleanValue(state, true);
  6452. else
  6453. lua_interface->SetBooleanValue(state, false);
  6454. return 1;
  6455. }
  6456. else {
  6457. // Have an effect but no tier was passed so return true
  6458. lua_interface->SetBooleanValue(state, true);
  6459. }
  6460. return 1;
  6461. }
  6462. // no effect so return false
  6463. lua_interface->SetBooleanValue(state, false);
  6464. return 1;
  6465. }
  6466. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6467. if (!lua_interface)
  6468. return 0;
  6469. Spawn* spawn = lua_interface->GetSpawn(state);
  6470. int32 id = lua_interface->GetInt32Value(state, 2);
  6471. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6472. Spawn* spawn2 = 0;
  6473. vector<Spawn*> list;
  6474. if (!spawn) {
  6475. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6476. return 0;
  6477. }
  6478. //If zone not provided, use spawn's zone
  6479. if (!zone)
  6480. zone = spawn->GetZone();
  6481. list = zone->GetSpawnsByID(id);
  6482. if (list.size() == 0) {
  6483. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6484. return 0;
  6485. }
  6486. vector<Spawn*>::iterator itr = list.begin();
  6487. for (int8 i = 0; i < list.size(); i++) {
  6488. spawn2 = itr[i];
  6489. if (spawn2)
  6490. spawn2->AddAllowAccessSpawn(spawn);
  6491. }
  6492. return 0;
  6493. }
  6494. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6495. if (!lua_interface)
  6496. return 0;
  6497. Spawn* spawn = lua_interface->GetSpawn(state);
  6498. int32 id = lua_interface->GetInt32Value(state, 2);
  6499. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6500. Spawn* spawn2 = 0;
  6501. if (!spawn) {
  6502. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. //If zone not provided, use spawn's zone
  6506. if (!zone)
  6507. zone = spawn->GetZone();
  6508. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6509. vector<Spawn*>::iterator itr = list.begin();
  6510. if (list.size() == 0) {
  6511. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. for (int8 i = 0; i < list.size(); i++) {
  6515. spawn2 = itr[i];
  6516. if (spawn2)
  6517. spawn2->RemoveSpawnAccess(spawn);
  6518. }
  6519. return 0;
  6520. }
  6521. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6522. if (!lua_interface)
  6523. return 0;
  6524. Quest* quest = lua_interface->GetQuest(state);
  6525. if (!quest) {
  6526. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6527. return 0;
  6528. }
  6529. quest->SetYellowName(true);
  6530. return 0;
  6531. }
  6532. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6533. if (!lua_interface)
  6534. return 0;
  6535. Spawn* spawn = lua_interface->GetSpawn(state);
  6536. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6537. if (!spawn) {
  6538. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6539. return 0;
  6540. }
  6541. if (!spawn->IsPlayer()) {
  6542. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6546. return 1;
  6547. }
  6548. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6549. if (!lua_interface)
  6550. return 0;
  6551. Spawn* spawn = lua_interface->GetSpawn(state);
  6552. if (!spawn) {
  6553. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. if (!spawn->IsPlayer()) {
  6557. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6558. return 0;
  6559. }
  6560. ZoneServer* zone = spawn->GetZone();
  6561. if (!zone) {
  6562. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6563. return 0;
  6564. }
  6565. Instance_Type iType = zone->GetInstanceType();
  6566. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6567. iType == GROUP_LOCKOUT_INSTANCE ||
  6568. iType == RAID_LOCKOUT_INSTANCE ||
  6569. iType == SOLO_PERSIST_INSTANCE ||
  6570. iType == GROUP_PERSIST_INSTANCE ||
  6571. iType == RAID_PERSIST_INSTANCE) {
  6572. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6573. if (data) {
  6574. // Check to see if the timer has already been set, if it has return out.
  6575. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6576. return 0;
  6577. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6578. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6579. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6580. if (client) {
  6581. string time_msg = "";
  6582. int32 time = data->success_lockout_time;
  6583. int16 hour;
  6584. int8 min;
  6585. int8 sec;
  6586. hour = time / 3600;
  6587. time = time % 3600;
  6588. min = time / 60;
  6589. time = time % 60;
  6590. sec = time;
  6591. if (hour > 0) {
  6592. char temp[10];
  6593. sprintf(temp, " %i", hour);
  6594. time_msg.append(temp);
  6595. time_msg.append(" hour");
  6596. time_msg.append((hour > 1) ? "s" : "");
  6597. }
  6598. if (min > 0) {
  6599. char temp[5];
  6600. sprintf(temp, " %i", min);
  6601. time_msg.append(temp);
  6602. time_msg.append(" minute");
  6603. time_msg.append((min > 1) ? "s" : "");
  6604. }
  6605. // Only add seconds if minutes and hours are 0
  6606. if (hour == 0 && min == 0 && sec > 0) {
  6607. char temp[5];
  6608. sprintf(temp, " %i", sec);
  6609. time_msg.append(temp);
  6610. time_msg.append(" second");
  6611. time_msg.append((sec > 1) ? "s" : "");
  6612. }
  6613. 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());
  6614. }
  6615. }
  6616. else
  6617. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6618. }
  6619. else
  6620. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6621. return 0;
  6622. }
  6623. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6624. if (!lua_interface)
  6625. return 0;
  6626. Spawn* spawn = lua_interface->GetSpawn(state);
  6627. if (!spawn) {
  6628. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. if (!spawn->IsPlayer()) {
  6632. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. ZoneServer* zone = spawn->GetZone();
  6636. if (!zone) {
  6637. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. Instance_Type iType = zone->GetInstanceType();
  6641. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6642. iType == GROUP_LOCKOUT_INSTANCE ||
  6643. iType == RAID_LOCKOUT_INSTANCE ||
  6644. iType == SOLO_PERSIST_INSTANCE ||
  6645. iType == GROUP_PERSIST_INSTANCE ||
  6646. iType == RAID_PERSIST_INSTANCE) {
  6647. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6648. if (data) {
  6649. // Check to see if the timer has already been set, if it has return out.
  6650. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6651. return 0;
  6652. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6653. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6654. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6655. if (client) {
  6656. string time_msg = "";
  6657. int32 time = data->failure_lockout_time;
  6658. int16 hour;
  6659. int8 min;
  6660. int8 sec;
  6661. hour = time / 3600;
  6662. time = time % 3600;
  6663. min = time / 60;
  6664. time = time % 60;
  6665. sec = time;
  6666. if (hour > 0) {
  6667. char temp[10];
  6668. sprintf(temp, " %i", hour);
  6669. time_msg.append(temp);
  6670. time_msg.append(" hour");
  6671. time_msg.append((hour > 1) ? "s" : "");
  6672. }
  6673. if (min > 0) {
  6674. char temp[5];
  6675. sprintf(temp, " %i", min);
  6676. time_msg.append(temp);
  6677. time_msg.append(" minute");
  6678. time_msg.append((min > 1) ? "s" : "");
  6679. }
  6680. // Only add seconds if minutes and hours are 0
  6681. if (hour == 0 && min == 0 && sec > 0) {
  6682. char temp[5];
  6683. sprintf(temp, " %i", sec);
  6684. time_msg.append(temp);
  6685. time_msg.append(" second");
  6686. time_msg.append((sec > 1) ? "s" : "");
  6687. }
  6688. 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());
  6689. }
  6690. }
  6691. else
  6692. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6693. }
  6694. else
  6695. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6696. return 0;
  6697. }
  6698. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6699. if (!lua_interface)
  6700. return 0;
  6701. Spawn* spawn = lua_interface->GetSpawn(state);
  6702. if (!spawn) {
  6703. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6704. return 0;
  6705. }
  6706. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6707. return 1;
  6708. }
  6709. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6710. if (!lua_interface)
  6711. return 0;
  6712. Spawn* player = lua_interface->GetSpawn(state);
  6713. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6714. if (!player) {
  6715. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6716. return 0;
  6717. }
  6718. if (!player->IsPlayer()) {
  6719. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6720. return 0;
  6721. }
  6722. if (!ground) {
  6723. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6724. return 0;
  6725. }
  6726. if (!ground->IsGroundSpawn()) {
  6727. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6728. return 0;
  6729. }
  6730. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6731. if (!groundspawn_entries) {
  6732. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6733. return 0;
  6734. }
  6735. Skill* skill = 0;
  6736. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6737. if (collection_skill == "Collecting")
  6738. skill = ((Player*)player)->GetSkillByName("Gathering");
  6739. else
  6740. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6741. if (!skill) {
  6742. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6743. return 0;
  6744. }
  6745. vector<GroundSpawnEntry*>::iterator itr;
  6746. GroundSpawnEntry* entry = 0;
  6747. bool can_harvest = false;
  6748. sint32 min_skill = -1;
  6749. int16 totalSkill = skill->current_val;
  6750. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6751. if(skillID != 0xFFFFFFFF)
  6752. {
  6753. ((Entity*)player)->MStats.lock();
  6754. totalSkill += ((Entity*)player)->stats[skillID];
  6755. ((Entity*)player)->MStats.unlock();
  6756. }
  6757. // first, iterate through groundspawn_entries, discard tables player cannot use
  6758. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6759. {
  6760. entry = *itr;
  6761. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6762. min_skill = entry->min_skill_level;
  6763. // if player lacks skill, skip table
  6764. if (entry->min_skill_level > totalSkill)
  6765. continue;
  6766. // if bonus, but player lacks level, skip table
  6767. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6768. continue;
  6769. can_harvest = true;
  6770. break;
  6771. }
  6772. lua_interface->SetBooleanValue(state, can_harvest);
  6773. // If false, send the message to the client
  6774. if (!can_harvest) {
  6775. Client* client = player->GetZone()->GetClientBySpawn(player);
  6776. if (client) {
  6777. string msg = "You do not have enough skill to ";
  6778. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6779. msg.append("gather");
  6780. else if (collection_skill == "Mining")
  6781. msg.append("mine");
  6782. else if (collection_skill == "Trapping")
  6783. msg.append("trap");
  6784. else if (collection_skill == "Foresting")
  6785. msg.append("forest");
  6786. else if (collection_skill == "Fishing")
  6787. msg.append("catch");
  6788. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6789. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6790. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6791. }
  6792. }
  6793. return 1;
  6794. }
  6795. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6796. if (!lua_interface)
  6797. return 0;
  6798. Spawn* player = lua_interface->GetSpawn(state);
  6799. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6800. if (!player) {
  6801. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6802. return 0;
  6803. }
  6804. if (!player->IsPlayer()) {
  6805. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6806. return 0;
  6807. }
  6808. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6809. lua_interface->SetBooleanValue(state, ret);
  6810. return 1;
  6811. }
  6812. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6813. // Check to see if we have a valid lua_interface
  6814. if (!lua_interface)
  6815. return 0;
  6816. // Get the spawn that is getting the pet
  6817. Spawn* spawn = lua_interface->GetSpawn(state);
  6818. Spawn* target = lua_interface->GetSpawn(state, 2);
  6819. // Get the DB ID of the pet
  6820. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6821. float x = lua_interface->GetFloatValue(state, 4);
  6822. float y = lua_interface->GetFloatValue(state, 5);
  6823. float z = lua_interface->GetFloatValue(state, 6);
  6824. // Get the spell that this command was called from
  6825. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6826. // Check to make sure the spawn pointer is valid
  6827. if (!spawn) {
  6828. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. // Check to make sure the spawn is an entity
  6832. if (!spawn->IsEntity()) {
  6833. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. if (!target) {
  6837. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. if (!target->IsEntity()) {
  6841. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6842. return 0;
  6843. }
  6844. // Check to see if the DB ID for the pet is set
  6845. if (pet_id == 0) {
  6846. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6847. return 0;
  6848. }
  6849. // Check to see if the pointer to the spell is valid
  6850. if (!luaspell) {
  6851. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6852. return 0;
  6853. }
  6854. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6855. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6856. if (!pet) {
  6857. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6858. return 0;
  6859. }
  6860. // Check to make sure the pet is an npc
  6861. if (!pet->IsNPC()) {
  6862. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6863. return 0;
  6864. }
  6865. if (x == 0)
  6866. x = spawn->GetX();
  6867. if (y == 0)
  6868. y = spawn->GetY();
  6869. if (z == 0)
  6870. z = spawn->GetZ();
  6871. // Spawn the pet at the same location as the owner
  6872. pet->SetX(x);
  6873. pet->SetY(y);
  6874. pet->SetZ(z);
  6875. pet->SetLocation(spawn->GetLocation());
  6876. pet->SetHeading(spawn->GetHeading());
  6877. spawn->GetZone()->AddSpawn(pet);
  6878. /*
  6879. const char* spawn_script = world.GetSpawnScript(pet_id);
  6880. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6881. spawn->SetSpawnScript(string(spawn_script));
  6882. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6883. }*/
  6884. // Get a random pet name
  6885. string random_pet_name;
  6886. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6887. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6888. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6889. // Set the pets name
  6890. pet->SetName(random_pet_name.c_str());
  6891. // Set the level of the pet to the owners level
  6892. pet->SetLevel(spawn->GetLevel());
  6893. // Set the faction of the pet to the same faction as the owner
  6894. pet->SetFactionID(spawn->GetFactionID());
  6895. // Set the spawn as a pet
  6896. pet->SetPet(true);
  6897. // Give a pointer of the owner to the pet
  6898. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6899. // Set the pet type
  6900. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6901. // Set the spell id used to create this pet
  6902. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6903. // Set the spell tier used to create this pet
  6904. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6905. // Set the pets spawn type to 6
  6906. pet->SetSpawnType(6);
  6907. // Set the pets brain
  6908. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6909. // Check to see if the pet has a subtitle
  6910. if (strlen(pet->GetSubTitle()) > 0) {
  6911. // Add the players name to the front of the sub title
  6912. string pet_subtitle;
  6913. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6914. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6915. // Set the pets subtitle to the new one
  6916. pet->SetSubTitle(pet_subtitle.c_str());
  6917. }
  6918. // Set the pet as the return value for this function
  6919. lua_interface->SetSpawnValue(state, pet);
  6920. return 1;
  6921. }
  6922. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6923. if (!lua_interface)
  6924. return 0;
  6925. Spawn* spawn = lua_interface->GetSpawn(state);
  6926. Spawn* player = lua_interface->GetSpawn(state, 2);
  6927. float max_distance = lua_interface->GetFloatValue(state, 3);
  6928. string type = lua_interface->GetStringValue(state, 4);
  6929. if (!spawn || (spawn && spawn->IsPlayer())) {
  6930. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6931. return 0;
  6932. }
  6933. if (!player || (player && !player->IsPlayer())) {
  6934. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6935. return 0;
  6936. }
  6937. Client* client = 0;
  6938. if (player->GetZone())
  6939. client = player->GetZone()->GetClientBySpawn(player);
  6940. if (!client) {
  6941. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6942. return 0;
  6943. }
  6944. //Set max_distance to default if not set or not proper value
  6945. if (max_distance <= 0)
  6946. max_distance = 500;
  6947. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6948. if (packet) {
  6949. float unknown2_3 = 0;
  6950. int8 placement_mode = 0;
  6951. if (type == "wall") {
  6952. placement_mode = 2;
  6953. unknown2_3 = 150;
  6954. }
  6955. else if (type == "ceiling")
  6956. placement_mode = 1;
  6957. packet->setDataByName("placement_mode", placement_mode);
  6958. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6959. packet->setDataByName("model_type", spawn->GetModelType());
  6960. packet->setDataByName("unknown", 1); //size
  6961. packet->setDataByName("unknown2", 1); //size 2
  6962. packet->setDataByName("unknown2", .5, 1); //size 3
  6963. packet->setDataByName("unknown2", 3, 2);
  6964. packet->setDataByName("unknown2", unknown2_3, 3);
  6965. packet->setDataByName("max_distance", max_distance);
  6966. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6967. client->QueuePacket(packet->serialize());
  6968. safe_delete(packet);
  6969. }
  6970. return 0;
  6971. }
  6972. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6973. if (!lua_interface)
  6974. return 0;
  6975. Item* item = lua_interface->GetItem(state);
  6976. if (!item) {
  6977. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6978. return 0;
  6979. }
  6980. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6981. return 1;
  6982. }
  6983. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6984. if (!lua_interface)
  6985. return 0;
  6986. Spawn* spawn = lua_interface->GetSpawn(state);
  6987. if (!spawn) {
  6988. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6989. return 0;
  6990. }
  6991. if (spawn->GetZone())
  6992. spawn->GetZone()->AddTransportSpawn(spawn);
  6993. return 0;
  6994. }
  6995. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6996. if (!lua_interface)
  6997. return 0;
  6998. Spawn* spawn = lua_interface->GetSpawn(state);
  6999. if (!spawn) {
  7000. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7001. return 0;
  7002. }
  7003. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7004. return 1;
  7005. }
  7006. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7007. if (!lua_interface)
  7008. return 0;
  7009. Skill* skill = lua_interface->GetSkill(state);
  7010. if (!skill) {
  7011. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. lua_interface->SetInt32Value(state, skill->current_val);
  7015. return 1;
  7016. }
  7017. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7018. if (!lua_interface)
  7019. return 0;
  7020. Skill* skill = lua_interface->GetSkill(state);
  7021. if (!skill) {
  7022. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7023. return 0;
  7024. }
  7025. lua_interface->SetInt32Value(state, skill->max_val);
  7026. return 1;
  7027. }
  7028. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7029. if (!lua_interface)
  7030. return 0;
  7031. Skill* skill = lua_interface->GetSkill(state);
  7032. if (!skill) {
  7033. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7037. return 1;
  7038. }
  7039. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. Skill* skill = lua_interface->GetSkill(state);
  7043. int16 value = lua_interface->GetInt16Value(state, 2);
  7044. if (!skill) {
  7045. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7046. return 0;
  7047. }
  7048. skill->max_val = value;
  7049. if (skill->max_val < skill->current_val)
  7050. skill->current_val = skill->max_val;
  7051. return 0;
  7052. }
  7053. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7054. if (!lua_interface)
  7055. return 0;
  7056. Skill* skill = lua_interface->GetSkill(state);
  7057. int16 value = lua_interface->GetInt16Value(state, 2);
  7058. if (!skill) {
  7059. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7060. return 0;
  7061. }
  7062. if (value > skill->max_val)
  7063. skill->current_val = skill->max_val;
  7064. else
  7065. skill->current_val = value;
  7066. return 0;
  7067. }
  7068. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7069. if (!lua_interface)
  7070. return 0;
  7071. Spawn* player = lua_interface->GetSpawn(state);
  7072. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7073. if (skill_id > 0 && player && player->IsPlayer()) {
  7074. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7075. return 1;
  7076. }
  7077. return 0;
  7078. }
  7079. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7080. if (!lua_interface)
  7081. return 0;
  7082. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7083. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7084. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7085. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7086. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7087. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7088. if (player_spawn && player_spawn->IsPlayer()) {
  7089. Player* player = (Player*)player_spawn;
  7090. bool added = false;
  7091. if (!player->skill_list.HasSkill(skill_id)) {
  7092. player->AddSkill(skill_id, current_val, max_val, true);
  7093. added = true;
  7094. }
  7095. 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
  7096. Client* client = player->GetClient();
  7097. if (client) {
  7098. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7099. if (packet)
  7100. client->QueuePacket(packet);
  7101. }
  7102. }
  7103. if (added) {
  7104. lua_interface->SetBooleanValue(state, true);
  7105. return 1;
  7106. }
  7107. }
  7108. else {
  7109. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7110. }
  7111. }
  7112. else {
  7113. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7114. }
  7115. lua_interface->SetBooleanValue(state, false);
  7116. return 1;
  7117. }
  7118. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7119. if (!lua_interface)
  7120. return 0;
  7121. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7122. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7123. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7124. if (skill_id > 0) {
  7125. if (player_spawn && player_spawn->IsPlayer()) {
  7126. Player* player = (Player*)player_spawn;
  7127. if (player->skill_list.HasSkill(skill_id)) {
  7128. player->RemovePlayerSkill(skill_id);
  7129. if (!more_to_remove) {
  7130. Client* client = player->GetClient();
  7131. if (client) {
  7132. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7133. if (packet)
  7134. client->QueuePacket(packet);
  7135. }
  7136. }
  7137. }
  7138. }
  7139. else {
  7140. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7141. }
  7142. }
  7143. else {
  7144. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7145. }
  7146. return 0;
  7147. }
  7148. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7149. if (!lua_interface)
  7150. return 0;
  7151. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7152. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7153. int16 amount = lua_interface->GetInt8Value(state, 3);
  7154. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7155. if (amount > 0 && skill_type < 100) {
  7156. if (player_spawn && player_spawn->IsPlayer()) {
  7157. Player* player = (Player*)player_spawn;
  7158. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7159. if (!more_to_increase) {
  7160. Client* client = player->GetClient();
  7161. if (client) {
  7162. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7163. if (packet)
  7164. client->QueuePacket(packet);
  7165. }
  7166. }
  7167. }
  7168. else {
  7169. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7170. }
  7171. }
  7172. else {
  7173. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7174. }
  7175. return 0;
  7176. }
  7177. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7178. if (!lua_interface)
  7179. return 0;
  7180. Spawn* spawn = lua_interface->GetSpawn(state);
  7181. string name = lua_interface->GetStringValue(state, 2);
  7182. if (!spawn) {
  7183. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7184. return 0;
  7185. }
  7186. if (!spawn->IsEntity()) {
  7187. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7188. return 0;
  7189. }
  7190. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7191. if (skill) {
  7192. lua_interface->SetSkillValue(state, skill);
  7193. return 1;
  7194. }
  7195. return 0;
  7196. }
  7197. int EQ2Emu_lua_AddProc(lua_State* state) {
  7198. if (!lua_interface)
  7199. return 0;
  7200. Spawn* spawn = lua_interface->GetSpawn(state);
  7201. int8 type = lua_interface->GetInt8Value(state, 2);
  7202. float chance = lua_interface->GetFloatValue(state, 3);
  7203. Item* item = lua_interface->GetItem(state, 4);
  7204. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7205. LuaSpell* spell = 0;
  7206. if (!spawn && (!spell || !use_all_spelltargets)) {
  7207. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7208. return 0;
  7209. }
  7210. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7211. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7212. return 0;
  7213. }
  7214. if (!item)
  7215. spell = lua_interface->GetCurrentSpell(state);
  7216. if (!item && !spell) {
  7217. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7218. return 0;
  7219. }
  7220. if (spell && use_all_spelltargets) {
  7221. Spawn* target;
  7222. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7223. for (int8 i = 0; i < spell->targets.size(); i++) {
  7224. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7225. if (!target || !target->IsEntity())
  7226. continue;
  7227. ((Entity*)target)->AddProc(type, chance, item, spell);
  7228. }
  7229. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7230. }
  7231. else
  7232. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7233. return 0;
  7234. }
  7235. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7236. if (!lua_interface)
  7237. return 0;
  7238. Spawn* spawn = lua_interface->GetSpawn(state);
  7239. Item* item = lua_interface->GetItem(state, 2);
  7240. LuaSpell* spell = 0;
  7241. if (!spawn) {
  7242. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7243. return 0;
  7244. }
  7245. if (!spawn->IsEntity()) {
  7246. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. if (!item)
  7250. spell = lua_interface->GetCurrentSpell(state);
  7251. if (!item && !spell) {
  7252. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7253. return 0;
  7254. }
  7255. if (spell) {
  7256. Spawn* target;
  7257. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7258. for (int8 i = 0; i < spell->targets.size(); i++) {
  7259. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7260. if (!target || !target->IsEntity())
  7261. continue;
  7262. ((Entity*)target)->RemoveProc(item, spell);
  7263. }
  7264. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7265. spell->caster->RemoveProc(item, spell);
  7266. }
  7267. else
  7268. ((Entity*)spawn)->RemoveProc(item, spell);
  7269. return 0;
  7270. }
  7271. int EQ2Emu_lua_Knockback(lua_State* state) {
  7272. if (!lua_interface)
  7273. return 0;
  7274. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7275. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7276. int32 duration = lua_interface->GetInt32Value(state, 3);
  7277. float vertical = lua_interface->GetFloatValue(state, 4);
  7278. float horizontal = lua_interface->GetFloatValue(state, 5);
  7279. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7280. if (!target_spawn) {
  7281. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7282. return 0;
  7283. }
  7284. if (!spawn) {
  7285. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7286. return 0;
  7287. }
  7288. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7289. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7290. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7291. if (packet) {
  7292. packet->setDataByName("target_x", target_spawn->GetX());
  7293. packet->setDataByName("target_y", target_spawn->GetY());
  7294. packet->setDataByName("target_z", target_spawn->GetZ());
  7295. packet->setDataByName("vertical_movement", vertical);
  7296. packet->setDataByName("horizontal_movement", horizontal);
  7297. if (use_heading)
  7298. packet->setDataByName("use_player_heading", 1);
  7299. client->QueuePacket(packet->serialize());
  7300. }
  7301. safe_delete(packet);
  7302. }
  7303. return 0;
  7304. }
  7305. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7306. if (!lua_interface)
  7307. return 0;
  7308. Spawn* spawn = lua_interface->GetSpawn(state);
  7309. if (!spawn) {
  7310. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7311. return 0;
  7312. }
  7313. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7314. return 1;
  7315. }
  7316. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7317. if (!lua_interface)
  7318. return 0;
  7319. Spawn* caster = lua_interface->GetSpawn(state);
  7320. Spawn* target = lua_interface->GetSpawn(state, 2);
  7321. string name = lua_interface->GetStringValue(state, 3);
  7322. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7323. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7324. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7325. string success_msg = lua_interface->GetStringValue(state, 7);
  7326. string effect_msg = lua_interface->GetStringValue(state, 8);
  7327. if (!caster) {
  7328. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7329. return 0;
  7330. }
  7331. if (!caster->IsEntity()) {
  7332. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7333. return 0;
  7334. }
  7335. if (!target) {
  7336. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7337. return 0;
  7338. }
  7339. if (!target->IsEntity()) {
  7340. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7341. return 0;
  7342. }
  7343. if (name.length() == 0) {
  7344. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7345. return 0;
  7346. }
  7347. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7348. return 0;
  7349. }
  7350. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7351. if (!lua_interface)
  7352. return 0;
  7353. string name = lua_interface->GetStringValue(state);
  7354. if (name.length() == 0) {
  7355. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7356. return 0;
  7357. }
  7358. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7359. if (!skill) {
  7360. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7361. return 0;
  7362. }
  7363. lua_interface->SetInt32Value(state, skill->skill_id);
  7364. return 1;
  7365. }
  7366. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7367. if (!lua_interface)
  7368. return 0;
  7369. Spawn* spawn = lua_interface->GetSpawn(state);
  7370. if (!spawn) {
  7371. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7372. return 0;
  7373. }
  7374. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7375. return 1;
  7376. }
  7377. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7378. if (!lua_interface)
  7379. return 0;
  7380. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7381. if (!luaspell) {
  7382. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7383. return 0;
  7384. }
  7385. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7386. return 1;
  7387. }
  7388. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7389. if (!lua_interface)
  7390. return 0;
  7391. Spawn* spawn = lua_interface->GetSpawn(state);
  7392. Spawn* target = lua_interface->GetSpawn(state, 2);
  7393. if (!spawn) {
  7394. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7395. return 0;
  7396. }
  7397. if (!spawn->IsEntity()) {
  7398. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7399. return 0;
  7400. }
  7401. if (!target) {
  7402. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7403. return 0;
  7404. }
  7405. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7406. return 1;
  7407. }
  7408. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7409. if (!lua_interface)
  7410. return 0;
  7411. Spawn* spawn = lua_interface->GetSpawn(state);
  7412. Spawn* target = lua_interface->GetSpawn(state, 2);
  7413. if (!spawn) {
  7414. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7415. return 0;
  7416. }
  7417. if (!spawn->IsEntity()) {
  7418. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7419. return 0;
  7420. }
  7421. if (!target) {
  7422. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7423. return 0;
  7424. }
  7425. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7426. return 1;
  7427. }
  7428. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7429. if (!lua_interface)
  7430. return 0;
  7431. Item* item = lua_interface->GetItem(state);
  7432. if (!item) {
  7433. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7434. return 0;
  7435. }
  7436. lua_interface->SetInt32Value(state, item->details.count);
  7437. return 1;
  7438. }
  7439. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7440. if (!lua_interface)
  7441. return 0;
  7442. Item* item = lua_interface->GetItem(state);
  7443. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7444. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7445. if (!item) {
  7446. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. if (!owner) {
  7450. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. if (!owner->IsPlayer()) {
  7454. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7455. return 0;
  7456. }
  7457. if (item->stack_count < new_count) {
  7458. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7459. return 0;
  7460. }
  7461. if (new_count > 0) {
  7462. item->details.count = new_count;
  7463. item->save_needed = true;
  7464. }
  7465. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7466. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7467. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7468. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7469. else
  7470. {
  7471. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7472. return 0;
  7473. }
  7474. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7475. if (!client)
  7476. return 0;
  7477. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7478. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7479. if (app)
  7480. client->QueuePacket(app);
  7481. return 0;
  7482. }
  7483. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7484. if (!lua_interface)
  7485. return 0;
  7486. int32 time = lua_interface->GetInt32Value(state);
  7487. string function = lua_interface->GetStringValue(state, 2);
  7488. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7489. Spawn* target = lua_interface->GetSpawn(state, 4);
  7490. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7491. if (time == 0) {
  7492. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7493. return 0;
  7494. }
  7495. if (function.length() == 0) {
  7496. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7497. return 0;
  7498. }
  7499. if (!spell) {
  7500. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7501. return 0;
  7502. }
  7503. SpellScriptTimer* timer = new SpellScriptTimer;
  7504. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7505. #ifdef WIN32
  7506. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7507. #else
  7508. bzero(timer, sizeof(SpellScriptTimer));
  7509. #endif*/
  7510. timer->caster = 0;
  7511. timer->deleteWhenDone = false;
  7512. timer->target = 0;
  7513. timer->time = Timer::GetCurrentTime2() + time;
  7514. timer->customFunction = function;
  7515. timer->spell = spell;
  7516. if (caster)
  7517. timer->caster = caster->GetID();
  7518. if (target)
  7519. timer->target = target->GetID();
  7520. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7521. return 0;
  7522. }
  7523. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7524. if (!lua_interface)
  7525. return 0;
  7526. float hp_perc = lua_interface->GetFloatValue(state);
  7527. float power_perc = lua_interface->GetFloatValue(state, 2);
  7528. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7529. Spawn* target = lua_interface->GetSpawn(state, 4);
  7530. string heal_name = lua_interface->GetStringValue(state, 5);
  7531. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7532. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7533. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7534. if (!spell) {
  7535. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7536. return 0;
  7537. }
  7538. Entity* caster = spell->caster;
  7539. if (!caster) {
  7540. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7541. return 0;
  7542. }
  7543. Client* client = 0;
  7544. PendingResurrection* rez = 0;
  7545. ZoneServer* zone = spell->caster->GetZone();
  7546. if (!target) {
  7547. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7548. if (spell->targets.size() > 0) {
  7549. vector<int32> spell_targets = spell->targets;
  7550. for (int8 i = 0; i < spell_targets.size(); i++) {
  7551. target = zone->GetSpawnByID(spell_targets.at(i));
  7552. if (!target)
  7553. continue;
  7554. if (!target->IsPlayer())
  7555. continue;
  7556. client = target->GetZone()->GetClientBySpawn(target);
  7557. if (!client)
  7558. continue;
  7559. rez = client->GetCurrentRez();
  7560. if (rez->active)
  7561. continue;
  7562. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7563. rez->active = true;
  7564. rez->caster = caster;
  7565. rez->expire_timer = new Timer;
  7566. int32 duration = spell->spell->GetSpellDuration();
  7567. rez->expire_timer->Start(duration * 100);
  7568. rez->hp_perc = hp_perc;
  7569. rez->mp_perc = power_perc;
  7570. rez->range = spell->spell->GetSpellData()->range;
  7571. rez->spell_name = spell->spell->GetName();
  7572. if (heal_name.length() > 0)
  7573. rez->heal_name = heal_name;
  7574. else
  7575. rez->heal_name = rez->spell_name;
  7576. rez->no_calcs = no_calcs;
  7577. rez->crit_mod = crit_mod;
  7578. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7579. if (send_window)
  7580. client->SendResurrectionWindow();
  7581. else {
  7582. target->GetZone()->ResurrectSpawn(target, client);
  7583. rez->should_delete = true;
  7584. }
  7585. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7586. }
  7587. }
  7588. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7589. }
  7590. else {
  7591. client = target->GetZone()->GetClientBySpawn(target);
  7592. if (!client)
  7593. return 0;
  7594. rez = client->GetCurrentRez();
  7595. if (rez->active)
  7596. return 0;
  7597. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7598. rez->active = true;
  7599. rez->caster = caster;
  7600. rez->expire_timer = new Timer;
  7601. int32 duration = spell->spell->GetSpellDuration();
  7602. rez->expire_timer->Start(duration * 100);
  7603. rez->hp_perc = hp_perc;
  7604. rez->mp_perc = power_perc;
  7605. rez->range = spell->spell->GetSpellData()->range;
  7606. rez->spell_name = spell->spell->GetName();
  7607. if (heal_name.length() > 0)
  7608. rez->heal_name = heal_name;
  7609. else
  7610. rez->heal_name = rez->spell_name;
  7611. rez->no_calcs = no_calcs;
  7612. rez->crit_mod = crit_mod;
  7613. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7614. if (send_window)
  7615. client->SendResurrectionWindow();
  7616. else {
  7617. target->GetZone()->ResurrectSpawn(target, client);
  7618. rez->should_delete = true;
  7619. }
  7620. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7621. }
  7622. return 0;
  7623. }
  7624. int EQ2Emu_lua_SetVision(lua_State* state) {
  7625. if (!lua_interface)
  7626. return 0;
  7627. Spawn* spawn = lua_interface->GetSpawn(state);
  7628. int8 vision = lua_interface->GetInt8Value(state, 2);
  7629. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7630. if (!spawn) {
  7631. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7632. return 0;
  7633. }
  7634. if (!spawn->IsEntity()) {
  7635. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7636. return 0;
  7637. }
  7638. if (spell && spell->targets.size() > 0) {
  7639. ZoneServer* zone = spell->caster->GetZone();
  7640. for (int8 i = 0; i < spell->targets.size(); i++) {
  7641. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7642. if (target && target->IsEntity()) {
  7643. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7644. if (target->IsPlayer())
  7645. ((Player*)target)->SetCharSheetChanged(true);
  7646. }
  7647. }
  7648. }
  7649. else {
  7650. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7651. if (spawn->IsPlayer())
  7652. ((Player*)spawn)->SetCharSheetChanged(true);
  7653. }
  7654. return 0;
  7655. }
  7656. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7657. if (!lua_interface)
  7658. return 0;
  7659. Spawn* spawn = lua_interface->GetSpawn(state);
  7660. float intensity = lua_interface->GetFloatValue(state, 2);
  7661. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7662. if (!spawn) {
  7663. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if (!spawn->IsEntity()) {
  7667. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. if (spell && spell->targets.size() > 0) {
  7671. ZoneServer* zone = spell->caster->GetZone();
  7672. for (int8 i = 0; i < spell->targets.size(); i++) {
  7673. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7674. if (target && target->IsEntity()) {
  7675. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7676. if (target->IsPlayer())
  7677. ((Player*)target)->SetCharSheetChanged(true);
  7678. }
  7679. }
  7680. }
  7681. else {
  7682. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7683. if (spawn->IsPlayer())
  7684. ((Player*)spawn)->SetCharSheetChanged(true);
  7685. }
  7686. return 0;
  7687. }
  7688. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Spawn* spawn = lua_interface->GetSpawn(state);
  7692. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7693. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7694. if (!spawn) {
  7695. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7696. return 0;
  7697. }
  7698. if (!spawn->IsEntity()) {
  7699. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en 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_breathe_underwater(breatheUnderwater);
  7708. if (target->IsPlayer())
  7709. ((Player*)target)->SetCharSheetChanged(true);
  7710. }
  7711. }
  7712. }
  7713. else {
  7714. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7715. if (spawn->IsPlayer())
  7716. ((Player*)spawn)->SetCharSheetChanged(true);
  7717. }
  7718. return 0;
  7719. }
  7720. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7721. if (!lua_interface)
  7722. return 0;
  7723. Item* item = lua_interface->GetItem(state);
  7724. int8 type = lua_interface->GetInt32Value(state, 2);
  7725. if (!item) {
  7726. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7727. return 0;
  7728. }
  7729. if (type == 1)
  7730. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7731. else if (type == 2)
  7732. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7733. return 1;
  7734. }
  7735. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7736. if (!lua_interface)
  7737. return 0;
  7738. Spawn* target = lua_interface->GetSpawn(state);
  7739. float val = lua_interface->GetFloatValue(state, 2);
  7740. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7741. // Added from Gangrenous post
  7742. if (spell && spell->resisted)
  7743. return 0;
  7744. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7745. if (val > 1.0f)
  7746. val = 1.0f - (val / 100.0f);
  7747. if (spell && spell->spell && spell->targets.size() > 0) {
  7748. ZoneServer* zone = spell->caster->GetZone();
  7749. for (int32 i = 0; i != spell->targets.size(); i++) {
  7750. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7751. if (spawn && spawn->IsEntity()) {
  7752. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7753. if (spawn->IsPlayer())
  7754. ((Player*)spawn)->SetCharSheetChanged(true);
  7755. }
  7756. }
  7757. }
  7758. else {
  7759. if (target && target->IsEntity()) {
  7760. ((Entity*)target)->SetSpeedMultiplier(val);
  7761. if (target->IsPlayer())
  7762. ((Player*)target)->SetCharSheetChanged(true);
  7763. }
  7764. }
  7765. return 0;
  7766. }
  7767. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7768. if (!lua_interface)
  7769. return 0;
  7770. Spawn* spawn = lua_interface->GetSpawn(state);
  7771. int16 model = lua_interface->GetInt16Value(state, 2);
  7772. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7773. if (spell && spell->spell && spell->targets.size() > 0) {
  7774. ZoneServer* zone = spell->caster->GetZone();
  7775. for (int32 i = 0; i < spell->targets.size(); i++) {
  7776. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7777. if (target)
  7778. target->SetIllusionModel(model);
  7779. }
  7780. }
  7781. else {
  7782. if (!spawn) {
  7783. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7784. return 0;
  7785. }
  7786. spawn->SetIllusionModel(model);
  7787. }
  7788. return 0;
  7789. }
  7790. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7791. if (!lua_interface)
  7792. return 0;
  7793. Spawn* spawn = lua_interface->GetSpawn(state);
  7794. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7795. if (spell && spell->spell && spell->targets.size() > 0) {
  7796. ZoneServer* zone = spell->caster->GetZone();
  7797. for (int32 i = 0; i < spell->targets.size(); i++) {
  7798. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7799. if (target)
  7800. target->SetIllusionModel(0);
  7801. }
  7802. }
  7803. else {
  7804. if (!spawn) {
  7805. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7806. return 0;
  7807. }
  7808. spawn->SetIllusionModel(0);
  7809. }
  7810. return 0;
  7811. }
  7812. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7813. if (!lua_interface)
  7814. return 0;
  7815. Spawn* caster = lua_interface->GetSpawn(state);
  7816. Spawn* target = lua_interface->GetSpawn(state, 2);
  7817. float chance = lua_interface->GetFloatValue(state, 3);
  7818. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7819. if (!caster) {
  7820. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7821. return 0;
  7822. }
  7823. if (!caster->IsEntity()) {
  7824. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7825. return 0;
  7826. }
  7827. if (!target) {
  7828. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7829. return 0;
  7830. }
  7831. if (!target->IsEntity()) {
  7832. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7833. return 0;
  7834. }
  7835. if (chance <= 0) {
  7836. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7837. return 0;
  7838. }
  7839. if (!spell) {
  7840. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7841. return 0;
  7842. }
  7843. if (((Entity*)caster)->GetThreatTransfer()) {
  7844. return 0;
  7845. }
  7846. ThreatTransfer* transfer = new ThreatTransfer;
  7847. transfer->Target = target->GetID();
  7848. transfer->Amount = chance;
  7849. transfer->Spell = spell;
  7850. ((Entity*)caster)->SetThreatTransfer(transfer);
  7851. return 0;
  7852. }
  7853. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7854. if (!lua_interface)
  7855. return 0;
  7856. Spawn* spawn = lua_interface->GetSpawn(state);
  7857. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7858. if (!spawn) {
  7859. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7860. return 0;
  7861. }
  7862. if (!spell) {
  7863. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7864. return 0;
  7865. }
  7866. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7867. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7868. ((Entity*)spawn)->SetThreatTransfer(0);
  7869. safe_delete(transfer);
  7870. }
  7871. return 0;
  7872. }
  7873. int EQ2Emu_lua_CureByType(lua_State* state) {
  7874. if (!lua_interface)
  7875. return 0;
  7876. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7877. if (!spell) {
  7878. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7879. return 0;
  7880. }
  7881. int8 cure_count = lua_interface->GetInt8Value(state);
  7882. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7883. string cure_name = lua_interface->GetStringValue(state, 3);
  7884. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7885. Spawn* target = lua_interface->GetSpawn(state, 5);
  7886. if (target) {
  7887. if (!target->IsEntity()) {
  7888. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7889. return 0;
  7890. }
  7891. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7892. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7893. }
  7894. else {
  7895. ZoneServer* zone = spell->caster->GetZone();
  7896. vector<int32> targets = spell->targets;
  7897. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7898. for (int8 i = 0; i < targets.size(); i++) {
  7899. target = zone->GetSpawnByID(targets.at(i));
  7900. if (!target || !target->IsEntity())
  7901. continue;
  7902. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7903. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7904. }
  7905. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7906. }
  7907. return 0;
  7908. }
  7909. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7910. if (!lua_interface)
  7911. return 0;
  7912. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7913. if (!spell) {
  7914. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7915. return 0;
  7916. }
  7917. int8 cure_count = lua_interface->GetInt8Value(state);
  7918. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7919. string cure_name = lua_interface->GetStringValue(state, 3);
  7920. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7921. Spawn* target = lua_interface->GetSpawn(state, 5);
  7922. if (target) {
  7923. if (!target->IsEntity()) {
  7924. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7925. return 0;
  7926. }
  7927. if (((Entity*)target)->GetDetCount() > 0)
  7928. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7929. }
  7930. else {
  7931. ZoneServer* zone = spell->caster->GetZone();
  7932. vector<int32> targets = spell->targets;
  7933. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7934. for (int8 i = 0; i < targets.size(); i++) {
  7935. target = zone->GetSpawnByID(targets.at(i));
  7936. if (!target || !target->IsEntity())
  7937. continue;
  7938. if (((Entity*)target)->GetDetCount() > 0)
  7939. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7940. }
  7941. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7942. }
  7943. return 0;
  7944. }
  7945. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7946. if (!lua_interface)
  7947. return 0;
  7948. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7949. if (!spell) {
  7950. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7951. return 0;
  7952. }
  7953. if (!spell->caster) {
  7954. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7955. return 0;
  7956. }
  7957. if (!spell->caster->GetZone()) {
  7958. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7959. return 0;
  7960. }
  7961. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7962. return 0;
  7963. }
  7964. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7965. if (!lua_interface)
  7966. return 0;
  7967. Spawn* spawn = lua_interface->GetSpawn(state);
  7968. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7969. if (!spell) {
  7970. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7971. return 0;
  7972. }
  7973. if (spawn && spawn->IsEntity())
  7974. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7975. else {
  7976. ZoneServer* zone = spell->caster->GetZone();
  7977. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7978. for (int32 i = 0; i < spell->targets.size(); i++) {
  7979. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7980. if (!spawn || !spawn->IsEntity())
  7981. continue;
  7982. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7983. }
  7984. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7985. }
  7986. return 0;
  7987. }
  7988. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7989. if (!lua_interface)
  7990. return 0;
  7991. Spawn* spawn = lua_interface->GetSpawn(state);
  7992. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7993. if (!spell) {
  7994. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. if (spawn && spawn->IsEntity())
  7998. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7999. else {
  8000. ZoneServer* zone = spell->caster->GetZone();
  8001. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8002. for (int32 i = 0; i < spell->targets.size(); i++) {
  8003. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8004. if (!spawn || !spawn->IsEntity())
  8005. continue;
  8006. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8007. }
  8008. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8009. }
  8010. return 0;
  8011. }
  8012. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8013. if (!lua_interface)
  8014. return 0;
  8015. Spawn* caster = lua_interface->GetSpawn(state);
  8016. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8017. if (!caster) {
  8018. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (!caster->IsPlayer()) {
  8022. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. Spawn* target = caster->GetTarget();
  8026. if (!target) {
  8027. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8028. return 0;
  8029. }
  8030. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8031. if (!client) {
  8032. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8033. return 0;
  8034. }
  8035. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8036. if (ho) {
  8037. ho->SetTarget(target->GetID());
  8038. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8039. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8040. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8041. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8042. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8043. deque<GroupMemberInfo*>::iterator itr;
  8044. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8045. if (group)
  8046. {
  8047. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8048. deque<GroupMemberInfo*>* members = group->GetMembers();
  8049. for (itr = members->begin(); itr != members->end(); itr++) {
  8050. if ((*itr)->client)
  8051. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8052. }
  8053. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8054. }
  8055. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8056. }
  8057. else
  8058. safe_delete(ho);
  8059. }
  8060. else {
  8061. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8062. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8063. }
  8064. else
  8065. safe_delete(ho);
  8066. }
  8067. }
  8068. return 0;
  8069. }
  8070. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8071. if (!lua_interface)
  8072. return 0;
  8073. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8074. if (!spell) {
  8075. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. int16 triggerCount = lua_interface->GetInt16Value(state);
  8079. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8080. if (!triggerCount) {
  8081. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8082. return 0;
  8083. }
  8084. spell->num_triggers = triggerCount;
  8085. spell->had_triggers = true;
  8086. spell->cancel_after_all_triggers = cancel_after_triggers;
  8087. return 0;
  8088. }
  8089. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8090. if (!lua_interface)
  8091. return 0;
  8092. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8093. if (!spell) {
  8094. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8095. return 0;
  8096. }
  8097. lua_interface->SetInt32Value(state, spell->num_triggers);
  8098. return 1;
  8099. }
  8100. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8101. if (!lua_interface)
  8102. return 0;
  8103. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8104. if (!spell) {
  8105. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. int16 remove_count = lua_interface->GetInt16Value(state);
  8109. if (!remove_count)
  8110. remove_count = 1;
  8111. if (remove_count >= spell->num_triggers) {
  8112. spell->num_triggers = 0;
  8113. if (spell->cancel_after_all_triggers)
  8114. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8115. }
  8116. else {
  8117. spell->num_triggers -= remove_count;
  8118. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8119. }
  8120. return 0;
  8121. }
  8122. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8123. if (!lua_interface)
  8124. return 0;
  8125. Spawn* spawn = lua_interface->GetSpawn(state);
  8126. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8127. if (!spawn) {
  8128. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8129. return 0;
  8130. }
  8131. if (!copy_spawn) {
  8132. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8133. return 0;
  8134. }
  8135. spawn->CopySpawnAppearance(copy_spawn);
  8136. return 0;
  8137. }
  8138. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8139. Spawn* spawn = lua_interface->GetSpawn(state);
  8140. int8 type = lua_interface->GetInt8Value(state, 2);
  8141. if (!spawn) {
  8142. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8143. return 0;
  8144. }
  8145. else if (!spawn->IsEntity()) {
  8146. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8147. return 0;
  8148. }
  8149. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8150. return 1;
  8151. }
  8152. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8153. if (!lua_interface)
  8154. return 0;
  8155. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8156. int8 type = lua_interface->GetInt8Value(state);
  8157. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8158. if (!spell) {
  8159. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. if (spawn) {
  8163. if (!spawn->IsEntity()) {
  8164. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8165. return 0;
  8166. }
  8167. Entity* entity = ((Entity*)spawn);
  8168. entity->AddImmunity(spell, type);
  8169. }
  8170. else {
  8171. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8172. for (int8 i = 0; i < spell->targets.size(); i++) {
  8173. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8174. if (!spawn || !spawn->IsEntity())
  8175. continue;
  8176. Entity* entity = ((Entity*)spawn);
  8177. entity->AddImmunity(spell, type);
  8178. }
  8179. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8180. }
  8181. return 0;
  8182. }
  8183. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8184. if (!lua_interface)
  8185. return 0;
  8186. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8187. int8 type = lua_interface->GetInt8Value(state);
  8188. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8189. if (!spell) {
  8190. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. if (spawn) {
  8194. if (!spawn->IsEntity()) {
  8195. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8196. return 0;
  8197. }
  8198. Entity* entity = ((Entity*)spawn);
  8199. entity->RemoveImmunity(spell, type);
  8200. }
  8201. else {
  8202. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8203. for (int8 i = 0; i < spell->targets.size(); i++) {
  8204. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8205. if (!spawn || !spawn->IsEntity())
  8206. continue;
  8207. Entity* entity = ((Entity*)spawn);
  8208. entity->RemoveImmunity(spell, type);
  8209. }
  8210. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8211. }
  8212. return 0;
  8213. }
  8214. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8215. if (!lua_interface)
  8216. return 0;
  8217. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8218. if (!spell) {
  8219. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8220. return 0;
  8221. }
  8222. float snare = lua_interface->GetFloatValue(state);
  8223. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8224. // convert the val to the speed multipler value (100 - val)
  8225. float val = 100.0 - snare;
  8226. val /= 100.0;
  8227. if (spawn) {
  8228. if (!spawn->IsEntity()) {
  8229. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8230. return 0;
  8231. }
  8232. ((Entity*)spawn)->SetSnareValue(spell, val);
  8233. }
  8234. else {
  8235. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8236. for (int8 i = 0; i < spell->targets.size(); i++) {
  8237. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8238. if (!spawn || !spawn->IsEntity())
  8239. continue;
  8240. ((Entity*)spawn)->SetSnareValue(spell, val);
  8241. }
  8242. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8243. }
  8244. return 0;
  8245. }
  8246. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8247. if (!lua_interface)
  8248. return 0;
  8249. Spawn* spawn = lua_interface->GetSpawn(state);
  8250. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8251. if (!spawn) {
  8252. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8253. return 0;
  8254. }
  8255. if (race_id == 0) {
  8256. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8260. return 1;
  8261. }
  8262. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8263. if (!lua_interface)
  8264. return 0;
  8265. Spawn* spawn = lua_interface->GetSpawn(state);
  8266. if (!spawn) {
  8267. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8268. return 0;
  8269. }
  8270. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8271. return 1;
  8272. }
  8273. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8274. if (!lua_interface)
  8275. return 0;
  8276. Spawn* spawn = lua_interface->GetSpawn(state);
  8277. if (!spawn) {
  8278. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8282. return 1;
  8283. }
  8284. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8285. if (!lua_interface)
  8286. return 0;
  8287. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8288. if (!spell) {
  8289. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8290. return 0;
  8291. }
  8292. lua_interface->SetStringValue(state, spell->spell->GetName());
  8293. return 1;
  8294. }
  8295. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8296. if (!lua_interface)
  8297. return 0;
  8298. Quest* quest = lua_interface->GetQuest(state);
  8299. if (!quest) {
  8300. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8301. return 0;
  8302. }
  8303. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8304. return 1;
  8305. }
  8306. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8307. if (!lua_interface)
  8308. return 0;
  8309. Quest* quest = lua_interface->GetQuest(state);
  8310. int32 flags = lua_interface->GetInt32Value(state, 2);
  8311. if (!quest) {
  8312. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8313. return 0;
  8314. }
  8315. quest->SetQuestFlags(flags);
  8316. return 0;
  8317. }
  8318. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8319. if (!lua_interface)
  8320. return 0;
  8321. Quest* quest = lua_interface->GetQuest(state);
  8322. Spawn* player = lua_interface->GetSpawn(state, 2);
  8323. int32 step = lua_interface->GetInt32Value(state, 3);
  8324. int32 duration = lua_interface->GetInt32Value(state, 4);
  8325. string action = lua_interface->GetStringValue(state, 5);
  8326. if (!quest) {
  8327. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8328. return 0;
  8329. }
  8330. if (!player) {
  8331. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8332. return 0;
  8333. }
  8334. if (!player->IsPlayer()) {
  8335. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. if (step == 0) {
  8339. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. if (duration == 0) {
  8343. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. if (action.length() == 0) {
  8347. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8348. return 0;
  8349. }
  8350. Client* client = player->GetZone()->GetClientBySpawn(player);
  8351. if (!client) {
  8352. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. quest->SetTimerStep(step);
  8356. quest->AddFailedAction(step, action);
  8357. quest->SetStepTimer(duration);
  8358. client->AddQuestTimer(quest->GetQuestID());
  8359. return 0;
  8360. }
  8361. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8362. if (!lua_interface)
  8363. return 0;
  8364. Quest* quest = lua_interface->GetQuest(state);
  8365. Spawn* player = lua_interface->GetSpawn(state, 2);
  8366. if (!quest) {
  8367. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. if (!player) {
  8371. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8372. return 0;
  8373. }
  8374. if (!player->IsPlayer()) {
  8375. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8376. return 0;
  8377. }
  8378. Client* client = player->GetZone()->GetClientBySpawn(player);
  8379. if (!client) {
  8380. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. quest->SetTimerStep(0);
  8384. quest->SetStepTimer(0);
  8385. client->RemoveQuestTimer(quest->GetQuestID());
  8386. return 0;
  8387. }
  8388. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8389. if (!lua_interface)
  8390. return 0;
  8391. Spawn* player = lua_interface->GetSpawn(state);
  8392. Quest* quest = lua_interface->GetQuest(state, 2);
  8393. int32 step = lua_interface->GetInt32Value(state, 3);
  8394. if (!player) {
  8395. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8396. return 0;
  8397. }
  8398. if (!player->IsPlayer()) {
  8399. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8400. return 0;
  8401. }
  8402. if (!quest) {
  8403. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. if (step == 0) {
  8407. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. Client* client = player->GetZone()->GetClientBySpawn(player);
  8411. if (!client) {
  8412. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8413. return 0;
  8414. }
  8415. if (quest->RemoveQuestStep(step, client)) {
  8416. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8417. client->GetCurrentZone()->SendQuestUpdates(client);
  8418. }
  8419. else
  8420. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8421. return 0;
  8422. }
  8423. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8424. if (!lua_interface)
  8425. return 0;
  8426. Quest* quest = lua_interface->GetQuest(state, 1);
  8427. int32 step = lua_interface->GetInt32Value(state, 2);
  8428. string desc = lua_interface->GetStringValue(state, 3);
  8429. string task_group = lua_interface->GetStringValue(state, 4);
  8430. if (!quest) {
  8431. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8432. return 0;
  8433. }
  8434. if (step == 0) {
  8435. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8436. return 0;
  8437. }
  8438. QuestStep* quest_step = quest->GetQuestStep(step);
  8439. if (!quest_step) {
  8440. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8441. return 0;
  8442. }
  8443. quest_step->SetStepProgress(0);
  8444. quest_step->SetTaskGroup(task_group);
  8445. quest_step->SetDescription(desc);
  8446. return 0;
  8447. }
  8448. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8449. if (!lua_interface)
  8450. return 0;
  8451. Quest* quest = lua_interface->GetQuest(state);
  8452. int32 step = lua_interface->GetInt32Value(state, 2);
  8453. string action = lua_interface->GetStringValue(state, 3);
  8454. if (!quest) {
  8455. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. if (step == 0) {
  8459. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8460. return 0;
  8461. }
  8462. if (action.length() == 0) {
  8463. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8464. return 0;
  8465. }
  8466. quest->AddFailedAction(step, action);
  8467. return 0;
  8468. }
  8469. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8470. if (!lua_interface)
  8471. return 0;
  8472. Spawn* player = lua_interface->GetSpawn(state);
  8473. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8474. int32 step = lua_interface->GetInt32Value(state, 3);
  8475. if (!player) {
  8476. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8477. return 0;
  8478. }
  8479. if (!player->IsPlayer()) {
  8480. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8481. return 0;
  8482. }
  8483. if (quest_id == 0) {
  8484. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8485. return 0;
  8486. }
  8487. if (step == 0) {
  8488. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8489. return 0;
  8490. }
  8491. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8492. if (!quest) {
  8493. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8494. return 0;
  8495. }
  8496. quest->StepFailed(step);
  8497. return 0;
  8498. }
  8499. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8500. if (!lua_interface)
  8501. return 0;
  8502. Spawn* player = lua_interface->GetSpawn(state);
  8503. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8504. if (!player) {
  8505. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8506. return 0;
  8507. }
  8508. if (!player->IsPlayer()) {
  8509. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8510. return 0;
  8511. }
  8512. if (quest_id == 0) {
  8513. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8514. return 0;
  8515. }
  8516. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8517. if (!quest) {
  8518. lua_interface->SetInt32Value(state, 0);
  8519. return 1;
  8520. }
  8521. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8522. return 1;
  8523. }
  8524. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8525. if (!lua_interface)
  8526. return 0;
  8527. string name = lua_interface->GetStringValue(state);
  8528. string value = lua_interface->GetStringValue(state, 2);
  8529. string comment = lua_interface->GetStringValue(state, 3);
  8530. if (name.length() == 0) {
  8531. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. if (value.length() == 0) {
  8535. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. string varname = string("lua_").append(name);
  8539. Variable* var = variables.FindVariable(varname);
  8540. if (var)
  8541. var->SetValue(value.c_str());
  8542. else {
  8543. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8544. variables.AddVariable(var);
  8545. }
  8546. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8547. return 0;
  8548. }
  8549. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8550. if (!lua_interface)
  8551. return 0;
  8552. string name = lua_interface->GetStringValue(state);
  8553. if (name.length() == 0) {
  8554. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. string varname = string("lua_").append(name);
  8558. Variable* var = variables.FindVariable(varname);
  8559. if (var)
  8560. lua_interface->SetStringValue(state, var->GetValue());
  8561. else
  8562. lua_interface->SetStringValue(state, "NULL");
  8563. return 1;
  8564. }
  8565. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8566. if (!lua_interface)
  8567. return 0;
  8568. Spawn* player = lua_interface->GetSpawn(state);
  8569. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8570. if (!player) {
  8571. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8572. return 0;
  8573. }
  8574. if (!player->IsPlayer()) {
  8575. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8576. return 0;
  8577. }
  8578. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8579. return 1;
  8580. }
  8581. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8582. if (!lua_interface)
  8583. return 0;
  8584. Spawn* player = lua_interface->GetSpawn(state);
  8585. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8586. if (!player) {
  8587. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8588. return 0;
  8589. }
  8590. if (!player->IsPlayer()) {
  8591. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8592. return 0;
  8593. }
  8594. Language* language = master_languages_list.GetLanguage(language_id);
  8595. if (language)
  8596. {
  8597. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8598. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8599. }
  8600. return 0;
  8601. }
  8602. int EQ2Emu_lua_IsNight(lua_State* state) {
  8603. if (!lua_interface)
  8604. return 0;
  8605. ZoneServer* zone = lua_interface->GetZone(state);
  8606. if (!zone) {
  8607. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8608. return 0;
  8609. }
  8610. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8611. return 1;
  8612. }
  8613. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8614. if (!lua_interface)
  8615. return 0;
  8616. Spawn* spawn = lua_interface->GetSpawn(state);
  8617. if (!spawn) {
  8618. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8619. return 0;
  8620. }
  8621. if (!spawn->IsWidget()) {
  8622. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. ((Widget*)spawn)->SetMultiFloorLift(true);
  8626. if (spawn->GetZone())
  8627. spawn->GetZone()->AddTransportSpawn(spawn);
  8628. return 0;
  8629. }
  8630. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. Spawn* player = lua_interface->GetSpawn(state);
  8634. int32 path = lua_interface->GetInt32Value(state, 2);
  8635. if (!player) {
  8636. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8637. return 0;
  8638. }
  8639. if (!player->IsPlayer()) {
  8640. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8641. return 0;
  8642. }
  8643. if (path == 0) {
  8644. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8645. return 0;
  8646. }
  8647. Client* client = player->GetZone()->GetClientBySpawn(player);
  8648. if (!client) {
  8649. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8650. return 0;
  8651. }
  8652. client->SendFlightAutoMount(path);
  8653. return 0;
  8654. }
  8655. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8656. if (!lua_interface)
  8657. return 0;
  8658. Spawn* player = lua_interface->GetSpawn(state);
  8659. if (!player) {
  8660. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8661. return 0;
  8662. }
  8663. if (!player->IsPlayer()) {
  8664. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8665. return 0;
  8666. }
  8667. Client* client = player->GetZone()->GetClientBySpawn(player);
  8668. if (!client) {
  8669. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8670. return 0;
  8671. }
  8672. client->EndAutoMount();
  8673. return 0;
  8674. }
  8675. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8676. if (!lua_interface)
  8677. return 0;
  8678. Spawn* player = lua_interface->GetSpawn(state);
  8679. if (!player) {
  8680. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8681. return 0;
  8682. }
  8683. if (!player->IsPlayer()) {
  8684. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8685. return 0;
  8686. }
  8687. Client* client = player->GetZone()->GetClientBySpawn(player);
  8688. if (!client) {
  8689. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8693. return 1;
  8694. }
  8695. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8696. if (!lua_interface)
  8697. return 0;
  8698. Spawn* player = lua_interface->GetSpawn(state);
  8699. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8700. int32 value = lua_interface->GetInt32Value(state, 3);
  8701. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8702. if (!player) {
  8703. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8704. return 0;
  8705. }
  8706. if (!player->IsPlayer()) {
  8707. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8708. return 0;
  8709. }
  8710. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8711. return 0;
  8712. }
  8713. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8714. if (!lua_interface)
  8715. return 0;
  8716. Spawn* player = lua_interface->GetSpawn(state);
  8717. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8718. if (!player) {
  8719. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8720. return 0;
  8721. }
  8722. if (!player->IsPlayer()) {
  8723. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8727. if (!hd)
  8728. return 0;
  8729. lua_interface->SetInt32Value(state, hd->Value);
  8730. lua_interface->SetInt32Value(state, hd->Value2);
  8731. return 2;
  8732. }
  8733. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8734. if (!lua_interface)
  8735. return 0;
  8736. Spawn* spawn = lua_interface->GetSpawn(state);
  8737. int32 grid = lua_interface->GetInt32Value(state, 2);
  8738. if (!spawn) {
  8739. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. if (grid == 0) {
  8743. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8744. return 0;
  8745. }
  8746. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8747. return 0;
  8748. }
  8749. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8750. if (!lua_interface)
  8751. return 0;
  8752. Spawn* spawn = lua_interface->GetSpawn(state);
  8753. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8754. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8755. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8756. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8757. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8758. if (!spawn) {
  8759. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. //Add this quest to the list of required quests for this spawn
  8763. spawn->SetRequiredHistory(event_id, value1, value2);
  8764. //If private spawn value set
  8765. if (private_spawn) {
  8766. //Set the spawn to be private when not granted access via history
  8767. spawn->AddAllowAccessSpawn(spawn);
  8768. spawn->SetPrivateQuestSpawn(true);
  8769. }
  8770. //This value will override vis_flags in the vis packet
  8771. if (flag_override > 0)
  8772. spawn->SetQuestsRequiredOverride(flag_override);
  8773. return 0;
  8774. }
  8775. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8776. if (!lua_interface)
  8777. return 0;
  8778. Spawn* player = lua_interface->GetSpawn(state);
  8779. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8780. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8781. if (!player) {
  8782. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8783. return 0;
  8784. }
  8785. if (!player->IsPlayer()) {
  8786. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8790. return 1;
  8791. }
  8792. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8793. if (!lua_interface)
  8794. return 0;
  8795. Spawn* player = lua_interface->GetSpawn(state);
  8796. int8 level = lua_interface->GetInt8Value(state, 2);
  8797. if (!player) {
  8798. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. if (!player->IsPlayer()) {
  8802. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. if (level == 0) {
  8806. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8807. return 0;
  8808. }
  8809. Client* client = player->GetZone()->GetClientBySpawn(player);
  8810. if (!client) {
  8811. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8812. return 0;
  8813. }
  8814. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8815. return 0;
  8816. }
  8817. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8818. if (!lua_interface)
  8819. return 0;
  8820. Spawn* player = lua_interface->GetSpawn(state);
  8821. int32 amount = lua_interface->GetInt32Value(state, 2);
  8822. if (!player) {
  8823. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. if (!player->IsPlayer()) {
  8827. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. if (amount == 0) {
  8831. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. ((Player*)player)->AddCoins(amount);
  8835. return 0;
  8836. }
  8837. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8838. if (!lua_interface)
  8839. return 0;
  8840. Spawn* player = lua_interface->GetSpawn(state);
  8841. int32 amount = lua_interface->GetInt32Value(state, 2);
  8842. if (!player) {
  8843. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8844. return 0;
  8845. }
  8846. if (!player->IsPlayer()) {
  8847. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8848. return 0;
  8849. }
  8850. if (amount == 0) {
  8851. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8852. return 0;
  8853. }
  8854. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8855. return 1;
  8856. }
  8857. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8858. if (!lua_interface)
  8859. return 0;
  8860. ZoneServer* zone = lua_interface->GetZone(state);
  8861. if (!zone) {
  8862. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. vector<Entity*> players = zone->GetPlayers();
  8866. if (players.size() == 0)
  8867. return 0;
  8868. lua_createtable(state, players.size(), 0);
  8869. int newTable = lua_gettop(state);
  8870. for (int32 i = 0; i < players.size(); i++) {
  8871. lua_interface->SetSpawnValue(state, players.at(i));
  8872. lua_rawseti(state, newTable, i + 1);
  8873. }
  8874. return 1;
  8875. }
  8876. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8877. if (!lua_interface)
  8878. return 0;
  8879. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8880. if (!zone) {
  8881. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8882. return 0;
  8883. }
  8884. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8885. //Map of <placement_id, location_id>
  8886. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8887. map<int32, int32>::iterator itr;
  8888. vector<Spawn*> group;
  8889. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8890. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8891. if (!location) {
  8892. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8893. return 0;
  8894. }
  8895. Spawn* spawn = 0;
  8896. if (location->entities[0]) {
  8897. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8898. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8899. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8900. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8901. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8902. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8903. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8904. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8905. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8906. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8907. if(spawn && spawn->IsOmittedByDBFlag())
  8908. {
  8909. 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);
  8910. safe_delete(spawn);
  8911. continue;
  8912. }
  8913. if (spawn) {
  8914. const char* script = 0;
  8915. for (int x = 0; x < 3; x++) {
  8916. switch (x) {
  8917. case 0:
  8918. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8919. break;
  8920. case 1:
  8921. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8922. break;
  8923. case 2:
  8924. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8925. break;
  8926. }
  8927. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8928. spawn->SetSpawnScript(string(script));
  8929. break;
  8930. }
  8931. }
  8932. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8933. lua_interface->SetSpawnValue(state, spawn);
  8934. group.push_back(spawn);
  8935. }
  8936. else {
  8937. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8938. safe_delete(spawn);
  8939. }
  8940. }
  8941. }
  8942. if (!group.empty()) {
  8943. lua_createtable(state, group.size(), 0);
  8944. int newTable = lua_gettop(state);
  8945. for (int32 i = 0; i < group.size(); i++) {
  8946. lua_interface->SetSpawnValue(state, group[i]);
  8947. lua_rawseti(state, newTable, i + 1);
  8948. }
  8949. }
  8950. else
  8951. lua_pushnil(state);
  8952. return 1;
  8953. }
  8954. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8955. if (!lua_interface)
  8956. return 0;
  8957. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8958. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8959. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8960. if (!spawn) {
  8961. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. if (anim_id == 0) {
  8965. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8966. return 0;
  8967. }
  8968. if (leeway == 0)
  8969. leeway = 5000;
  8970. spawn->SetSpawnAnim(anim_id);
  8971. spawn->SetSpawnAnimLeeway(leeway);
  8972. return 0;
  8973. }
  8974. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8975. if (!lua_interface)
  8976. return 0;
  8977. Spawn* player = lua_interface->GetSpawn(state);
  8978. if (!player) {
  8979. return 0;
  8980. }
  8981. Client* client = player->GetZone()->GetClientBySpawn(player);
  8982. if (!client) {
  8983. return 0;
  8984. }
  8985. lua_interface->SetInt32Value(state, client->GetVersion());
  8986. return 1;
  8987. }
  8988. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8989. if (!lua_interface)
  8990. return 0;
  8991. Item* item = lua_interface->GetItem(state);
  8992. if (!item) {
  8993. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8994. return 0;
  8995. }
  8996. lua_interface->SetInt32Value(state, item->details.item_id);
  8997. return 1;
  8998. }
  8999. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9000. if (!lua_interface)
  9001. return 0;
  9002. Spawn* spawn = lua_interface->GetSpawn(state);
  9003. if (!spawn) {
  9004. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9005. return 0;
  9006. }
  9007. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9008. return 1;
  9009. }
  9010. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9011. if (!lua_interface)
  9012. return 0;
  9013. Spawn* spawn = lua_interface->GetSpawn(state);
  9014. if (!spawn) {
  9015. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9016. return 0;
  9017. }
  9018. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9019. return 1;
  9020. }
  9021. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9022. if (!lua_interface)
  9023. return 0;
  9024. Spawn* spawn = lua_interface->GetSpawn(state);
  9025. if (!spawn) {
  9026. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9027. return 0;
  9028. }
  9029. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9030. return 1;
  9031. }
  9032. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9033. if (!lua_interface)
  9034. return 0;
  9035. Spawn* spawn = lua_interface->GetSpawn(state);
  9036. if (!spawn) {
  9037. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9038. return 0;
  9039. }
  9040. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9041. return 1;
  9042. }
  9043. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9044. if (!lua_interface)
  9045. return 0;
  9046. Spawn* spawn = lua_interface->GetSpawn(state);
  9047. float pct = lua_interface->GetFloatValue(state, 2);
  9048. if (!spawn) {
  9049. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9050. return 0;
  9051. }
  9052. if (pct == 0) {
  9053. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9054. return 0;
  9055. }
  9056. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9057. lua_interface->SetInt32Value(state, amount);
  9058. return 1;
  9059. }
  9060. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. Spawn* spawn = lua_interface->GetSpawn(state);
  9064. float pct = lua_interface->GetFloatValue(state, 2);
  9065. if (!spawn) {
  9066. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9067. return 0;
  9068. }
  9069. if (pct == 0) {
  9070. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9074. lua_interface->SetInt32Value(state, amount);
  9075. return 1;
  9076. }
  9077. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9078. if (!lua_interface)
  9079. return 0;
  9080. Spawn* spawn = lua_interface->GetSpawn(state);
  9081. if (!spawn) {
  9082. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9083. return 0;
  9084. }
  9085. if (!spawn->IsPlayer()) {
  9086. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9087. return 0;
  9088. }
  9089. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9090. return 1;
  9091. }
  9092. int EQ2Emu_lua_Evac(lua_State* state) {
  9093. if (!lua_interface)
  9094. return 0;
  9095. Spawn* target = lua_interface->GetSpawn(state);
  9096. if (target) {
  9097. float x = target->GetZone()->GetSafeX();
  9098. float y = target->GetZone()->GetSafeY();
  9099. float z = target->GetZone()->GetSafeZ();
  9100. float h = target->GetZone()->GetSafeHeading();
  9101. target->SetX(x);
  9102. target->SetY(y);
  9103. target->SetZ(z);
  9104. target->SetHeading(h);
  9105. target->SetSpawnOrigX(x);
  9106. target->SetSpawnOrigY(y);
  9107. target->SetSpawnOrigZ(z);
  9108. target->SetSpawnOrigHeading(h);
  9109. if (target->IsPlayer()) {
  9110. Client* client = target->GetZone()->GetClientBySpawn(target);
  9111. if (client) {
  9112. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9113. int numargs = lua_interface->GetNumberOfArgs(state);
  9114. if(numargs == 4) {
  9115. x = lua_interface->GetFloatValue(state,1);
  9116. y = lua_interface->GetFloatValue(state,2);
  9117. z = lua_interface->GetFloatValue(state,3);
  9118. h = lua_interface->GetFloatValue(state,4);
  9119. }
  9120. client->SetReloadingZone(true);
  9121. target->SetX(x);
  9122. target->SetY(y);
  9123. target->SetZ(z);
  9124. target->SetHeading(h);
  9125. target->SetSpawnOrigX(x);
  9126. target->SetSpawnOrigY(y);
  9127. target->SetSpawnOrigZ(z);
  9128. target->SetSpawnOrigHeading(h);
  9129. target->SetAppearancePosition(x,y,z);
  9130. client->SetZoningCoords(x,y,z,h);
  9131. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9132. if (packet)
  9133. {
  9134. packet->setDataByName("x", x);
  9135. packet->setDataByName("y", y);
  9136. packet->setDataByName("z", z);
  9137. client->QueuePacket(packet->serialize());
  9138. safe_delete(packet);
  9139. }
  9140. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9141. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9142. }
  9143. }
  9144. }
  9145. else {
  9146. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9147. ZoneServer* zone = spell->caster->GetZone();
  9148. float x = spell->caster->GetZone()->GetSafeX();
  9149. float y = spell->caster->GetZone()->GetSafeY();
  9150. float z = spell->caster->GetZone()->GetSafeZ();
  9151. float h = spell->caster->GetZone()->GetSafeHeading();
  9152. int numargs = lua_interface->GetNumberOfArgs(state);
  9153. if(numargs == 4) {
  9154. x = lua_interface->GetFloatValue(state,1);
  9155. y = lua_interface->GetFloatValue(state,2);
  9156. z = lua_interface->GetFloatValue(state,3);
  9157. h = lua_interface->GetFloatValue(state,4);
  9158. }
  9159. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9160. for (int32 i = 0; i < spell->targets.size(); i++) {
  9161. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9162. if (!target2)
  9163. continue;
  9164. if (target2->IsPlayer()) {
  9165. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9166. if (client) {
  9167. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9168. client->SetReloadingZone(true);
  9169. target2->SetX(x);
  9170. target2->SetY(y);
  9171. target2->SetZ(z);
  9172. target2->SetHeading(h);
  9173. target2->SetSpawnOrigX(x);
  9174. target2->SetSpawnOrigY(y);
  9175. target2->SetSpawnOrigZ(z);
  9176. target2->SetSpawnOrigHeading(h);
  9177. target2->SetAppearancePosition(x,y,z);
  9178. client->SetZoningCoords(x,y,z,h);
  9179. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9180. if (packet)
  9181. {
  9182. packet->setDataByName("x", x);
  9183. packet->setDataByName("y", y);
  9184. packet->setDataByName("z", z);
  9185. client->QueuePacket(packet->serialize());
  9186. safe_delete(packet);
  9187. }
  9188. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9189. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9190. }
  9191. }
  9192. }
  9193. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9194. }
  9195. return 0;
  9196. }
  9197. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9198. if (!lua_interface)
  9199. return 0;
  9200. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9201. if (!luaspell) {
  9202. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9203. return 0;
  9204. }
  9205. int8 tier = luaspell->spell->GetSpellTier();
  9206. lua_interface->SetInt32Value(state, tier);
  9207. return 1;
  9208. }
  9209. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9210. if (!lua_interface)
  9211. return 0;
  9212. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9213. if (!luaspell) {
  9214. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9215. return 0;
  9216. }
  9217. int32 spell_id = luaspell->spell->GetSpellID();
  9218. lua_interface->SetInt32Value(state, spell_id);
  9219. return 1;
  9220. }
  9221. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9222. if (!lua_interface)
  9223. return 0;
  9224. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9225. if (!spawn) {
  9226. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9227. return 0;
  9228. }
  9229. if (!spawn->IsPlayer()) {
  9230. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9231. return 0;
  9232. }
  9233. ZoneServer* zone = spawn->GetZone();
  9234. if (!zone) {
  9235. return 0;
  9236. }
  9237. Client* client = zone->GetClientBySpawn(spawn);
  9238. if (!client) {
  9239. return 0;
  9240. }
  9241. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9242. return 0;
  9243. }
  9244. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9245. if (!lua_interface)
  9246. return 0;
  9247. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9248. if (!spawn) {
  9249. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9250. return 0;
  9251. }
  9252. if (!spawn->IsPlayer()) {
  9253. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9254. return 0;
  9255. }
  9256. ZoneServer* zone = spawn->GetZone();
  9257. if (!zone) {
  9258. return 0;
  9259. }
  9260. Client* client = zone->GetClientBySpawn(spawn);
  9261. if (!client) {
  9262. return 0;
  9263. }
  9264. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9265. return 0;
  9266. }
  9267. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9268. if (!lua_interface)
  9269. return 0;
  9270. Spawn* caster = lua_interface->GetSpawn(state);
  9271. Spawn* target = lua_interface->GetSpawn(state, 2);
  9272. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9273. string spell_name = lua_interface->GetStringValue(state, 4);
  9274. if (!caster) {
  9275. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9276. return 0;
  9277. }
  9278. if (!caster->IsEntity()) {
  9279. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9280. return 0;
  9281. }
  9282. if (!target) {
  9283. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9284. return 0;
  9285. }
  9286. if (!target->IsEntity()) {
  9287. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9288. return 0;
  9289. }
  9290. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9291. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9292. return 0;
  9293. }
  9294. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9295. if (!lua_interface)
  9296. return 0;
  9297. Spawn* player = lua_interface->GetSpawn(state);
  9298. int32 amount = lua_interface->GetInt32Value(state, 2);
  9299. if (player && player->IsPlayer() && amount > 0) {
  9300. ((Player*)player)->AddXP(amount);
  9301. ((Player*)player)->SetCharSheetChanged(true);
  9302. Client* client = player->GetZone()->GetClientBySpawn(player);
  9303. if (client) {
  9304. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9305. }
  9306. }
  9307. return 0;
  9308. }
  9309. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9310. if (!lua_interface)
  9311. return 0;
  9312. Spawn* player = lua_interface->GetSpawn(state);
  9313. int8 type = lua_interface->GetInt8Value(state, 2);
  9314. string text = lua_interface->GetStringValue(state, 3);
  9315. Client* client = 0;
  9316. if (player && player->IsPlayer())
  9317. client = player->GetZone()->GetClientBySpawn(player);
  9318. if (!client || text.length() == 0) {
  9319. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9320. return 0;
  9321. }
  9322. client->SimpleMessage(type, text.c_str());
  9323. return 0;
  9324. }
  9325. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9326. if (!lua_interface)
  9327. return 0;
  9328. Spawn* player = lua_interface->GetSpawn(state);
  9329. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9330. Client* client = 0;
  9331. if (player && player->IsPlayer())
  9332. client = player->GetZone()->GetClientBySpawn(player);
  9333. if (!client || !spawn) {
  9334. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9335. return 0;
  9336. }
  9337. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9338. if (!items) {
  9339. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9340. return 0;
  9341. }
  9342. client->Loot(spawn->GetLootCoins(), items, spawn);
  9343. return 0;
  9344. }
  9345. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9346. if (!lua_interface)
  9347. return 0;
  9348. Spawn* spawnref = lua_interface->GetSpawn(state);
  9349. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9350. if (spawn_id > 0 && spawnref) {
  9351. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9352. if (spawns.size() == 0) {
  9353. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9354. return 0;
  9355. }
  9356. Spawn* spawn = 0;
  9357. int16 index = MakeRandomInt(0, spawns.size());
  9358. if (index >= spawns.size() || index < 0)
  9359. index = 0;
  9360. spawn = spawns[index];
  9361. lua_interface->SetSpawnValue(state, spawn);
  9362. return 1;
  9363. }
  9364. else {
  9365. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9366. }
  9367. return 0;
  9368. }
  9369. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9370. Spawn* player = lua_interface->GetSpawn(state);
  9371. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9372. string name = lua_interface->GetStringValue(state, 3);
  9373. float distance = lua_interface->GetFloatValue(state, 4);
  9374. string command = lua_interface->GetStringValue(state, 5);
  9375. string error_text = lua_interface->GetStringValue(state, 6);
  9376. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9377. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9378. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9379. if (distance == 0)
  9380. distance = 10.0f;
  9381. if (command.length() == 0)
  9382. command = name;
  9383. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9384. if (spawns.size() == 0) {
  9385. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. Spawn* spawn = 0;
  9389. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9390. spawn = *itr;
  9391. if (spawn) {
  9392. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9393. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9394. }
  9395. }
  9396. }
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Client* client = 0;
  9403. Spawn* player = lua_interface->GetSpawn(state);
  9404. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9405. if (player && player->IsPlayer() && player->GetZone())
  9406. client = player->GetZone()->GetClientBySpawn(player);
  9407. else{
  9408. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9409. return 0;
  9410. }
  9411. if (client) {
  9412. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9413. if (packet) {
  9414. packet->setDataByName("goal_num", goal_num);
  9415. client->QueuePacket(packet->serialize());
  9416. safe_delete(packet);
  9417. }
  9418. }
  9419. return 0;
  9420. }
  9421. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9422. if (!lua_interface)
  9423. return 0;
  9424. Client* client = 0;
  9425. Spawn* player = lua_interface->GetSpawn(state);
  9426. if (player && player->IsPlayer() && player->GetZone())
  9427. client = player->GetZone()->GetClientBySpawn(player);
  9428. else {
  9429. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9430. return 0;
  9431. }
  9432. if (client) {
  9433. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9434. }
  9435. return 0;
  9436. }
  9437. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9438. if (!lua_interface)
  9439. return 0;
  9440. Client* client = 0;
  9441. Spawn* player = lua_interface->GetSpawn(state);
  9442. float duration = lua_interface->GetFloatValue(state, 2);
  9443. string text = lua_interface->GetStringValue(state, 3);
  9444. string voice = lua_interface->GetStringValue(state, 4);
  9445. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9446. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9447. string signal = lua_interface->GetStringValue(state, 7);
  9448. string goal1 = lua_interface->GetStringValue(state, 8);
  9449. string task1 = lua_interface->GetStringValue(state, 9);
  9450. string goal2 = lua_interface->GetStringValue(state, 10);
  9451. string task2 = lua_interface->GetStringValue(state, 11);
  9452. string goal3 = lua_interface->GetStringValue(state, 12);
  9453. string task3 = lua_interface->GetStringValue(state, 13);
  9454. string goal4 = lua_interface->GetStringValue(state, 14);
  9455. string task4 = lua_interface->GetStringValue(state, 15);
  9456. if (!player) {
  9457. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9458. return 0;
  9459. }
  9460. if (!player->IsPlayer()) {
  9461. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9462. return 0;
  9463. }
  9464. else
  9465. client = ((Player*)player)->GetClient();
  9466. if (!client) {
  9467. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9468. return 0;
  9469. }
  9470. if (text.length() == 0) {
  9471. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9472. return 0;
  9473. }
  9474. if (duration >= 0 && duration < 2)
  9475. duration = 2;
  9476. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9477. if (packet) {
  9478. packet->setDataByName("open_seconds_max", duration);
  9479. packet->setDataByName("text", text.c_str());
  9480. packet->setDataByName("voice", voice.c_str());
  9481. int8 num_goals = 1;
  9482. if (task2.length() > 0)
  9483. num_goals++;
  9484. if (task3.length() > 0)
  9485. num_goals++;
  9486. if (task4.length() > 0)
  9487. num_goals++;
  9488. packet->setArrayLengthByName("num_goals", num_goals);
  9489. for (int8 i = 0; i < num_goals; i++) {
  9490. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9491. }
  9492. if (goal1.length() > 0)
  9493. packet->setArrayDataByName("goal_text", goal1.c_str());
  9494. if (goal2.length() > 0)
  9495. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9496. if (goal3.length() > 0)
  9497. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9498. if (goal4.length() > 0)
  9499. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9500. packet->setSubArrayDataByName("task_text", task1.c_str());
  9501. if (task2.length() > 0)
  9502. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9503. if (task3.length() > 0)
  9504. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9505. if (task4.length() > 0)
  9506. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9507. packet->setDataByName("complete_sound", "click");
  9508. packet->setDataByName("signal", signal.c_str());
  9509. packet->setDataByName("voice_key1", voice_key1);
  9510. packet->setDataByName("voice_key2", voice_key2);
  9511. client->QueuePacket(packet->serialize());
  9512. safe_delete(packet);
  9513. }
  9514. return 0;
  9515. }
  9516. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9517. if (!lua_interface)
  9518. return 0;
  9519. Client* client = 0;
  9520. Spawn* player = lua_interface->GetSpawn(state);
  9521. string window = lua_interface->GetStringValue(state, 2);
  9522. int8 show = lua_interface->GetInt8Value(state, 3);
  9523. if (!player) {
  9524. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9525. return 0;
  9526. }
  9527. if (!player->IsPlayer()) {
  9528. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9529. return 0;
  9530. }
  9531. else
  9532. client = ((Player*)player)->GetClient();
  9533. if (!client) {
  9534. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9535. return 0;
  9536. }
  9537. if (window.length() == 0) {
  9538. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9539. return 0;
  9540. }
  9541. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9542. if (packet) {
  9543. packet->setDataByName("window", window.c_str());
  9544. packet->setDataByName("show", show);
  9545. client->QueuePacket(packet->serialize());
  9546. safe_delete(packet);
  9547. }
  9548. return 0;
  9549. }
  9550. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9551. //See GameEvents.txt for options that can be used for this function
  9552. if (!lua_interface)
  9553. return 0;
  9554. Client* client = 0;
  9555. Spawn* player = lua_interface->GetSpawn(state);
  9556. string event_name = lua_interface->GetStringValue(state, 2);
  9557. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9558. if (!player || !player->IsPlayer()) {
  9559. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9560. return 0;
  9561. }
  9562. if (player->GetZone())
  9563. client = player->GetZone()->GetClientBySpawn(player);
  9564. if (!client) {
  9565. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9566. return 0;
  9567. }
  9568. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9569. if (packet) {
  9570. packet->setDataByName("event_name", event_name.c_str());
  9571. packet->setDataByName("enabled", enabled);
  9572. client->QueuePacket(packet->serialize());
  9573. safe_delete(packet);
  9574. }
  9575. return 0;
  9576. }
  9577. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9578. if (!lua_interface)
  9579. return 0;
  9580. Spawn* player = lua_interface->GetSpawn(state);
  9581. if (player && player->IsPlayer()) {
  9582. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9583. return 1;
  9584. }
  9585. return 0;
  9586. }
  9587. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9588. if (!lua_interface)
  9589. return 0;
  9590. Spawn* player = lua_interface->GetSpawn(state);
  9591. int8 step = lua_interface->GetInt8Value(state, 2);
  9592. if (player && player->IsPlayer() && step > 0) {
  9593. ((Player*)player)->SetTutorialStep(step);
  9594. }
  9595. return 0;
  9596. }
  9597. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9598. if (!lua_interface)
  9599. return 0;
  9600. Client* client = 0;
  9601. Spawn* player = lua_interface->GetSpawn(state);
  9602. string window = lua_interface->GetStringValue(state, 2);
  9603. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9604. if (!player) {
  9605. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9606. return 0;
  9607. }
  9608. if (!player->IsPlayer()) {
  9609. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9610. return 0;
  9611. }
  9612. else
  9613. client = ((Player*)player)->GetClient();
  9614. if (!client) {
  9615. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9616. return 0;
  9617. }
  9618. if (window.length() == 0) {
  9619. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9620. return 0;
  9621. }
  9622. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9623. if (packet) {
  9624. packet->setDataByName("window", window.c_str());
  9625. packet->setDataByName("flash_seconds", flash_seconds);
  9626. client->QueuePacket(packet->serialize());
  9627. safe_delete(packet);
  9628. }
  9629. return 0;
  9630. }
  9631. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9632. if (!lua_interface)
  9633. return 0;
  9634. Spawn* spawn = lua_interface->GetSpawn(state);
  9635. Spawn* target = lua_interface->GetSpawn(state, 2);
  9636. if (spawn && target)
  9637. return spawn->CheckLoS(target);
  9638. return 0;
  9639. }
  9640. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9641. if (!lua_interface)
  9642. return 0;
  9643. Spawn* spawn = lua_interface->GetSpawn(state);
  9644. float x = lua_interface->GetFloatValue(state, 2);
  9645. float y = lua_interface->GetFloatValue(state, 3);
  9646. float z = lua_interface->GetFloatValue(state, 4);
  9647. if (spawn)
  9648. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9649. return 0;
  9650. }
  9651. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9652. if (!lua_interface)
  9653. return 0;
  9654. ZoneServer* zone = lua_interface->GetZone(state);
  9655. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9656. if (zone)
  9657. zone->SetExpansionFlag(xpackFlag);
  9658. return 0;
  9659. }
  9660. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9661. if (!lua_interface)
  9662. return 0;
  9663. ZoneServer* zone = lua_interface->GetZone(state);
  9664. if (zone) {
  9665. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9666. return 1;
  9667. }
  9668. return 0;
  9669. }
  9670. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9671. if (!lua_interface)
  9672. return 0;
  9673. ZoneServer* zone = lua_interface->GetZone(state);
  9674. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9675. if (zone)
  9676. zone->SetHolidayFlag(holidayFlag);
  9677. return 0;
  9678. }
  9679. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9680. if (!lua_interface)
  9681. return 0;
  9682. ZoneServer* zone = lua_interface->GetZone(state);
  9683. if (zone) {
  9684. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9685. return 1;
  9686. }
  9687. return 0;
  9688. }
  9689. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9690. if (!lua_interface)
  9691. return 0;
  9692. Spawn* spawn = lua_interface->GetSpawn(state);
  9693. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9694. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9695. float distance = lua_interface->GetFloatValue(state, 4);
  9696. string in_range_function = lua_interface->GetStringValue(state, 5);
  9697. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9698. if (spawn && distance > 0 && in_range_function.length() > 0)
  9699. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9700. return 0;
  9701. }
  9702. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9703. if (!lua_interface)
  9704. return 0;
  9705. Spawn* spawn = lua_interface->GetSpawn(state);
  9706. Spawn* target = lua_interface->GetSpawn(state, 2);
  9707. if (spawn && target)
  9708. {
  9709. if (spawn->IsPlayer() && target->IsEntity())
  9710. {
  9711. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9712. return 1;
  9713. }
  9714. else if (spawn->IsEntity() && target->IsEntity())
  9715. {
  9716. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9717. return 1;
  9718. }
  9719. }
  9720. return 0;
  9721. }
  9722. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9723. if (!lua_interface)
  9724. return 0;
  9725. Spawn* spawn = lua_interface->GetSpawn(state);
  9726. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9727. if (spawn && spawn->IsEntity())
  9728. {
  9729. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9730. if (spawn->IsPlayer())
  9731. {
  9732. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9733. if (client)
  9734. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9735. }
  9736. }
  9737. return 0;
  9738. }
  9739. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9740. if (!lua_interface)
  9741. return 0;
  9742. Spawn* spawn = lua_interface->GetSpawn(state);
  9743. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9744. if (spawn && spawn->IsEntity())
  9745. {
  9746. ((Entity*)spawn)->SetSeeHideSpell(val);
  9747. if (spawn->IsPlayer())
  9748. {
  9749. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9750. if (client)
  9751. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9752. }
  9753. }
  9754. return 0;
  9755. }
  9756. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9757. {
  9758. if (!lua_interface)
  9759. return 0;
  9760. Spawn* player = lua_interface->GetSpawn(state);
  9761. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9762. string command = lua_interface->GetStringValue(state, 3);
  9763. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9764. lua_interface->ResetFunctionStack(state);
  9765. if (spawn && player && player->IsPlayer())
  9766. {
  9767. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9768. bool res = false;
  9769. if (cmd)
  9770. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9771. lua_interface->SetBooleanValue(state, res);
  9772. return 1;
  9773. }
  9774. return 0;
  9775. }
  9776. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9777. {
  9778. if (!lua_interface)
  9779. return 0;
  9780. Spawn* spawn = lua_interface->GetSpawn(state);
  9781. int32 charID = lua_interface->GetInt32Value(state, 2);
  9782. string command = lua_interface->GetStringValue(state, 3);
  9783. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9784. lua_interface->ResetFunctionStack(state);
  9785. if (spawn && charID)
  9786. {
  9787. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9788. bool res = false;
  9789. if (cmd)
  9790. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9791. lua_interface->SetBooleanValue(state, res);
  9792. return 1;
  9793. }
  9794. return 0;
  9795. }
  9796. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9797. {
  9798. if (!lua_interface)
  9799. return 0;
  9800. Spawn* spawn = lua_interface->GetSpawn(state);
  9801. string command = lua_interface->GetStringValue(state, 2);
  9802. lua_interface->ResetFunctionStack(state);
  9803. if (spawn && command.length() > 0)
  9804. spawn->RemovePrimaryEntityCommand(command.c_str());
  9805. return 0;
  9806. }
  9807. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9808. if (!lua_interface)
  9809. return 0;
  9810. Spawn* spawn = lua_interface->GetSpawn(state);
  9811. float distance = lua_interface->GetFloatValue(state, 2);
  9812. string command = lua_interface->GetStringValue(state, 3);
  9813. Spawn* player = lua_interface->GetSpawn(state, 4);
  9814. lua_interface->ResetFunctionStack(state);
  9815. if (spawn) {
  9816. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9817. }
  9818. return 0;
  9819. }
  9820. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9821. if (!lua_interface)
  9822. return 0;
  9823. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9824. Spawn* spawn = lua_interface->GetSpawn(state);
  9825. Spawn* player = lua_interface->GetSpawn(state, 2);
  9826. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9827. lua_interface->ResetFunctionStack(state);
  9828. if (spawn && player && transport_id && player->IsPlayer()) {
  9829. Client* client = 0;
  9830. if (player && player->IsPlayer())
  9831. client = player->GetZone()->GetClientBySpawn(player);
  9832. if (!client)
  9833. return 0;
  9834. vector<TransportDestination*> destinations;
  9835. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9836. if (destinations.size())
  9837. {
  9838. client->SetTemporaryTransportID(transport_id);
  9839. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9840. }
  9841. else
  9842. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9843. }
  9844. return 0;
  9845. }
  9846. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9847. if (!lua_interface)
  9848. return 0;
  9849. Spawn* player = lua_interface->GetSpawn(state);
  9850. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9851. lua_interface->ResetFunctionStack(state);
  9852. if (player && player->IsPlayer()) {
  9853. Client* client = 0;
  9854. if (player && player->IsPlayer())
  9855. client = player->GetZone()->GetClientBySpawn(player);
  9856. if (!client)
  9857. return 0;
  9858. client->SetTemporaryTransportID(transport_id);
  9859. }
  9860. return 0;
  9861. }
  9862. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9863. if (!lua_interface)
  9864. return 0;
  9865. Spawn* player = lua_interface->GetSpawn(state);
  9866. lua_interface->ResetFunctionStack(state);
  9867. if (player && player->IsPlayer()) {
  9868. Client* client = 0;
  9869. if (player && player->IsPlayer())
  9870. client = player->GetZone()->GetClientBySpawn(player);
  9871. if (!client)
  9872. return 0;
  9873. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9874. return 1;
  9875. }
  9876. return 0;
  9877. }
  9878. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9879. if (!lua_interface)
  9880. return 0;
  9881. Spawn* spawn = lua_interface->GetSpawn(state);
  9882. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9883. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9884. if (!spawn) {
  9885. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9886. return 0;
  9887. }
  9888. if (!spawn->IsEntity()) {
  9889. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9890. return 0;
  9891. }
  9892. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9893. {
  9894. 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);
  9895. return 0;
  9896. }
  9897. lua_interface->ResetFunctionStack(state);
  9898. if (spell && spell->targets.size() > 0) {
  9899. ZoneServer* zone = spell->caster->GetZone();
  9900. for (int8 i = 0; i < spell->targets.size(); i++) {
  9901. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9902. if (target && target->IsEntity()) {
  9903. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9904. if (target->IsPlayer())
  9905. ((Player*)target)->SetCharSheetChanged(true);
  9906. }
  9907. }
  9908. }
  9909. else {
  9910. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9911. if (spawn->IsPlayer())
  9912. ((Player*)spawn)->SetCharSheetChanged(true);
  9913. }
  9914. return 0;
  9915. }
  9916. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9917. if (!lua_interface)
  9918. return 0;
  9919. Spawn* spawn = lua_interface->GetSpawn(state);
  9920. lua_interface->ResetFunctionStack(state);
  9921. if (!spawn) {
  9922. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9923. return 0;
  9924. }
  9925. if (!spawn->IsEntity()) {
  9926. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9927. return 0;
  9928. }
  9929. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9930. return 1;
  9931. }
  9932. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9933. if (!lua_interface)
  9934. return 0;
  9935. int32 spell_id = lua_interface->GetInt32Value(state);
  9936. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9937. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9938. if (spell_id > 0) {
  9939. if (spell_tier == 0)
  9940. spell_tier = 1;
  9941. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9942. LuaSpell* lua_spell = 0;
  9943. if(custom_lua_script.size() > 0)
  9944. {
  9945. // attempt to load the custom script since it isn't already loaded
  9946. // we will re-obtain the lua_spell further below
  9947. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9948. {
  9949. 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());
  9950. lua_interface->LoadLuaSpell(custom_lua_script);
  9951. }
  9952. }
  9953. else
  9954. custom_lua_script = spell->GetSpellData()->lua_script;
  9955. if (!lua_spell && lua_interface)
  9956. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9957. if (!lua_spell)
  9958. {
  9959. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9960. return 0;
  9961. }
  9962. lua_spell->spell = new Spell(spell);
  9963. lua_interface->AddCustomSpell(lua_spell);
  9964. lua_interface->SetSpellValue(state, lua_spell);
  9965. return 1;
  9966. }
  9967. return 0;
  9968. }
  9969. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9970. if (!lua_interface)
  9971. return 0;
  9972. LuaSpell* spell = lua_interface->GetSpell(state);
  9973. string field = lua_interface->GetStringValue(state, 2);
  9974. if (!spell) {
  9975. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9976. return 0;
  9977. }
  9978. if (!spell->spell || !spell->spell->GetSpellData()) {
  9979. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9980. return 0;
  9981. }
  9982. boost::to_lower(field);
  9983. return spell->spell->GetSpellData(state, field);
  9984. }
  9985. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9986. if (!lua_interface)
  9987. return 0;
  9988. LuaSpell* spell = lua_interface->GetSpell(state);
  9989. string field = lua_interface->GetStringValue(state, 2);
  9990. int8 fieldArg = 3; // field value after the initial set
  9991. if (!spell) {
  9992. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9993. return 0;
  9994. }
  9995. if (!spell->spell || !spell->spell->GetSpellData()) {
  9996. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9997. return 0;
  9998. }
  9999. boost::to_lower(field);
  10000. bool valSet = false;
  10001. spell->spell->SetSpellData(state, field, fieldArg);
  10002. return valSet;
  10003. }
  10004. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10005. if (!lua_interface)
  10006. return 0;
  10007. LuaSpell* spell = lua_interface->GetSpell(state);
  10008. int8 idx = lua_interface->GetInt32Value(state, 2);
  10009. if (!spell) {
  10010. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10011. return 0;
  10012. }
  10013. if (!spell->spell || !spell->spell->GetSpellData()) {
  10014. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10015. return 0;
  10016. }
  10017. if (spell->spell->lua_data.size() <= idx)
  10018. {
  10019. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10020. return 0;
  10021. }
  10022. bool setVal = true;
  10023. LUAData* data = spell->spell->lua_data[idx];
  10024. switch (data->type)
  10025. {
  10026. case 0:
  10027. {
  10028. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10029. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10030. data->int_value = value;
  10031. data->int_value2 = value2;
  10032. break;
  10033. }
  10034. case 1:
  10035. {
  10036. float value = lua_interface->GetFloatValue(state, 3);
  10037. float value2 = lua_interface->GetFloatValue(state, 4);
  10038. data->float_value = value;
  10039. data->float_value2 = value2;
  10040. break;
  10041. }
  10042. case 2:
  10043. {
  10044. bool value = lua_interface->GetBooleanValue(state, 3);
  10045. data->bool_value = value;
  10046. break;
  10047. }
  10048. case 3:
  10049. {
  10050. string value = lua_interface->GetStringValue(state, 3);
  10051. string value2 = lua_interface->GetStringValue(state, 4);
  10052. data->string_value = value;
  10053. data->string_value2 = value2;
  10054. break;
  10055. }
  10056. default:
  10057. setVal = false;
  10058. }
  10059. return setVal;
  10060. }
  10061. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10062. if (!lua_interface)
  10063. return 0;
  10064. LuaSpell* spell = lua_interface->GetSpell(state);
  10065. int8 idx = lua_interface->GetInt32Value(state, 2);
  10066. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10067. if (!spell) {
  10068. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10069. return 0;
  10070. }
  10071. if (!spell->spell || !spell->spell->GetSpellData()) {
  10072. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10073. return 0;
  10074. }
  10075. if (spell->spell->lua_data.size() <= idx)
  10076. {
  10077. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10078. return 0;
  10079. }
  10080. bool setVal = true;
  10081. LUAData* data = spell->spell->lua_data[idx];
  10082. switch (data->type)
  10083. {
  10084. case 0:
  10085. {
  10086. if(!secondfield)
  10087. lua_interface->SetSInt32Value(state, data->int_value);
  10088. else
  10089. lua_interface->SetSInt32Value(state, data->int_value2);
  10090. break;
  10091. }
  10092. case 1:
  10093. {
  10094. if (!secondfield)
  10095. lua_interface->SetFloatValue(state, data->float_value);
  10096. else
  10097. lua_interface->SetFloatValue(state, data->float_value2);
  10098. break;
  10099. }
  10100. case 2:
  10101. {
  10102. lua_interface->SetBooleanValue(state, data->bool_value);
  10103. break;
  10104. }
  10105. case 3:
  10106. {
  10107. if (!secondfield)
  10108. lua_interface->SetStringValue(state, data->string_value.c_str());
  10109. else
  10110. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10111. break;
  10112. }
  10113. default:
  10114. setVal = false;
  10115. }
  10116. return setVal;
  10117. }
  10118. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10119. if (!lua_interface)
  10120. return 0;
  10121. LuaSpell* spell = lua_interface->GetSpell(state);
  10122. int8 idx = lua_interface->GetInt32Value(state, 2);
  10123. string field = lua_interface->GetStringValue(state, 3);
  10124. boost::to_lower(field);
  10125. if (!spell) {
  10126. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10127. return 0;
  10128. }
  10129. if (!spell->spell || !spell->spell->GetSpellData()) {
  10130. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10131. return 0;
  10132. }
  10133. if (spell->spell->effects.size() <= idx)
  10134. {
  10135. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10136. return 0;
  10137. }
  10138. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10139. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10140. if (field == "description")
  10141. effect->description = string(lua_interface->GetStringValue(state, 4));
  10142. else if (field == "bullet")
  10143. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10144. else if (field == "percentage")
  10145. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10146. else // no match
  10147. return 0;
  10148. return 1;
  10149. }
  10150. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10151. if (!lua_interface)
  10152. return 0;
  10153. LuaSpell* spell = lua_interface->GetSpell(state);
  10154. int8 idx = lua_interface->GetInt32Value(state, 2);
  10155. string field = lua_interface->GetStringValue(state, 3);
  10156. boost::to_lower(field);
  10157. if (!spell) {
  10158. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10159. return 0;
  10160. }
  10161. if (!spell->spell || !spell->spell->GetSpellData()) {
  10162. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10163. return 0;
  10164. }
  10165. if (spell->spell->effects.size() <= idx)
  10166. {
  10167. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10168. return 0;
  10169. }
  10170. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10171. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10172. if (field == "description")
  10173. lua_interface->SetStringValue(state, effect->description.c_str());
  10174. else if (field == "bullet")
  10175. lua_interface->SetInt32Value(state, effect->subbullet);
  10176. else if (field == "percentage")
  10177. lua_interface->SetInt32Value(state, effect->percentage);
  10178. else // no match
  10179. return 0;
  10180. return 1;
  10181. }
  10182. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10183. if (!lua_interface)
  10184. return 0;
  10185. LuaSpell* spell = lua_interface->GetSpell(state);
  10186. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10187. Spawn* target = lua_interface->GetSpawn(state, 3);
  10188. if (!target) {
  10189. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10190. return 0;
  10191. }
  10192. if (!target->IsEntity()) {
  10193. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10194. return 0;
  10195. }
  10196. if (!spell) {
  10197. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10198. return 0;
  10199. }
  10200. if (caster && !caster->IsEntity()) {
  10201. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10202. return 0;
  10203. }
  10204. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10205. return 0;
  10206. }
  10207. int EQ2Emu_lua_InWater(lua_State* state) {
  10208. if (!lua_interface)
  10209. return 0;
  10210. Spawn* spawn = lua_interface->GetSpawn(state);
  10211. lua_interface->ResetFunctionStack(state);
  10212. if (spawn) {
  10213. lua_interface->SetBooleanValue(state, spawn->InWater());
  10214. return 1;
  10215. }
  10216. return 0;
  10217. }
  10218. int EQ2Emu_lua_InLava(lua_State* state) {
  10219. if (!lua_interface)
  10220. return 0;
  10221. Spawn* spawn = lua_interface->GetSpawn(state);
  10222. lua_interface->ResetFunctionStack(state);
  10223. if (spawn) {
  10224. lua_interface->SetBooleanValue(state, spawn->InLava());
  10225. return 1;
  10226. }
  10227. return 0;
  10228. }
  10229. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10230. if (!lua_interface)
  10231. return 0;
  10232. Spawn* attacker = lua_interface->GetSpawn(state);
  10233. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10234. int8 type = lua_interface->GetInt8Value(state, 3);
  10235. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10236. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10237. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10238. string spell_name = lua_interface->GetStringValue(state, 7);
  10239. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10240. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10241. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10242. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10243. lua_interface->ResetFunctionStack(state);
  10244. if (!attacker) {
  10245. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10246. return 0;
  10247. }
  10248. if (!attacker->IsEntity()) {
  10249. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10250. return 0;
  10251. }
  10252. if (!victim) {
  10253. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10254. return 0;
  10255. }
  10256. if (!victim->IsEntity()) {
  10257. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10258. return 0;
  10259. }
  10260. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10261. return 0;
  10262. }
  10263. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10264. if (!lua_interface)
  10265. return 0;
  10266. Spawn* spawn = lua_interface->GetSpawn(state);
  10267. lua_interface->ResetFunctionStack(state);
  10268. if (spawn) {
  10269. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10270. return 1;
  10271. }
  10272. return 0;
  10273. }
  10274. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10275. if (!lua_interface)
  10276. return 0;
  10277. Spawn* spawn = lua_interface->GetSpawn(state);
  10278. bool invul = lua_interface->GetBooleanValue(state, 2);
  10279. lua_interface->ResetFunctionStack(state);
  10280. if (spawn) {
  10281. spawn->SetInvulnerable(invul);
  10282. }
  10283. return 0;
  10284. }
  10285. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10286. if (!lua_interface)
  10287. return 0;
  10288. string category = lua_interface->GetStringValue(state);
  10289. string name = lua_interface->GetStringValue(state, 2);
  10290. lua_interface->ResetFunctionStack(state);
  10291. Rule *ret = 0;
  10292. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10293. lua_interface->SetBooleanValue(state, ret->GetBool());
  10294. return 1;
  10295. }
  10296. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10297. return 0;
  10298. }
  10299. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10300. if (!lua_interface)
  10301. return 0;
  10302. string category = lua_interface->GetStringValue(state);
  10303. string name = lua_interface->GetStringValue(state, 2);
  10304. lua_interface->ResetFunctionStack(state);
  10305. Rule *ret = 0;
  10306. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10307. lua_interface->SetInt32Value(state, ret->GetInt32());
  10308. return 1;
  10309. }
  10310. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10311. return 0;
  10312. }
  10313. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10314. if (!lua_interface)
  10315. return 0;
  10316. string category = lua_interface->GetStringValue(state);
  10317. string name = lua_interface->GetStringValue(state, 2);
  10318. lua_interface->ResetFunctionStack(state);
  10319. Rule *ret = 0;
  10320. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10321. lua_interface->SetFloatValue(state, ret->GetFloat());
  10322. return 1;
  10323. }
  10324. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10325. return 0;
  10326. }
  10327. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10328. if (!lua_interface)
  10329. return 0;
  10330. Spawn* spawn = lua_interface->GetSpawn(state);
  10331. string type = lua_interface->GetStringValue(state, 2);
  10332. lua_interface->ResetFunctionStack(state);
  10333. if (spawn) {
  10334. int res = 1;
  10335. boost::to_lower(type);
  10336. if(type == "assigned_aa")
  10337. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10338. else if ( type == "unassigned_aa")
  10339. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10340. else if ( type == "assigned_tradeskill_aa")
  10341. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10342. else if ( type == "unassigned_tradeskill_aa")
  10343. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10344. else if ( type == "assigned_prestige_aa")
  10345. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10346. else if ( type == "unassigned_prestige_aa")
  10347. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10348. else if ( type == "assigned_tradeskill_prestige_aa")
  10349. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10350. else if ( type == "unassigned_tradeskill_prestige_aa")
  10351. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10352. else
  10353. res = 0;
  10354. return res;
  10355. }
  10356. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10357. return 0;
  10358. }
  10359. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10360. if (!lua_interface)
  10361. return 0;
  10362. Spawn* spawn = lua_interface->GetSpawn(state);
  10363. string type = lua_interface->GetStringValue(state, 2);
  10364. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10365. lua_interface->ResetFunctionStack(state);
  10366. if (spawn) {
  10367. boost::to_lower(type);
  10368. if(type == "assigned_aa")
  10369. spawn->SetAssignedAA((sint16)value);
  10370. else if ( type == "unassigned_aa")
  10371. spawn->SetUnassignedAA((sint16)value);
  10372. else if ( type == "assigned_tradeskill_aa")
  10373. spawn->SetTradeskillAA((sint16)value);
  10374. else if ( type == "unassigned_tradeskill_aa")
  10375. spawn->SetUnassignedTradeskillAA((sint16)value);
  10376. else if ( type == "assigned_prestige_aa")
  10377. spawn->SetPrestigeAA((sint16)value);
  10378. else if ( type == "unassigned_prestige_aa")
  10379. spawn->SetUnassignedPrestigeAA((sint16)value);
  10380. else if ( type == "assigned_tradeskill_prestige_aa")
  10381. spawn->SetTradeskillPrestigeAA((sint16)value);
  10382. else if ( type == "unassigned_tradeskill_prestige_aa")
  10383. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10384. if(spawn->IsPlayer())
  10385. ((Player*)spawn)->SetCharSheetChanged(true);
  10386. }
  10387. return 0;
  10388. }
  10389. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10390. if (!lua_interface)
  10391. return 0;
  10392. string titleName = lua_interface->GetStringValue(state);
  10393. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10394. lua_interface->ResetFunctionStack(state);
  10395. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10396. lua_interface->SetSInt32Value(state, index);
  10397. return 1;
  10398. }
  10399. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10400. if (!lua_interface)
  10401. return 0;
  10402. Spawn* spawn = lua_interface->GetSpawn(state);
  10403. string titleName = lua_interface->GetStringValue(state, 2);
  10404. lua_interface->ResetFunctionStack(state);
  10405. if(!spawn->IsPlayer())
  10406. {
  10407. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10408. lua_interface->SetSInt32Value(state, -1);
  10409. return 1;
  10410. }
  10411. Player* player = (Player*)spawn;
  10412. // check if player already has the title, don't need to add twice
  10413. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10414. if ( playerHasTitle)
  10415. {
  10416. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10417. return 1;
  10418. }
  10419. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10420. if(!title)
  10421. {
  10422. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10423. lua_interface->SetSInt32Value(state, -1);
  10424. return 1;
  10425. }
  10426. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10427. if(returnIdx < 0)
  10428. {
  10429. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10430. }
  10431. lua_interface->SetSInt32Value(state, returnIdx);
  10432. player->GetClient()->SendTitleUpdate();
  10433. return 1;
  10434. }
  10435. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10436. if (!lua_interface)
  10437. return 0;
  10438. Spawn* spawn = lua_interface->GetSpawn(state);
  10439. string titleName = lua_interface->GetStringValue(state, 2);
  10440. lua_interface->ResetFunctionStack(state);
  10441. if(!spawn->IsPlayer())
  10442. {
  10443. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10444. return 0;
  10445. }
  10446. Player* player = (Player*)spawn;
  10447. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10448. if(!title)
  10449. {
  10450. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10451. return 0;
  10452. }
  10453. if(title->GetPrefix())
  10454. {
  10455. 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());
  10456. return 0;
  10457. }
  10458. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10459. player->GetClient()->SendTitleUpdate();
  10460. return 1;
  10461. }
  10462. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10463. if (!lua_interface)
  10464. return 0;
  10465. Spawn* spawn = lua_interface->GetSpawn(state);
  10466. string titleName = lua_interface->GetStringValue(state, 2);
  10467. lua_interface->ResetFunctionStack(state);
  10468. if(!spawn->IsPlayer())
  10469. {
  10470. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10471. return 0;
  10472. }
  10473. Player* player = (Player*)spawn;
  10474. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10475. if(!title)
  10476. {
  10477. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10478. return 0;
  10479. }
  10480. if(!title->GetPrefix())
  10481. {
  10482. 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());
  10483. return 0;
  10484. }
  10485. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10486. player->GetClient()->SendTitleUpdate();
  10487. return 1;
  10488. }
  10489. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10490. if (!lua_interface)
  10491. return 0;
  10492. Spawn* spawn = lua_interface->GetSpawn(state);
  10493. lua_interface->ResetFunctionStack(state);
  10494. if(!spawn->IsPlayer())
  10495. {
  10496. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10497. return 0;
  10498. }
  10499. Player* player = (Player*)spawn;
  10500. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10501. player->GetClient()->SendTitleUpdate();
  10502. return 1;
  10503. }
  10504. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10505. if (!lua_interface)
  10506. return 0;
  10507. Spawn* spawn = lua_interface->GetSpawn(state);
  10508. lua_interface->ResetFunctionStack(state);
  10509. if(!spawn->IsPlayer())
  10510. {
  10511. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10512. return 0;
  10513. }
  10514. Player* player = (Player*)spawn;
  10515. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10516. player->GetClient()->SendTitleUpdate();
  10517. return 1;
  10518. }
  10519. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10520. if (!lua_interface)
  10521. return 0;
  10522. Spawn* spawn = lua_interface->GetSpawn(state);
  10523. string field = lua_interface->GetStringValue(state, 2);
  10524. lua_interface->ResetFunctionStack(state);
  10525. if(!spawn || !spawn->IsEntity())
  10526. {
  10527. 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));
  10528. return 0;
  10529. }
  10530. Entity* ent = (Entity*)spawn;
  10531. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10532. return 1;
  10533. }
  10534. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10535. if (!lua_interface)
  10536. return 0;
  10537. Spawn* spawn = lua_interface->GetSpawn(state);
  10538. string field = lua_interface->GetStringValue(state, 2);
  10539. lua_interface->ResetFunctionStack(state);
  10540. if(!spawn || !spawn->IsEntity())
  10541. {
  10542. 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));
  10543. return 0;
  10544. }
  10545. Entity* ent = (Entity*)spawn;
  10546. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10547. return 1;
  10548. }
  10549. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10550. if (!lua_interface)
  10551. return 0;
  10552. Spawn* spawn = lua_interface->GetSpawn(state);
  10553. string field = lua_interface->GetStringValue(state, 2);
  10554. lua_interface->ResetFunctionStack(state);
  10555. if(!spawn || !spawn->IsEntity())
  10556. {
  10557. 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));
  10558. return 0;
  10559. }
  10560. Entity* ent = (Entity*)spawn;
  10561. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10562. return 1;
  10563. }
  10564. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10565. if (!lua_interface)
  10566. return 0;
  10567. Spawn* spawn = lua_interface->GetSpawn(state);
  10568. string field = lua_interface->GetStringValue(state, 2);
  10569. lua_interface->ResetFunctionStack(state);
  10570. if(!spawn || !spawn->IsEntity())
  10571. {
  10572. 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));
  10573. return 0;
  10574. }
  10575. Entity* ent = (Entity*)spawn;
  10576. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10577. return 1;
  10578. }
  10579. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10580. if (!lua_interface)
  10581. return 0;
  10582. Spawn* spawn = lua_interface->GetSpawn(state);
  10583. string field = lua_interface->GetStringValue(state, 2);
  10584. string value = lua_interface->GetStringValue(state, 3);
  10585. lua_interface->ResetFunctionStack(state);
  10586. if(!spawn || !spawn->IsEntity())
  10587. {
  10588. 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));
  10589. return 0;
  10590. }
  10591. Entity* ent = (Entity*)spawn;
  10592. bool set_ = ent->SetInfoStructString(field, value);
  10593. lua_interface->SetBooleanValue(state, set_);
  10594. return 1;
  10595. }
  10596. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10597. if (!lua_interface)
  10598. return 0;
  10599. Spawn* spawn = lua_interface->GetSpawn(state);
  10600. string field = lua_interface->GetStringValue(state, 2);
  10601. int64 value = lua_interface->GetInt64Value(state, 3);
  10602. lua_interface->ResetFunctionStack(state);
  10603. if(!spawn || !spawn->IsEntity())
  10604. {
  10605. 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));
  10606. return 0;
  10607. }
  10608. Entity* ent = (Entity*)spawn;
  10609. bool set_ = ent->SetInfoStructUInt(field, value);
  10610. lua_interface->SetBooleanValue(state, set_);
  10611. return 1;
  10612. }
  10613. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10614. if (!lua_interface)
  10615. return 0;
  10616. Spawn* spawn = lua_interface->GetSpawn(state);
  10617. string field = lua_interface->GetStringValue(state, 2);
  10618. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10619. lua_interface->ResetFunctionStack(state);
  10620. if(!spawn || !spawn->IsEntity())
  10621. {
  10622. 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));
  10623. return 0;
  10624. }
  10625. Entity* ent = (Entity*)spawn;
  10626. bool set_ = ent->SetInfoStructSInt(field, value);
  10627. lua_interface->SetBooleanValue(state, set_);
  10628. return 1;
  10629. }
  10630. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10631. if (!lua_interface)
  10632. return 0;
  10633. Spawn* spawn = lua_interface->GetSpawn(state);
  10634. string field = lua_interface->GetStringValue(state, 2);
  10635. float value = lua_interface->GetFloatValue(state, 3);
  10636. lua_interface->ResetFunctionStack(state);
  10637. if(!spawn || !spawn->IsEntity())
  10638. {
  10639. 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));
  10640. return 0;
  10641. }
  10642. Entity* ent = (Entity*)spawn;
  10643. bool set_ = ent->SetInfoStructFloat(field, value);
  10644. lua_interface->SetBooleanValue(state, set_);
  10645. return 1;
  10646. }
  10647. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10648. if (!lua_interface)
  10649. return 0;
  10650. Spawn* spawn = lua_interface->GetSpawn(state);
  10651. bool value = lua_interface->GetBooleanValue(state, 2);
  10652. lua_interface->ResetFunctionStack(state);
  10653. if(!spawn || !spawn->IsPlayer())
  10654. {
  10655. 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));
  10656. return 0;
  10657. }
  10658. ((Player*)spawn)->SetCharSheetChanged(value);
  10659. return 0;
  10660. }
  10661. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10662. if (!lua_interface)
  10663. return 0;
  10664. Spawn* spawn = lua_interface->GetSpawn(state);
  10665. std::string fromName = lua_interface->GetStringValue(state, 2);
  10666. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10667. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10668. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10669. int32 copper = lua_interface->GetInt32Value(state, 6);
  10670. int32 silver = lua_interface->GetInt32Value(state, 7);
  10671. int32 gold = lua_interface->GetInt32Value(state, 8);
  10672. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10673. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10674. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10675. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10676. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10677. lua_interface->ResetFunctionStack(state);
  10678. if(!spawn || !spawn->IsPlayer())
  10679. {
  10680. 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));
  10681. lua_interface->SetBooleanValue(state, false);
  10682. return 1;
  10683. }
  10684. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10685. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10686. lua_interface->SetBooleanValue(state, true);
  10687. return 1;
  10688. }
  10689. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10690. if (!lua_interface)
  10691. return 0;
  10692. int32 char_id = lua_interface->GetInt32Value(state);
  10693. std::string fromName = lua_interface->GetStringValue(state, 2);
  10694. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10695. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10696. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10697. int32 copper = lua_interface->GetInt32Value(state, 6);
  10698. int32 silver = lua_interface->GetInt32Value(state, 7);
  10699. int32 gold = lua_interface->GetInt32Value(state, 8);
  10700. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10701. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10702. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10703. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10704. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10705. lua_interface->ResetFunctionStack(state);
  10706. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10707. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10708. lua_interface->SetBooleanValue(state, true);
  10709. return 1;
  10710. }
  10711. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10712. Spawn* widget;
  10713. if (lua_interface) {
  10714. widget = lua_interface->GetSpawn(state);
  10715. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10716. lua_interface->ResetFunctionStack(state);
  10717. if (widget && widget->IsWidget())
  10718. {
  10719. ((Widget*)widget)->OpenDoor();
  10720. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10721. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10722. }
  10723. else
  10724. 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));
  10725. }
  10726. return 0;
  10727. }
  10728. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10729. Spawn* widget;
  10730. if (lua_interface) {
  10731. widget = lua_interface->GetSpawn(state);
  10732. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10733. lua_interface->ResetFunctionStack(state);
  10734. if (widget && widget->IsWidget())
  10735. {
  10736. ((Widget*)widget)->CloseDoor();
  10737. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10738. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10739. }
  10740. else
  10741. 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));
  10742. }
  10743. return 0;
  10744. }
  10745. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10746. if (!lua_interface)
  10747. return 0;
  10748. Spawn* widget = lua_interface->GetSpawn(state);
  10749. lua_interface->ResetFunctionStack(state);
  10750. if (widget && widget->IsWidget())
  10751. {
  10752. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10753. return 1;
  10754. }
  10755. return 0;
  10756. }
  10757. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10758. if (!lua_interface)
  10759. return 0;
  10760. sint32 min = lua_interface->GetSInt32Value(state);
  10761. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10762. lua_interface->ResetFunctionStack(state);
  10763. sint32 result = MakeRandomInt(min, max);
  10764. lua_interface->SetSInt32Value(state, result);
  10765. return 1;
  10766. }
  10767. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10768. if (!lua_interface)
  10769. return 0;
  10770. float min = lua_interface->GetFloatValue(state);
  10771. float max = lua_interface->GetFloatValue(state, 2);
  10772. lua_interface->ResetFunctionStack(state);
  10773. float result = MakeRandomFloat(min, max);
  10774. lua_interface->SetFloatValue(state, result);
  10775. return 1;
  10776. }
  10777. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10778. if (!lua_interface)
  10779. return 0;
  10780. Spawn* spawn = lua_interface->GetSpawn(state);
  10781. int32 value = lua_interface->GetInt32Value(state, 2);
  10782. lua_interface->ResetFunctionStack(state);
  10783. if(!spawn)
  10784. {
  10785. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10786. lua_interface->SetBooleanValue(state, false);
  10787. return 1;
  10788. }
  10789. spawn->AddIconValue(value);
  10790. lua_interface->SetBooleanValue(state, true);
  10791. return 1;
  10792. }
  10793. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10794. if (!lua_interface)
  10795. return 0;
  10796. Spawn* spawn = lua_interface->GetSpawn(state);
  10797. int32 value = lua_interface->GetInt32Value(state, 2);
  10798. lua_interface->ResetFunctionStack(state);
  10799. if(!spawn)
  10800. {
  10801. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10802. lua_interface->SetBooleanValue(state, false);
  10803. return 1;
  10804. }
  10805. spawn->RemoveIconValue(value);
  10806. lua_interface->SetBooleanValue(state, true);
  10807. return 1;
  10808. }
  10809. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10810. Spawn* npc = lua_interface->GetSpawn(state);
  10811. lua_interface->ResetFunctionStack(state);
  10812. if (npc && npc->IsNPC()) {
  10813. NPC* shard = (NPC*)npc;
  10814. int32 shardid = shard->GetShardID();
  10815. lua_interface->SetInt32Value(state, shardid);
  10816. return 1;
  10817. }
  10818. lua_interface->SetInt32Value(state, 0);
  10819. return 1;
  10820. }
  10821. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10822. Spawn* npc = lua_interface->GetSpawn(state);
  10823. lua_interface->ResetFunctionStack(state);
  10824. if (npc && npc->IsNPC()) {
  10825. NPC* shard = (NPC*)npc;
  10826. int32 charid = shard->GetShardCharID();
  10827. lua_interface->SetInt32Value(state, charid);
  10828. return 1;
  10829. }
  10830. lua_interface->SetInt32Value(state, 0);
  10831. return 1;
  10832. }
  10833. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10834. Spawn* npc = lua_interface->GetSpawn(state);
  10835. lua_interface->ResetFunctionStack(state);
  10836. if (npc && npc->IsNPC()) {
  10837. NPC* shard = (NPC*)npc;
  10838. int64 timestamp = shard->GetShardCreatedTimestamp();
  10839. lua_interface->SetSInt64Value(state, timestamp);
  10840. return 1;
  10841. }
  10842. lua_interface->SetSInt64Value(state, 0);
  10843. return 1;
  10844. }
  10845. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10846. if (!lua_interface)
  10847. return 0;
  10848. int32 shardid = lua_interface->GetInt32Value(state);
  10849. lua_interface->ResetFunctionStack(state);
  10850. if(shardid < 1)
  10851. lua_interface->SetBooleanValue(state, false);
  10852. else
  10853. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10854. return 1;
  10855. }
  10856. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10857. if (!lua_interface)
  10858. return 0;
  10859. Spawn* spawn = lua_interface->GetSpawn(state);
  10860. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10861. if (spawn) {
  10862. spawn->PauseMovement(delay_in_ms);
  10863. }
  10864. lua_interface->ResetFunctionStack(state);
  10865. return 0;
  10866. }
  10867. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10868. if (!lua_interface)
  10869. return 0;
  10870. Spawn* spawn = lua_interface->GetSpawn(state);
  10871. if (spawn) {
  10872. spawn->StopMovement();
  10873. }
  10874. lua_interface->ResetFunctionStack(state);
  10875. return 0;
  10876. }
  10877. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10878. Player* player = (Player*)lua_interface->GetSpawn(state);
  10879. int8 level = lua_interface->GetInt8Value(state, 2);
  10880. lua_interface->ResetFunctionStack(state);
  10881. if (player && player->IsPlayer() && level > 0) {
  10882. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10883. return 1;
  10884. }
  10885. return 0;
  10886. }
  10887. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10888. Player* player = (Player*)lua_interface->GetSpawn(state);
  10889. int8 level = lua_interface->GetInt8Value(state, 2);
  10890. lua_interface->ResetFunctionStack(state);
  10891. if (player && player->IsPlayer() && level > 0) {
  10892. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10893. return 1;
  10894. }
  10895. return 0;
  10896. }
  10897. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10898. ZoneServer* zone = lua_interface->GetZone(state);
  10899. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10900. lua_interface->ResetFunctionStack(state);
  10901. if (zone) {
  10902. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10903. if (spawn) {
  10904. lua_interface->SetSpawnValue(state, spawn);
  10905. return 1;
  10906. }
  10907. }
  10908. return 0;
  10909. }
  10910. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10911. if (!lua_interface)
  10912. return 0;
  10913. Spawn* spawn = lua_interface->GetSpawn(state);
  10914. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10915. lua_interface->ResetFunctionStack(state);
  10916. bool res = false;
  10917. if(spawn && spawn->IsTransportSpawn())
  10918. {
  10919. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10920. spawn->SetRailID(rail_id);
  10921. res = true;
  10922. }
  10923. else if (!spawn) {
  10924. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10925. }
  10926. else if(!spawn->IsTransportSpawn()) {
  10927. 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());
  10928. }
  10929. lua_interface->SetBooleanValue(state, res);
  10930. return 1;
  10931. }
  10932. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10933. if (!lua_interface)
  10934. return 0;
  10935. ZoneServer* zone = lua_interface->GetZone(state);
  10936. lua_interface->ResetFunctionStack(state);
  10937. if (zone) {
  10938. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10939. return 1;
  10940. }
  10941. return 0;
  10942. }
  10943. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10944. if (!lua_interface)
  10945. return 0;
  10946. Spawn* spawn = lua_interface->GetSpawn(state);
  10947. lua_interface->ResetFunctionStack(state);
  10948. if (spawn) {
  10949. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10950. return 1;
  10951. }
  10952. return 0;
  10953. }
  10954. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10955. if (!lua_interface)
  10956. return 0;
  10957. Spawn* player = lua_interface->GetSpawn(state);
  10958. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10959. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10960. lua_interface->ResetFunctionStack(state);
  10961. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10962. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10963. }
  10964. else if(!zoneID) {
  10965. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10966. }
  10967. else
  10968. {
  10969. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10970. return 1;
  10971. }
  10972. return 0;
  10973. }
  10974. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10975. if (!lua_interface)
  10976. return 0;
  10977. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10978. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10979. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10980. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10981. lua_interface->ResetFunctionStack(state);
  10982. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10983. world.GetWorldTimeStruct()->year = newYear;
  10984. world.GetWorldTimeStruct()->month = newMonth;
  10985. world.GetWorldTimeStruct()->hour = newHour;
  10986. world.GetWorldTimeStruct()->minute = newMinute;
  10987. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10988. return 0;
  10989. }
  10990. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10991. if (!lua_interface)
  10992. return 0;
  10993. lua_interface->ResetFunctionStack(state);
  10994. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10995. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10996. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10997. return 1;
  10998. }
  10999. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11000. if (!lua_interface)
  11001. return 0;
  11002. lua_interface->ResetFunctionStack(state);
  11003. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11004. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11005. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11006. return 1;
  11007. }
  11008. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11009. if (!lua_interface)
  11010. return 0;
  11011. lua_interface->ResetFunctionStack(state);
  11012. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11013. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11014. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11015. return 1;
  11016. }
  11017. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11018. if (!lua_interface)
  11019. return 0;
  11020. lua_interface->ResetFunctionStack(state);
  11021. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11022. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11023. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11024. return 1;
  11025. }
  11026. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11027. if (!lua_interface)
  11028. return 0;
  11029. lua_interface->ResetFunctionStack(state);
  11030. world.SendTimeUpdate();
  11031. return 0;
  11032. }