LuaFunctions.cpp 425 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id, true, false, false);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1609. ZoneServer* zone = lua_interface->GetZone(state);
  1610. Spawn* player = lua_interface->GetSpawn(state, 2);
  1611. Client* client = 0;
  1612. if (player && player->IsPlayer())
  1613. client = ((Player*)player)->GetClient();
  1614. float x = lua_interface->GetFloatValue(state, 3);
  1615. float y = lua_interface->GetFloatValue(state, 4);
  1616. float z = lua_interface->GetFloatValue(state, 5);
  1617. float heading = lua_interface->GetFloatValue(state, 6);
  1618. if (zone && client) {
  1619. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1620. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1621. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1622. {
  1623. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1624. return 0;
  1625. }
  1626. if (x != 0 || y != 0 || z != 0) {
  1627. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1628. player->SetX(x);
  1629. player->SetY(y);
  1630. player->SetZ(z);
  1631. player->SetHeading(heading);
  1632. client->Zone(zone->GetZoneName(), false);
  1633. }
  1634. else
  1635. client->Zone(zone->GetZoneName());
  1636. }
  1637. else
  1638. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1639. lua_interface->ResetFunctionStack(state);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1647. if (spawn && spawn2)
  1648. spawn->AddAllowAccessSpawn(spawn2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* target = lua_interface->GetSpawn(state);
  1656. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1657. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1658. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1659. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1660. lua_interface->ResetFunctionStack(state);
  1661. if (!target) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1663. return 0;
  1664. }
  1665. if (!target->IsEntity()) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1667. return 0;
  1668. }
  1669. if (spell_id <= 0) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1671. return 0;
  1672. }
  1673. if (caster && !caster->IsEntity()) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1675. return 0;
  1676. }
  1677. if (spell_tier == 0)
  1678. spell_tier = 1;
  1679. if (!caster)
  1680. caster = target;
  1681. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* target = lua_interface->GetSpawn(state);
  1688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1689. if(!luaspell || luaspell->resisted) {
  1690. lua_interface->ResetFunctionStack(state);
  1691. return 0;
  1692. }
  1693. Spawn* caster = luaspell->caster;
  1694. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1695. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1696. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1697. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1698. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1699. //lua_interface->ResetFunctionStack(state);
  1700. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1701. vector<int16> faction_req;
  1702. vector<int16> race_req;
  1703. int32 class_req = 0;
  1704. int32 i = 0;
  1705. int8 f = 0;
  1706. int8 r = 0;
  1707. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1708. if (class_id < 100) {
  1709. class_req += pow(2.0, double(class_id - 1));
  1710. }
  1711. else if (class_id > 100 && class_id < 1000) {
  1712. race_req.push_back(class_id);
  1713. r++;
  1714. }
  1715. else {
  1716. faction_req.push_back(class_id);
  1717. f++;
  1718. }
  1719. i++;
  1720. }
  1721. lua_interface->ResetFunctionStack(state);
  1722. if (caster && caster->IsEntity()) {
  1723. bool race_match = false;
  1724. bool success = false;
  1725. luaspell->resisted = false;
  1726. if (luaspell->targets.size() > 0) {
  1727. ZoneServer* zone = luaspell->caster->GetZone();
  1728. Spawn* target = 0;
  1729. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1730. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1731. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1732. if (race_req.size() > 0) {
  1733. for (int8 i = 0; i < race_req.size(); i++) {
  1734. if(race_req[i] == target->GetRace() ||
  1735. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1736. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1737. race_match = true;
  1738. }
  1739. }
  1740. }
  1741. else
  1742. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1743. if (race_match == true) {
  1744. float distance = caster->GetDistance(target, true);
  1745. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1746. }
  1747. }
  1748. }
  1749. success = true;
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (target) {
  1753. //check class and race/faction here
  1754. if (race_req.size() > 0) {
  1755. for (int8 i = 0; i < race_req.size(); i++) {
  1756. if(race_req[i] == target->GetRace() ||
  1757. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1758. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1759. race_match = true;
  1760. }
  1761. }
  1762. }
  1763. else
  1764. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1765. if (race_match == true) {
  1766. float distance = caster->GetDistance(target, true);
  1767. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1768. success = true;
  1769. }
  1770. }
  1771. if (success) {
  1772. Spell* spell = luaspell->spell;
  1773. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1774. ((Player*)caster)->InCombat(true);
  1775. if (caster->GetZone())
  1776. caster->GetZone()->TriggerCharSheetTimer();
  1777. }
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1787. lua_interface->ResetFunctionStack(state);
  1788. if (spawn && value != 0) {
  1789. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1790. spawn->SetPower(spawn->GetTotalPower());
  1791. else
  1792. spawn->SetPower(spawn->GetPower() + value);
  1793. }
  1794. return 0;
  1795. }
  1796. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1797. if (!lua_interface)
  1798. return 0;
  1799. Spawn* spawn = lua_interface->GetSpawn(state);
  1800. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1801. lua_interface->ResetFunctionStack(state);
  1802. if (spawn && value != 0) {
  1803. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1804. spawn->SetHP(spawn->GetTotalHP());
  1805. else
  1806. spawn->SetHP(spawn->GetHP() + value);
  1807. }
  1808. return 0;
  1809. }
  1810. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1811. if (!lua_interface)
  1812. return 0;
  1813. Spawn* spawn = lua_interface->GetSpawn(state);
  1814. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1815. lua_interface->ResetFunctionStack(state);
  1816. if (spawn && value != 0) {
  1817. spawn->SetPower(spawn->GetPower() + value);
  1818. if (value > spawn->GetTotalHPBase())
  1819. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1828. lua_interface->ResetFunctionStack(state);
  1829. if (spawn && value != 0) {
  1830. spawn->SetHP(spawn->GetHP() + value);
  1831. if (value > spawn->GetTotalHPBase())
  1832. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1833. }
  1834. return 0;
  1835. }
  1836. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1837. if (!lua_interface)
  1838. return 0;
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1841. lua_interface->ResetFunctionStack(state);
  1842. if (spawn) {
  1843. spawn->SetHP(value);
  1844. if (value > spawn->GetTotalHPBase())
  1845. spawn->SetTotalHP(value);
  1846. }
  1847. return 0;
  1848. }
  1849. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1850. if (!lua_interface)
  1851. return 0;
  1852. Spawn* spawn = lua_interface->GetSpawn(state);
  1853. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1854. float value = lua_interface->GetFloatValue(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1858. if (spawn && spawn->IsPlayer())
  1859. ((Player*)spawn)->SetCharSheetChanged(true);
  1860. return 0;
  1861. }
  1862. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1863. if (!lua_interface)
  1864. return 0;
  1865. Spawn* spawn = lua_interface->GetSpawn(state);
  1866. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1867. lua_interface->ResetFunctionStack(state);
  1868. if (spawn && spawn->IsEntity() && value > 0)
  1869. ((Entity*)spawn)->SetTotalHPBase(value);
  1870. return 0;
  1871. }
  1872. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1873. if (!lua_interface)
  1874. return 0;
  1875. Spawn* spawn = lua_interface->GetSpawn(state);
  1876. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1877. lua_interface->ResetFunctionStack(state);
  1878. if (spawn && value > 0) {
  1879. spawn->SetPower(value);
  1880. if (value > spawn->GetTotalPowerBase())
  1881. spawn->SetTotalPower(value);
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1890. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1891. lua_interface->ResetFunctionStack(state);
  1892. if (spawn && spawn->IsEntity() && value > 0)
  1893. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1894. return 0;
  1895. }
  1896. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1897. if (!lua_interface)
  1898. return 0;
  1899. Spawn* spawn = lua_interface->GetSpawn(state);
  1900. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1901. lua_interface->ResetFunctionStack(state);
  1902. if (spawn && spawn->IsEntity() && value > 0)
  1903. ((Entity*)spawn)->SetTotalPowerBase(value);
  1904. return 0;
  1905. }
  1906. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1907. if (!lua_interface)
  1908. return 0;
  1909. Spawn* spawn = lua_interface->GetSpawn(state);
  1910. float x = lua_interface->GetFloatValue(state, 2);
  1911. float y = lua_interface->GetFloatValue(state, 3);
  1912. float z = lua_interface->GetFloatValue(state, 4);
  1913. float heading = lua_interface->GetFloatValue(state, 5);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn) {
  1916. spawn->SetX(x);
  1917. spawn->SetY(y);
  1918. spawn->SetZ(z);
  1919. if (heading != 0)
  1920. spawn->SetHeading(heading);
  1921. spawn->SetSpawnOrigX(spawn->GetX());
  1922. spawn->SetSpawnOrigY(spawn->GetY());
  1923. spawn->SetSpawnOrigZ(spawn->GetZ());
  1924. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1925. if (spawn->IsPlayer()) {
  1926. Client* client = ((Player*)spawn)->GetClient();
  1927. if (client) {
  1928. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1929. client->QueuePacket(packet);
  1930. }
  1931. }
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. float value = lua_interface->GetFloatValue(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn) {
  1942. spawn->SetHeading(value);
  1943. if (spawn->IsPlayer()) {
  1944. Client* client = ((Player*)spawn)->GetClient();
  1945. if (client) {
  1946. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1947. client->QueuePacket(packet);
  1948. }
  1949. }
  1950. }
  1951. return 0;
  1952. }
  1953. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1954. if (!lua_interface)
  1955. return 0;
  1956. Spawn* spawn = lua_interface->GetSpawn(state);
  1957. int16 value = lua_interface->GetInt16Value(state, 2);
  1958. lua_interface->ResetFunctionStack(state);
  1959. if (spawn)
  1960. spawn->SetModelType(value);
  1961. return 0;
  1962. }
  1963. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1964. if (!lua_interface)
  1965. return 0;
  1966. Spawn* spawn = lua_interface->GetSpawn(state);
  1967. int8 value = lua_interface->GetInt8Value(state, 2);
  1968. lua_interface->ResetFunctionStack(state);
  1969. if (spawn) {
  1970. if (spawn->IsPlayer())
  1971. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1972. else
  1973. spawn->SetAdventureClass(value);
  1974. }
  1975. return 0;
  1976. }
  1977. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1978. if (!lua_interface)
  1979. return 0;
  1980. Spawn* spawn = lua_interface->GetSpawn(state);
  1981. int8 value = lua_interface->GetInt8Value(state, 2);
  1982. lua_interface->ResetFunctionStack(state);
  1983. if (spawn) {
  1984. spawn->SetTradeskillClass(value);
  1985. if (spawn->IsEntity()) {
  1986. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1987. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1988. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1989. }
  1990. if (spawn->IsPlayer())
  1991. ((Player*)spawn)->SetCharSheetChanged(true);
  1992. }
  1993. return 0;
  1994. }
  1995. int EQ2Emu_lua_SetMount(lua_State* state) {
  1996. if (!lua_interface)
  1997. return 0;
  1998. Spawn* spawn = lua_interface->GetSpawn(state);
  1999. int16 value = lua_interface->GetInt16Value(state, 2);
  2000. if (spawn && spawn->IsEntity()) {
  2001. ((Entity*)spawn)->SetMount(value);
  2002. EQ2_Color color;
  2003. color.red = 255;
  2004. color.green = 255;
  2005. color.blue = 255;
  2006. ((Entity*)spawn)->SetMountColor(&color);
  2007. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2012. if (!lua_interface)
  2013. return 0;
  2014. Spawn* spawn = lua_interface->GetSpawn(state);
  2015. EQ2_Color mount_color;
  2016. EQ2_Color saddle_color;
  2017. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2018. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2019. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2020. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2021. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2022. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2023. if (spawn && spawn->IsEntity()) {
  2024. ((Entity*)spawn)->SetMountColor(&mount_color);
  2025. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2026. }
  2027. return 0;
  2028. }
  2029. int EQ2Emu_lua_GetMount(lua_State* state) {
  2030. if (!lua_interface)
  2031. return 0;
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn && spawn->IsEntity()) {
  2034. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_GetRace(lua_State* state) {
  2040. if (!lua_interface)
  2041. return 0;
  2042. Spawn* spawn = lua_interface->GetSpawn(state);
  2043. if (spawn)
  2044. {
  2045. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2046. lua_interface->SetInt32Value(state, spawn->GetRace());
  2047. return 1;
  2048. }
  2049. return 0;
  2050. }
  2051. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2052. if (!lua_interface)
  2053. return 0;
  2054. Spawn* spawn = lua_interface->GetSpawn(state);
  2055. if (spawn) {
  2056. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2057. return 1;
  2058. }
  2059. return 0;
  2060. }
  2061. int EQ2Emu_lua_GetClass(lua_State* state) {
  2062. Spawn* spawn = lua_interface->GetSpawn(state);
  2063. if (spawn) {
  2064. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2065. return 1;
  2066. }
  2067. return 0;
  2068. }
  2069. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2070. Spawn* spawn = lua_interface->GetSpawn(state);
  2071. if (spawn) {
  2072. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2073. return 1;
  2074. }
  2075. return 0;
  2076. }
  2077. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2078. if (!lua_interface)
  2079. return 0;
  2080. Spawn* spawn = lua_interface->GetSpawn(state);
  2081. float value = lua_interface->GetFloatValue(state, 2);
  2082. lua_interface->ResetFunctionStack(state);
  2083. if (spawn) {
  2084. spawn->SetSpeed(value);
  2085. if(spawn->IsEntity())
  2086. ((Entity*)spawn)->SetSpeed(value);
  2087. if (spawn->IsPlayer()) {
  2088. Client* client = ((Player*)spawn)->GetClient();
  2089. if (client) {
  2090. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2091. if (packet) {
  2092. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2093. packet->setDataByName("speed", value);
  2094. packet->setDataByName("size", 0.51);
  2095. EQ2Packet* app = packet->serialize();
  2096. client->QueuePacket(app);
  2097. safe_delete(packet);
  2098. }
  2099. }
  2100. }
  2101. }
  2102. return 0;
  2103. }
  2104. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2105. if (!lua_interface)
  2106. return 0;
  2107. Spawn* spawn = lua_interface->GetSpawn(state);
  2108. const int16 type = lua_interface->GetInt16Value(state, 2);
  2109. const float value = lua_interface->GetFloatValue(state, 3);
  2110. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2111. if(!luaspell || luaspell->resisted) {
  2112. lua_interface->ResetFunctionStack(state);
  2113. return 0;
  2114. }
  2115. int64 class_req = 0;
  2116. int32 class_id = 0;
  2117. vector<int16> faction_req;
  2118. vector<int16> race_req;
  2119. int32 i = 0;
  2120. int8 f = 0;
  2121. int8 r = 0;
  2122. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2123. if (class_id < 100) {
  2124. class_req += pow(2.0, double(class_id - 1));
  2125. }
  2126. else if (class_id > 100 && class_id < 1000) {
  2127. race_req.push_back(class_id);
  2128. r++;
  2129. }
  2130. else {
  2131. faction_req.push_back(class_id);
  2132. f++;
  2133. }
  2134. i++;
  2135. }
  2136. if (value != 0 && type >= 0) {
  2137. if (luaspell && luaspell->spell && luaspell->caster) {
  2138. ZoneServer* zone = luaspell->caster->GetZone();
  2139. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2140. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2141. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2142. if (target) {
  2143. if (target->IsPlayer()) {
  2144. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2145. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2146. if (((Player*)target)->GetGroupMemberInfo())
  2147. ((Player*)target)->UpdateGroupMemberInfo();
  2148. ((Player*)target)->SetCharSheetChanged(true);
  2149. }
  2150. else if (target->IsNPC())
  2151. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2152. else
  2153. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2154. }
  2155. }
  2156. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2157. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2158. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2159. }
  2160. else if (spawn && spawn->IsEntity()) {
  2161. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2162. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2163. if (spawn->IsPlayer())
  2164. ((Player*)spawn)->SetCharSheetChanged(true);
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2168. }
  2169. else
  2170. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2171. return 0;
  2172. }
  2173. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2174. if (!lua_interface)
  2175. return 0;
  2176. Spawn* spawn = lua_interface->GetSpawn(state);
  2177. int16 type = lua_interface->GetInt16Value(state, 2);
  2178. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2179. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2180. if (!spawn) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!spawn->IsEntity()) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if (value == 0) {
  2189. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2190. return 0;
  2191. }
  2192. if (!luaspell || !luaspell->spell) {
  2193. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2194. return 0;
  2195. }
  2196. if(luaspell->resisted) {
  2197. lua_interface->ResetFunctionStack(state);
  2198. return 0;
  2199. }
  2200. int32 class_req = 0;
  2201. vector<int16> faction_req;
  2202. vector<int16> race_req;
  2203. int32 class_id = 0;
  2204. int32 i = 0;
  2205. int8 f = 0;
  2206. int8 r = 0;
  2207. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2208. if (class_id < 100) {
  2209. class_req += pow(2.0, double(class_id - 1));
  2210. }
  2211. else if (class_id > 100 && class_id < 1000) {
  2212. race_req.push_back(class_id);
  2213. r++;
  2214. }
  2215. else {
  2216. faction_req.push_back(class_id);
  2217. f++;
  2218. }
  2219. i++;
  2220. }
  2221. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2222. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2223. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2224. if (spawn->IsPlayer())
  2225. ((Player*)spawn)->SetCharSheetChanged(true);
  2226. return 0;
  2227. }
  2228. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2229. if (!lua_interface)
  2230. return 0;
  2231. Spawn* spawn = lua_interface->GetSpawn(state);
  2232. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2233. if (!spawn) {
  2234. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2235. return 0;
  2236. }
  2237. if (!spawn->IsEntity()) {
  2238. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2239. return 0;
  2240. }
  2241. if (!luaspell || !luaspell->spell) {
  2242. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2243. return 0;
  2244. }
  2245. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2246. if (spawn->IsPlayer())
  2247. ((Player*)spawn)->SetCharSheetChanged(true);
  2248. return 0;
  2249. }
  2250. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2251. if (!lua_interface)
  2252. return 0;
  2253. Spawn* spawn = lua_interface->GetSpawn(state);
  2254. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2255. if (luaspell && luaspell->spell) {
  2256. ZoneServer* zone = luaspell->caster->GetZone();
  2257. if(!zone) {
  2258. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2259. }
  2260. Spawn* target = 0;
  2261. if(zone) {
  2262. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2263. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2264. target = zone->GetSpawnByID(luaspell->targets[i]);
  2265. if (target && target->IsEntity()) {
  2266. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2267. if (target->IsPlayer())
  2268. ((Player*)target)->SetCharSheetChanged(true);
  2269. }
  2270. }
  2271. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2272. }
  2273. else {
  2274. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2275. }
  2276. }
  2277. else if (spawn && spawn->IsEntity()) {
  2278. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2279. if (spawn->IsPlayer())
  2280. ((Player*)spawn)->SetCharSheetChanged(true);
  2281. }
  2282. return 0;
  2283. }
  2284. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2285. if (!lua_interface)
  2286. return 0;
  2287. Spawn* spawn = lua_interface->GetSpawn(state);
  2288. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2289. float value = lua_interface->GetFloatValue(state, 3);
  2290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2291. if (value != 0) {
  2292. int32 spell_id = 0;
  2293. if (luaspell && luaspell->spell && luaspell->caster) {
  2294. if(luaspell->resisted) {
  2295. lua_interface->ResetFunctionStack(state);
  2296. return 0;
  2297. }
  2298. spell_id = luaspell->spell->GetSpellID();
  2299. ZoneServer* zone = luaspell->caster->GetZone();
  2300. Spawn* target = 0;
  2301. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2302. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2303. target = zone->GetSpawnByID(luaspell->targets[i]);
  2304. if (target && target->Alive()) {
  2305. if (target->IsPlayer()) {
  2306. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2307. Client* client = ((Player*)target)->GetClient();
  2308. if (client) {
  2309. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2310. if (packet)
  2311. client->QueuePacket(packet);
  2312. }
  2313. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2314. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2315. }
  2316. else if (target->IsNPC()) {
  2317. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2318. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2319. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2320. }
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2323. }
  2324. }
  2325. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2326. }
  2327. else if (spawn) {
  2328. if (spawn->IsPlayer()) {
  2329. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2330. Client* client = ((Player*)spawn)->GetClient();
  2331. if (client) {
  2332. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2333. if (packet)
  2334. client->QueuePacket(packet);
  2335. }
  2336. }
  2337. else if (spawn->IsNPC())
  2338. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2339. else
  2340. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2341. }
  2342. }
  2343. else
  2344. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2345. return 0;
  2346. }
  2347. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2348. if (!lua_interface)
  2349. return 0;
  2350. Spawn* spawn = lua_interface->GetSpawn(state);
  2351. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2352. if (spawn && spawn->IsPlayer()) {
  2353. int32 spell_id = 0;
  2354. if (luaspell && luaspell->spell) {
  2355. if(luaspell->resisted) {
  2356. lua_interface->ResetFunctionStack(state);
  2357. return 0;
  2358. }
  2359. spell_id = luaspell->spell->GetSpellID();
  2360. ZoneServer* zone = luaspell->caster->GetZone();
  2361. Spawn* target = 0;
  2362. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2363. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2364. target = zone->GetSpawnByID(luaspell->targets[i]);
  2365. if (target) {
  2366. if (target->IsPlayer()) {
  2367. ((Player*)target)->RemoveSkillBonus(spell_id);
  2368. Client* client = ((Player*)target)->GetClient();
  2369. if (client) {
  2370. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2371. if (packet)
  2372. client->QueuePacket(packet);
  2373. }
  2374. }
  2375. else if (target->IsNPC())
  2376. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2377. else
  2378. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2379. }
  2380. }
  2381. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2382. }
  2383. else if (spawn) {
  2384. if (spawn->IsPlayer()) {
  2385. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2386. Client* client = ((Player*)spawn)->GetClient();
  2387. if (client) {
  2388. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2389. if (packet)
  2390. client->QueuePacket(packet);
  2391. }
  2392. }
  2393. else if (spawn->IsNPC())
  2394. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2395. else
  2396. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2397. }
  2398. }
  2399. return 0;
  2400. }
  2401. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2402. if (!lua_interface)
  2403. return 0;
  2404. Spawn* spawn = lua_interface->GetSpawn(state);
  2405. int8 type = lua_interface->GetInt32Value(state, 2);
  2406. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2407. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2408. if(luaspell && luaspell->resisted) {
  2409. lua_interface->ResetFunctionStack(state);
  2410. return 0;
  2411. }
  2412. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2413. ZoneServer* zone = luaspell->caster->GetZone();
  2414. Spawn* target = 0;
  2415. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2416. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2417. target = zone->GetSpawnByID(luaspell->targets[i]);
  2418. if (target && target->IsEntity()) {
  2419. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2420. ((Entity*)target)->AddMezSpell(luaspell);
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2423. if (target->IsNPC())
  2424. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2425. }
  2426. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2427. ((Entity*)target)->AddStifleSpell(luaspell);
  2428. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2429. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2430. if (target->IsNPC())
  2431. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2432. }
  2433. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2434. ((Entity*)target)->AddDazeSpell(luaspell);
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2437. if (target->IsNPC())
  2438. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2439. }
  2440. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2443. ((Entity*)target)->AddStunSpell(luaspell);
  2444. if (target->IsNPC())
  2445. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2446. }
  2447. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2448. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2449. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2450. ((Entity*)target)->AddRootSpell(luaspell);
  2451. if (target->IsNPC())
  2452. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2453. }
  2454. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2457. ((Entity*)target)->AddFearSpell(luaspell);
  2458. if (target->IsNPC())
  2459. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2460. }
  2461. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2462. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2463. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2464. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2465. }
  2466. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2467. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2468. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2469. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2470. }
  2471. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2472. ((Entity*)target)->AddSnareSpell(luaspell);
  2473. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2474. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2475. if (target->IsNPC())
  2476. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2477. }
  2478. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2479. ((Entity*)target)->AddFlightSpell(luaspell);
  2480. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2481. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2482. }
  2483. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2484. ((Entity*)target)->AddGlideSpell(luaspell);
  2485. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2486. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2487. }
  2488. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2489. ((Entity*)target)->AddSafefallSpell(luaspell);
  2490. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2491. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2492. }
  2493. else
  2494. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2495. }
  2496. else
  2497. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2498. }
  2499. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2500. }
  2501. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2502. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2503. ((Entity*)spawn)->AddMezSpell(luaspell);
  2504. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2505. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2506. }
  2507. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2508. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2509. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2510. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2511. }
  2512. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2513. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2514. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2515. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2516. }
  2517. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2518. ((Entity*)spawn)->AddStunSpell(luaspell);
  2519. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2520. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2521. }
  2522. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2523. ((Entity*)spawn)->AddRootSpell(luaspell);
  2524. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2525. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2526. }
  2527. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2528. ((Entity*)spawn)->AddFearSpell(luaspell);
  2529. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2530. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2531. }
  2532. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2533. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2536. }
  2537. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2538. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2539. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2540. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2541. }
  2542. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2543. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2544. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2545. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2546. }
  2547. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2548. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2549. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2550. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2551. }
  2552. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2553. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2554. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2555. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2556. }
  2557. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2558. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2559. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2560. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2561. }
  2562. else
  2563. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2564. }
  2565. else
  2566. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2567. return 0;
  2568. }
  2569. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2570. if (!lua_interface)
  2571. return 0;
  2572. Spawn* spawn = lua_interface->GetSpawn(state);
  2573. int8 type = lua_interface->GetInt8Value(state, 2);
  2574. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2575. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2576. if (spawn && spawn->IsEntity()) {
  2577. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2578. ZoneServer* zone = luaspell->caster->GetZone();
  2579. Spawn* target = 0;
  2580. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2581. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2582. target = zone->GetSpawnByID(luaspell->targets[i]);
  2583. if (target) {
  2584. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2585. ((Entity*)target)->RemoveMezSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2587. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2588. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2589. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2590. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2591. ((Entity*)target)->RemoveStunSpell(luaspell);
  2592. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2593. ((Entity*)target)->RemoveRootSpell(luaspell);
  2594. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2595. ((Entity*)target)->RemoveFearSpell(luaspell);
  2596. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2597. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2598. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2599. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2600. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2601. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2602. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2603. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2604. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2605. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2606. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2607. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2608. else
  2609. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2610. }
  2611. }
  2612. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2613. }
  2614. else if (only_remove_spawn) {
  2615. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2616. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2618. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2619. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2620. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2621. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2622. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2623. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2624. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2625. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2626. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2627. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2628. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2629. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2630. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2631. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2632. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2633. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2634. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2635. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2636. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2637. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2638. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2639. else
  2640. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2641. }
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. int8 type = lua_interface->GetInt8Value(state, 2);
  2650. bool hasEffect = false;
  2651. if (!spawn)
  2652. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2653. else if (!spawn->IsEntity())
  2654. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2655. else if (type < CONTROL_MAX_EFFECTS)
  2656. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2657. else
  2658. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2659. lua_interface->SetBooleanValue(state, hasEffect);
  2660. return 1;
  2661. }
  2662. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2663. if (!lua_interface)
  2664. return 0;
  2665. Spawn* spawn = lua_interface->GetSpawn(state);
  2666. float distance = 0.0f;
  2667. if (!spawn)
  2668. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2669. else if (!spawn->IsNPC())
  2670. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2671. else
  2672. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2673. lua_interface->SetFloatValue(state, distance);
  2674. return 1;
  2675. }
  2676. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2677. if (!lua_interface)
  2678. return 0;
  2679. Spawn* spawn = lua_interface->GetSpawn(state);
  2680. float distance = 0.0f;
  2681. if (!spawn)
  2682. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2683. else if (!spawn->IsNPC())
  2684. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2685. else
  2686. distance = ((NPC*)spawn)->GetAggroRadius();
  2687. lua_interface->SetFloatValue(state, distance);
  2688. return 1;
  2689. }
  2690. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. float distance = lua_interface->GetFloatValue(state, 2);
  2695. bool override = lua_interface->GetBooleanValue(state, 3);
  2696. bool result = false;
  2697. lua_interface->ResetFunctionStack(state);
  2698. if (!spawn)
  2699. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2700. else if (!spawn->IsNPC())
  2701. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2702. else
  2703. {
  2704. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2705. result = true;
  2706. }
  2707. lua_interface->SetBooleanValue(state, result);
  2708. return 1;
  2709. }
  2710. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2711. if (!lua_interface)
  2712. return 0;
  2713. Spawn* spawn = lua_interface->GetSpawn(state);
  2714. int16 value = lua_interface->GetInt16Value(state, 2);
  2715. if (spawn && spawn->IsEntity()) {
  2716. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2717. if (spawn->IsPlayer())
  2718. ((Player*)spawn)->SetCharSheetChanged(true);
  2719. }
  2720. return 0;
  2721. }
  2722. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2723. if (!lua_interface)
  2724. return 0;
  2725. Spawn* spawn = lua_interface->GetSpawn(state);
  2726. int16 value = lua_interface->GetInt16Value(state, 2);
  2727. if (spawn && spawn->IsEntity()) {
  2728. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2729. if (spawn->IsPlayer())
  2730. ((Player*)spawn)->SetCharSheetChanged(true);
  2731. }
  2732. return 0;
  2733. }
  2734. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2735. if (!lua_interface)
  2736. return 0;
  2737. Spawn* spawn = lua_interface->GetSpawn(state);
  2738. int16 value = lua_interface->GetInt16Value(state, 2);
  2739. if (spawn && spawn->IsEntity()) {
  2740. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2741. if (spawn->IsPlayer())
  2742. ((Player*)spawn)->SetCharSheetChanged(true);
  2743. }
  2744. return 0;
  2745. }
  2746. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2747. if (!lua_interface)
  2748. return 0;
  2749. Spawn* spawn = lua_interface->GetSpawn(state);
  2750. int16 value = lua_interface->GetInt16Value(state, 2);
  2751. if (spawn && spawn->IsEntity()) {
  2752. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2753. if (spawn->IsPlayer())
  2754. ((Player*)spawn)->SetCharSheetChanged(true);
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. int16 value = lua_interface->GetInt16Value(state, 2);
  2763. if (spawn && spawn->IsEntity()) {
  2764. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2765. if (spawn->IsPlayer())
  2766. ((Player*)spawn)->SetCharSheetChanged(true);
  2767. }
  2768. return 0;
  2769. }
  2770. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2771. if (!lua_interface)
  2772. return 0;
  2773. Spawn* spawn = lua_interface->GetSpawn(state);
  2774. int8 value = lua_interface->GetInt8Value(state, 2);
  2775. if (spawn && spawn->IsEntity()) {
  2776. ((Entity*)spawn)->SetDeity(value);
  2777. if (spawn->IsPlayer())
  2778. ((Player*)spawn)->SetCharSheetChanged(true);
  2779. }
  2780. lua_interface->ResetFunctionStack(state);
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* spawn = lua_interface->GetSpawn(state);
  2787. if (spawn && spawn->IsEntity()) {
  2788. int8 deity = ((Entity*)spawn)->GetDeity();
  2789. lua_interface->SetInt32Value(state, deity);
  2790. return 1;
  2791. }
  2792. return 0;
  2793. }
  2794. int EQ2Emu_lua_SetInt(lua_State* state) {
  2795. if (!lua_interface)
  2796. return 0;
  2797. Spawn* spawn = lua_interface->GetSpawn(state);
  2798. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2799. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2800. if (spawn && spawn->IsEntity()) {
  2801. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2802. if (spawn->IsPlayer())
  2803. ((Player*)spawn)->SetCharSheetChanged(true);
  2804. }
  2805. return 0;
  2806. }
  2807. int EQ2Emu_lua_SetWis(lua_State* state) {
  2808. if (!lua_interface)
  2809. return 0;
  2810. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. float value = lua_interface->GetFloatValue(state, 2);
  2813. if (spawn && spawn->IsEntity()) {
  2814. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2815. if (spawn->IsPlayer())
  2816. ((Player*)spawn)->SetCharSheetChanged(true);
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_SetSta(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. float value = lua_interface->GetFloatValue(state, 2);
  2825. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2826. if (spawn && spawn->IsEntity()) {
  2827. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2828. if (spawn->IsPlayer())
  2829. ((Player*)spawn)->SetCharSheetChanged(true);
  2830. }
  2831. return 0;
  2832. }
  2833. int EQ2Emu_lua_SetStr(lua_State* state) {
  2834. if (!lua_interface)
  2835. return 0;
  2836. Spawn* spawn = lua_interface->GetSpawn(state);
  2837. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2838. float value = lua_interface->GetFloatValue(state, 2);
  2839. if (spawn && spawn->IsEntity()) {
  2840. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2841. if (spawn->IsPlayer())
  2842. ((Player*)spawn)->SetCharSheetChanged(true);
  2843. }
  2844. return 0;
  2845. }
  2846. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2847. if (!lua_interface)
  2848. return 0;
  2849. Spawn* spawn = lua_interface->GetSpawn(state);
  2850. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2851. float value = lua_interface->GetFloatValue(state, 2);
  2852. if (spawn && spawn->IsEntity()) {
  2853. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2854. if (spawn->IsPlayer())
  2855. ((Player*)spawn)->SetCharSheetChanged(true);
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn) {
  2864. lua_interface->SetInt32Value(state, spawn->GetHP());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn) {
  2874. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2880. if (!lua_interface)
  2881. return 0;
  2882. Spawn* spawn = lua_interface->GetSpawn(state);
  2883. if (spawn) {
  2884. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2885. return 1;
  2886. }
  2887. return 0;
  2888. }
  2889. int EQ2Emu_lua_GetName(lua_State* state) {
  2890. if (!lua_interface)
  2891. return 0;
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. if (spawn) {
  2894. lua_interface->SetStringValue(state, spawn->GetName());
  2895. return 1;
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2900. Spawn* spawn = lua_interface->GetSpawn(state);
  2901. if (spawn) {
  2902. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  2908. Spawn* spawn = lua_interface->GetSpawn(state);
  2909. if (spawn) {
  2910. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  2911. return 1;
  2912. }
  2913. return 0;
  2914. }
  2915. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2916. if (!lua_interface)
  2917. return 0;
  2918. Spawn* spawn = lua_interface->GetSpawn(state);
  2919. if (spawn) {
  2920. lua_interface->SetInt32Value(state, spawn->GetPower());
  2921. return 1;
  2922. }
  2923. return 0;
  2924. }
  2925. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2926. if (!lua_interface)
  2927. return 0;
  2928. Spawn* spawn = lua_interface->GetSpawn(state);
  2929. if (spawn) {
  2930. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2931. return 1;
  2932. }
  2933. return 0;
  2934. }
  2935. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2936. if (!lua_interface)
  2937. return 0;
  2938. Spawn* spawn = lua_interface->GetSpawn(state);
  2939. if (spawn) {
  2940. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2941. return 1;
  2942. }
  2943. return 0;
  2944. }
  2945. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2946. if (!lua_interface)
  2947. return 0;
  2948. Spawn* spawn = lua_interface->GetSpawn(state);
  2949. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2950. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2951. if (spawn && spawn2) {
  2952. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2953. lua_interface->SetFloatValue(state, distance);
  2954. return 1;
  2955. }
  2956. return 0;
  2957. }
  2958. int EQ2Emu_lua_GetX(lua_State* state) {
  2959. if (!lua_interface)
  2960. return 0;
  2961. Spawn* spawn = lua_interface->GetSpawn(state);
  2962. if (spawn) {
  2963. lua_interface->SetFloatValue(state, spawn->GetX());
  2964. return 1;
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_GetY(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Spawn* spawn = lua_interface->GetSpawn(state);
  2972. if (spawn) {
  2973. lua_interface->SetFloatValue(state, spawn->GetY());
  2974. return 1;
  2975. }
  2976. return 0;
  2977. }
  2978. int EQ2Emu_lua_GetZ(lua_State* state) {
  2979. if (!lua_interface)
  2980. return 0;
  2981. Spawn* spawn = lua_interface->GetSpawn(state);
  2982. if (spawn) {
  2983. lua_interface->SetFloatValue(state, spawn->GetZ());
  2984. return 1;
  2985. }
  2986. return 0;
  2987. }
  2988. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2989. if (!lua_interface)
  2990. return 0;
  2991. Spawn* spawn = lua_interface->GetSpawn(state);
  2992. if (spawn) {
  2993. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2994. return 1;
  2995. }
  2996. return 0;
  2997. }
  2998. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2999. if (!lua_interface)
  3000. return 0;
  3001. Spawn* spawn = lua_interface->GetSpawn(state);
  3002. if (spawn) {
  3003. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3004. return 1;
  3005. }
  3006. return 0;
  3007. }
  3008. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3009. if (!lua_interface)
  3010. return 0;
  3011. Spawn* spawn = lua_interface->GetSpawn(state);
  3012. if (spawn) {
  3013. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3014. return 1;
  3015. }
  3016. return 0;
  3017. }
  3018. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3019. if (!lua_interface)
  3020. return 0;
  3021. Spawn* spawn = lua_interface->GetSpawn(state);
  3022. if (spawn && spawn->IsEntity()) {
  3023. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetInt(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. if (spawn && spawn->IsEntity()) {
  3033. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3034. return 1;
  3035. }
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_GetWis(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. if (spawn && spawn->IsEntity()) {
  3043. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetSta(lua_State* state) {
  3049. if (!lua_interface)
  3050. return 0;
  3051. Spawn* spawn = lua_interface->GetSpawn(state);
  3052. if (spawn && spawn->IsEntity()) {
  3053. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3054. return 1;
  3055. }
  3056. return 0;
  3057. }
  3058. int EQ2Emu_lua_GetStr(lua_State* state) {
  3059. if (!lua_interface)
  3060. return 0;
  3061. Spawn* spawn = lua_interface->GetSpawn(state);
  3062. if (spawn && spawn->IsEntity()) {
  3063. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3064. return 1;
  3065. }
  3066. return 0;
  3067. }
  3068. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3069. if (!lua_interface)
  3070. return 0;
  3071. Spawn* spawn = lua_interface->GetSpawn(state);
  3072. if (spawn && spawn->IsEntity()) {
  3073. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3074. return 1;
  3075. }
  3076. return 0;
  3077. }
  3078. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3079. if (!lua_interface)
  3080. return 0;
  3081. Spawn* spawn = lua_interface->GetSpawn(state);
  3082. if (spawn && spawn->IsEntity()) {
  3083. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3084. return 1;
  3085. }
  3086. return 0;
  3087. }
  3088. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3089. if (!lua_interface)
  3090. return 0;
  3091. Spawn* spawn = lua_interface->GetSpawn(state);
  3092. if (spawn && spawn->IsEntity()) {
  3093. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3094. return 1;
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Spawn* spawn = lua_interface->GetSpawn(state);
  3102. if (spawn && spawn->IsEntity()) {
  3103. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3104. return 1;
  3105. }
  3106. return 0;
  3107. }
  3108. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3109. if (!lua_interface)
  3110. return 0;
  3111. Spawn* spawn = lua_interface->GetSpawn(state);
  3112. if (spawn && spawn->IsEntity()) {
  3113. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3114. return 1;
  3115. }
  3116. return 0;
  3117. }
  3118. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3119. if (!lua_interface)
  3120. return 0;
  3121. Spawn* spawn = lua_interface->GetSpawn(state);
  3122. if (spawn && spawn->IsEntity()) {
  3123. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3124. return 1;
  3125. }
  3126. return 0;
  3127. }
  3128. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3129. if (!lua_interface)
  3130. return 0;
  3131. Spawn* player = lua_interface->GetSpawn(state);
  3132. if (!player || !player->IsPlayer()) {
  3133. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3134. return 0;
  3135. }
  3136. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3137. if (quest_id <= 0) {
  3138. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3139. return 0;
  3140. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3141. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3142. return 0;
  3143. }
  3144. int32 step = lua_interface->GetInt32Value(state, 3);
  3145. if (step > 0) {
  3146. Client* client = ((Player*)player)->GetClient();
  3147. if (client)
  3148. client->AddPendingQuestUpdate(quest_id, step);
  3149. } else {
  3150. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3151. }
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3155. Spawn* player = lua_interface->GetSpawn(state);
  3156. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3157. int32 step = lua_interface->GetInt32Value(state, 3);
  3158. int32 progress = lua_interface->GetInt32Value(state, 4);
  3159. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3160. Client* client = ((Player*)player)->GetClient();
  3161. if (client)
  3162. client->AddPendingQuestUpdate(quest_id, step, progress);
  3163. }
  3164. return 0;
  3165. }
  3166. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3167. if (!lua_interface)
  3168. return 0;
  3169. Spawn* player = lua_interface->GetSpawn(state);
  3170. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3171. if (player && player->IsPlayer() && quest_id > 0) {
  3172. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3173. return 1;
  3174. }
  3175. return 0;
  3176. }
  3177. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3178. if (!lua_interface)
  3179. return 0;
  3180. Spawn* player = lua_interface->GetSpawn(state);
  3181. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3182. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3183. if (player && player->IsPlayer() && quest_id > 0) {
  3184. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3185. return 1;
  3186. }
  3187. return 0;
  3188. }
  3189. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3190. if (!lua_interface)
  3191. return 0;
  3192. Spawn* player = lua_interface->GetSpawn(state);
  3193. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3194. if (player && player->IsPlayer() && quest_id > 0) {
  3195. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3196. return 1;
  3197. }
  3198. return 0;
  3199. }
  3200. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3201. if (!lua_interface)
  3202. return 0;
  3203. Quest* quest = lua_interface->GetQuest(state);
  3204. string name = lua_interface->GetStringValue(state, 2);
  3205. string type = lua_interface->GetStringValue(state, 3);
  3206. string zone = lua_interface->GetStringValue(state, 4);
  3207. int16 level = lua_interface->GetInt16Value(state, 5);
  3208. string description = lua_interface->GetStringValue(state, 6);
  3209. bool load = true;
  3210. if (!quest) {
  3211. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3212. load = false;
  3213. }
  3214. if (load && name.length() == 0) {
  3215. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3216. load = false;
  3217. }
  3218. if (load && type.length() == 0) {
  3219. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3220. load = false;
  3221. }
  3222. if (load && zone.length() == 0) {
  3223. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3224. load = false;
  3225. }
  3226. if (load && description.length() == 0) {
  3227. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3228. load = false;
  3229. }
  3230. if (load && level == 0) {
  3231. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3232. load = false;
  3233. }
  3234. if (load)
  3235. quest->RegisterQuest(name, type, zone, level, description);
  3236. return 0;
  3237. }
  3238. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3239. if (!lua_interface)
  3240. return 0;
  3241. Quest* quest = lua_interface->GetQuest(state);
  3242. if (quest) {
  3243. int8 level = lua_interface->GetInt16Value(state, 2);
  3244. quest->SetPrereqLevel(level);
  3245. }
  3246. return 0;
  3247. }
  3248. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3249. if (!lua_interface)
  3250. return 0;
  3251. Quest* quest = lua_interface->GetQuest(state);
  3252. if (quest) {
  3253. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3254. quest->AddPrereqQuest(quest_id);
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Quest* quest = lua_interface->GetQuest(state);
  3262. if (quest) {
  3263. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3264. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3265. if (quantity == 0)
  3266. quantity = 1;
  3267. Item* master_item = master_item_list.GetItem(item_id);
  3268. if (master_item) {
  3269. Item* item = new Item(master_item);
  3270. item->details.count = quantity;
  3271. quest->AddPrereqItem(item);
  3272. }
  3273. }
  3274. return 0;
  3275. }
  3276. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3277. if (!lua_interface)
  3278. return 0;
  3279. Spawn* player = lua_interface->GetSpawn(state);
  3280. if(!player || !player->IsPlayer()) {
  3281. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3282. return 0;
  3283. }
  3284. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3285. if (quest_id > 0) {
  3286. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) > 0));
  3287. return 1;
  3288. } else {
  3289. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3290. }
  3291. return 0;
  3292. }
  3293. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3294. if (!lua_interface)
  3295. return 0;
  3296. Quest* quest = lua_interface->GetQuest(state);
  3297. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3298. lua_interface->ResetFunctionStack(state);
  3299. if (quest && spawn_id > 0)
  3300. quest->SetQuestReturnNPC(spawn_id);
  3301. return 0;
  3302. }
  3303. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3304. if (!lua_interface)
  3305. return 0;
  3306. Spawn* spawn = lua_interface->GetSpawn(state);
  3307. int32 time = lua_interface->GetInt32Value(state, 2);
  3308. string function = lua_interface->GetStringValue(state, 3);
  3309. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3310. Spawn* player = lua_interface->GetSpawn(state, 5);
  3311. lua_interface->ResetFunctionStack(state);
  3312. if (!spawn) {
  3313. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3314. return 0;
  3315. }
  3316. if (time <= 0) {
  3317. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3318. return 0;
  3319. }
  3320. if (function.length() == 0) {
  3321. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3322. return 0;
  3323. }
  3324. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3325. if ( time < 10)
  3326. time = 10;
  3327. timer->timer = Timer::GetCurrentTime2() + time;
  3328. timer->function = function;
  3329. timer->spawn = spawn->GetID();
  3330. timer->player = player ? player->GetID() : 0;
  3331. if (max_count == 0)
  3332. max_count = 1;
  3333. timer->max_count = max_count;
  3334. timer->current_count = 0;
  3335. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3336. return 0;
  3337. }
  3338. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3339. if (!lua_interface)
  3340. return 0;
  3341. Spawn* spawn = lua_interface->GetSpawn(state);
  3342. string function = lua_interface->GetStringValue(state, 2);
  3343. lua_interface->ResetFunctionStack(state);
  3344. if (!spawn) {
  3345. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3346. return 0;
  3347. }
  3348. if(!spawn->GetZone()) {
  3349. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3350. return 0;
  3351. }
  3352. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3353. return 0;
  3354. }
  3355. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3356. if (!lua_interface)
  3357. return 0;
  3358. Spawn* player = lua_interface->GetSpawn(state);
  3359. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3360. lua_interface->ResetFunctionStack(state);
  3361. if (player && player->IsPlayer() && quest_id > 0) {
  3362. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3363. return 1;
  3364. }
  3365. return 0;
  3366. }
  3367. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3368. if (!lua_interface)
  3369. return 0;
  3370. Spawn* player = lua_interface->GetSpawn(state);
  3371. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3372. lua_interface->ResetFunctionStack(state);
  3373. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3374. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3375. if (quest)
  3376. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3377. return 1;
  3378. }
  3379. return 0;
  3380. }
  3381. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3382. if (!lua_interface)
  3383. return 0;
  3384. Spawn* player = lua_interface->GetSpawn(state);
  3385. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3386. lua_interface->ResetFunctionStack(state);
  3387. if (player && player->IsPlayer() && quest_id > 0) {
  3388. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3389. return 1;
  3390. }
  3391. return 0;
  3392. }
  3393. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3394. if (!lua_interface)
  3395. return 0;
  3396. Spawn* npc = lua_interface->GetSpawn(state);
  3397. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3398. lua_interface->ResetFunctionStack(state);
  3399. if (npc && !npc->IsPlayer() && quest_id > 0)
  3400. npc->AddProvidedQuest(quest_id);
  3401. return 0;
  3402. }
  3403. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3404. if (!lua_interface)
  3405. return 0;
  3406. Spawn* npc = lua_interface->GetSpawn(state);
  3407. Spawn* player = lua_interface->GetSpawn(state, 2);
  3408. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3409. bool forced = lua_interface->GetBooleanValue(state, 4);
  3410. lua_interface->ResetFunctionStack(state);
  3411. /* NPC is allowed to be null */
  3412. if (player && player->IsPlayer() && quest_id > 0) {
  3413. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3414. if (master_quest) {
  3415. Client* client = ((Player*)player)->GetClient();
  3416. if (!client) {
  3417. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3418. }
  3419. Quest* quest = new Quest(master_quest);
  3420. if (!quest) {
  3421. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3422. }
  3423. if (client && quest) {
  3424. if (npc)
  3425. quest->SetQuestGiver(npc->GetDatabaseID());
  3426. else
  3427. quest->SetQuestGiver(0);
  3428. client->AddPendingQuest(quest, forced);
  3429. }
  3430. }
  3431. else {
  3432. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3433. }
  3434. }
  3435. else {
  3436. 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);
  3437. }
  3438. return 0;
  3439. }
  3440. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3441. if (!lua_interface)
  3442. return 0;
  3443. Quest* quest = lua_interface->GetQuest(state);
  3444. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3445. lua_interface->ResetFunctionStack(state);
  3446. if (quest) {
  3447. quest->AddPrereqClass(class_id);
  3448. }
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Quest* quest = lua_interface->GetQuest(state);
  3455. int8 race = lua_interface->GetInt8Value(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (quest) {
  3458. quest->AddPrereqRace(race);
  3459. }
  3460. return 0;
  3461. }
  3462. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3463. if (!lua_interface)
  3464. return 0;
  3465. Quest* quest = lua_interface->GetQuest(state);
  3466. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3467. lua_interface->ResetFunctionStack(state);
  3468. if (quest) {
  3469. quest->AddPrereqModelType(model_type);
  3470. }
  3471. return 0;
  3472. }
  3473. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3474. if (!lua_interface)
  3475. return 0;
  3476. Quest* quest = lua_interface->GetQuest(state);
  3477. int8 level = lua_interface->GetInt8Value(state, 2);
  3478. lua_interface->ResetFunctionStack(state);
  3479. if (!quest) {
  3480. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3481. return 0;
  3482. }
  3483. quest->SetPrereqTSLevel(level);
  3484. return 0;
  3485. }
  3486. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3487. if (!lua_interface)
  3488. return 0;
  3489. Quest* quest = lua_interface->GetQuest(state);
  3490. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3491. lua_interface->ResetFunctionStack(state);
  3492. if (!quest) {
  3493. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3494. return 0;
  3495. }
  3496. quest->AddPrereqTradeskillClass(class_id);
  3497. return 0;
  3498. }
  3499. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3500. if (!lua_interface)
  3501. return 0;
  3502. Quest* quest = lua_interface->GetQuest(state);
  3503. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3504. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3505. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3506. lua_interface->ResetFunctionStack(state);
  3507. if (quest) {
  3508. quest->AddPrereqFaction(faction_id, min, max);
  3509. }
  3510. return 0;
  3511. }
  3512. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3513. if (!lua_interface)
  3514. return 0;
  3515. Quest* quest = lua_interface->GetQuest(state);
  3516. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3517. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3518. lua_interface->ResetFunctionStack(state);
  3519. if (quest) {
  3520. if (quantity == 0)
  3521. quantity = 1;
  3522. Item* master_item = master_item_list.GetItem(item_id);
  3523. if (master_item) {
  3524. Item* item = new Item(master_item);
  3525. item->details.count = quantity;
  3526. quest->AddSelectableRewardItem(item);
  3527. }
  3528. }
  3529. return 0;
  3530. }
  3531. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3532. if (!lua_interface)
  3533. return 0;
  3534. Quest* quest = lua_interface->GetQuest(state);
  3535. if (quest) {
  3536. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3537. vector<Item*>* items = quest->GetRewardItems();
  3538. if (items) {
  3539. vector<Item*>::iterator itr;
  3540. for (itr = items->begin(); itr != items->end(); itr++) {
  3541. if (*itr && (*itr)->details.item_id == item_id) {
  3542. lua_interface->SetBooleanValue(state, true);
  3543. return 1;
  3544. }
  3545. }
  3546. }
  3547. }
  3548. lua_interface->SetBooleanValue(state, false);
  3549. return 1;
  3550. }
  3551. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3556. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3557. lua_interface->ResetFunctionStack(state);
  3558. if (quest) {
  3559. if (quantity == 0)
  3560. quantity = 1;
  3561. Item* master_item = master_item_list.GetItem(item_id);
  3562. if (master_item) {
  3563. Item* item = new Item(master_item);
  3564. item->details.count = quantity;
  3565. quest->AddRewardItem(item);
  3566. }
  3567. }
  3568. return 0;
  3569. }
  3570. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3571. if (!lua_interface)
  3572. return 0;
  3573. Quest* quest = lua_interface->GetQuest(state);
  3574. int32 copper = lua_interface->GetInt32Value(state, 2);
  3575. int32 silver = lua_interface->GetInt32Value(state, 3);
  3576. int32 gold = lua_interface->GetInt32Value(state, 4);
  3577. int32 plat = lua_interface->GetInt32Value(state, 5);
  3578. lua_interface->ResetFunctionStack(state);
  3579. if (quest) {
  3580. quest->AddRewardCoins(copper, silver, gold, plat);
  3581. }
  3582. return 0;
  3583. }
  3584. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3585. if (!lua_interface)
  3586. return 0;
  3587. Quest* quest = lua_interface->GetQuest(state);
  3588. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3589. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3590. lua_interface->ResetFunctionStack(state);
  3591. if (quest && faction_id > 0 && amount != 0)
  3592. quest->AddRewardFaction(faction_id, amount);
  3593. return 0;
  3594. }
  3595. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3596. if (!lua_interface)
  3597. return 0;
  3598. Quest* quest = lua_interface->GetQuest(state);
  3599. int32 status = lua_interface->GetInt32Value(state, 2);
  3600. lua_interface->ResetFunctionStack(state);
  3601. if (quest) {
  3602. quest->SetRewardStatus(status);
  3603. }
  3604. return 0;
  3605. }
  3606. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3607. if (!lua_interface)
  3608. return 0;
  3609. Quest* quest = lua_interface->GetQuest(state);
  3610. int32 status = lua_interface->GetInt32Value(state, 2);
  3611. lua_interface->ResetFunctionStack(state);
  3612. if (quest) {
  3613. quest->SetStatusTmpReward(status);
  3614. }
  3615. return 0;
  3616. }
  3617. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3618. if (!lua_interface)
  3619. return 0;
  3620. Quest* quest = lua_interface->GetQuest(state);
  3621. int64 coins = lua_interface->GetInt64Value(state, 2);
  3622. lua_interface->ResetFunctionStack(state);
  3623. if (quest) {
  3624. quest->SetCoinTmpReward(coins);
  3625. }
  3626. return 0;
  3627. }
  3628. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3629. if (!lua_interface)
  3630. return 0;
  3631. Quest* quest = lua_interface->GetQuest(state);
  3632. string comment = lua_interface->GetStringValue(state, 2);
  3633. lua_interface->ResetFunctionStack(state);
  3634. if (quest) {
  3635. quest->SetRewardComment(comment);
  3636. }
  3637. return 0;
  3638. }
  3639. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3640. if (!lua_interface)
  3641. return 0;
  3642. Quest* quest = lua_interface->GetQuest(state);
  3643. int32 exp = lua_interface->GetInt32Value(state, 2);
  3644. lua_interface->ResetFunctionStack(state);
  3645. if (quest) {
  3646. quest->SetRewardXP(exp);
  3647. }
  3648. return 0;
  3649. }
  3650. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  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. float percentage = lua_interface->GetFloatValue(state, 5);
  3656. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3657. int16 icon = lua_interface->GetInt16Value(state, 7);
  3658. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3659. if (quest) {
  3660. const char* taskgroup = 0;
  3661. if (str_taskgroup.length() > 0)
  3662. taskgroup = str_taskgroup.c_str();
  3663. int32 id = 0;
  3664. vector<int32>* ids = 0;
  3665. int i = 0;
  3666. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3667. if (ids == 0)
  3668. ids = new vector<int32>;
  3669. ids->push_back(id);
  3670. i++;
  3671. }
  3672. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3673. if (quest_step && icon && quantity > 0)
  3674. quest_step->SetIcon(icon);
  3675. if (quest->GetPlayer()) {
  3676. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3677. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3678. }
  3679. }
  3680. lua_interface->ResetFunctionStack(state);
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3684. {
  3685. if (!lua_interface)
  3686. return 0;
  3687. Quest* quest = lua_interface->GetQuest(state);
  3688. int32 step = lua_interface->GetInt32Value(state, 2);
  3689. string description = lua_interface->GetStringValue(state, 3);
  3690. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3691. float percentage = lua_interface->GetFloatValue(state, 5);
  3692. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3693. int16 icon = lua_interface->GetInt16Value(state, 7);
  3694. if (quest) {
  3695. const char* taskgroup = 0;
  3696. if (str_taskgroup.length() > 0)
  3697. taskgroup = str_taskgroup.c_str();
  3698. int32 id = 0;
  3699. vector<int32>* ids = 0;
  3700. int i = 0;
  3701. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3702. if (ids == 0)
  3703. ids = new vector<int32>;
  3704. ids->push_back(id);
  3705. i++;
  3706. }
  3707. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3708. if (quest_step && icon > 0 && quantity > 0)
  3709. quest_step->SetIcon(icon);
  3710. if (quest->GetPlayer()) {
  3711. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3712. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3713. }
  3714. safe_delete(ids);
  3715. }
  3716. lua_interface->ResetFunctionStack(state);
  3717. return 0;
  3718. }
  3719. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3720. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3721. }
  3722. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3723. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3724. }
  3725. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3726. if (!lua_interface)
  3727. return 0;
  3728. Quest* quest = lua_interface->GetQuest(state);
  3729. int32 step = lua_interface->GetInt32Value(state, 2);
  3730. string description = lua_interface->GetStringValue(state, 3);
  3731. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3732. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3733. int16 icon = lua_interface->GetInt16Value(state, 6);
  3734. if (quest) {
  3735. const char* taskgroup = 0;
  3736. if (str_taskgroup.length() > 0)
  3737. taskgroup = str_taskgroup.c_str();
  3738. int32 npc_id = 0;
  3739. vector<int32>* ids = 0;
  3740. int i = 0;
  3741. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3742. if (ids == 0)
  3743. ids = new vector<int32>;
  3744. ids->push_back(npc_id);
  3745. i++;
  3746. }
  3747. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  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. if(client)
  3753. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3754. }
  3755. safe_delete(ids);
  3756. }
  3757. lua_interface->ResetFunctionStack(state);
  3758. return 0;
  3759. }
  3760. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3761. if (!lua_interface)
  3762. return 0;
  3763. Quest* quest = lua_interface->GetQuest(state);
  3764. int32 step = lua_interface->GetInt32Value(state, 2);
  3765. string description = lua_interface->GetStringValue(state, 3);
  3766. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3767. float percentage = lua_interface->GetFloatValue(state, 5);
  3768. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3769. int16 icon = lua_interface->GetInt16Value(state, 7);
  3770. if (quest) {
  3771. const char* taskgroup = 0;
  3772. if (str_taskgroup.length() > 0)
  3773. taskgroup = str_taskgroup.c_str();
  3774. int32 item_id = 0;
  3775. vector<int32>* ids = 0;
  3776. int i = 0;
  3777. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3778. if (ids == 0)
  3779. ids = new vector<int32>;
  3780. ids->push_back(item_id);
  3781. i++;
  3782. }
  3783. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3784. if (quest_step && icon > 0 && quantity > 0)
  3785. quest_step->SetIcon(icon);
  3786. if (quest->GetPlayer()) {
  3787. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3788. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3789. }
  3790. safe_delete(ids);
  3791. }
  3792. lua_interface->ResetFunctionStack(state);
  3793. return 0;
  3794. }
  3795. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3796. if (!lua_interface)
  3797. return 0;
  3798. Quest* quest = lua_interface->GetQuest(state);
  3799. int32 step = lua_interface->GetInt32Value(state, 2);
  3800. string description = lua_interface->GetStringValue(state, 3);
  3801. float max_variation = lua_interface->GetFloatValue(state, 4);
  3802. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3803. int16 icon = lua_interface->GetInt16Value(state, 6);
  3804. if (quest) {
  3805. const char* taskgroup = 0;
  3806. if (str_taskgroup.length() > 0)
  3807. taskgroup = str_taskgroup.c_str();
  3808. vector<Location>* locations = 0;
  3809. int8 i = 7;
  3810. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3811. while (true) {
  3812. Location loc;
  3813. loc.x = lua_interface->GetFloatValue(state, i);
  3814. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3815. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3816. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3817. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3818. break;
  3819. if (locations == 0)
  3820. locations = new vector<Location>;
  3821. locations->push_back(loc);
  3822. i += 4;
  3823. }
  3824. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3825. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  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_AddQuestStepLocation(lua_State* state) {
  3837. if (!lua_interface)
  3838. return 0;
  3839. Quest* quest = lua_interface->GetQuest(state);
  3840. int32 step = lua_interface->GetInt32Value(state, 2);
  3841. string description = lua_interface->GetStringValue(state, 3);
  3842. float max_variation = lua_interface->GetFloatValue(state, 4);
  3843. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3844. int16 icon = lua_interface->GetInt16Value(state, 6);
  3845. if (quest) {
  3846. const char* taskgroup = 0;
  3847. if (str_taskgroup.length() > 0)
  3848. taskgroup = str_taskgroup.c_str();
  3849. vector<Location>* locations = 0;
  3850. int8 i = 7;
  3851. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3852. while (true) {
  3853. Location loc;
  3854. loc.x = lua_interface->GetFloatValue(state, i);
  3855. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3856. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3857. loc.zone_id = 0;
  3858. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3859. break;
  3860. if (locations == 0)
  3861. locations = new vector<Location>;
  3862. locations->push_back(loc);
  3863. i += 3;
  3864. }
  3865. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3866. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3867. if (quest_step && icon > 0)
  3868. quest_step->SetIcon(icon);
  3869. if (quest->GetPlayer()) {
  3870. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3871. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3872. }
  3873. }
  3874. lua_interface->ResetFunctionStack(state);
  3875. return 0;
  3876. }
  3877. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3878. if (!lua_interface)
  3879. return 0;
  3880. Quest* quest = lua_interface->GetQuest(state);
  3881. int32 step = lua_interface->GetInt32Value(state, 2);
  3882. string description = lua_interface->GetStringValue(state, 3);
  3883. float max_variation = lua_interface->GetFloatValue(state, 4);
  3884. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3885. int16 icon = lua_interface->GetInt16Value(state, 6);
  3886. if (quest) {
  3887. const char* taskgroup = 0;
  3888. if (str_taskgroup.length() > 0)
  3889. taskgroup = str_taskgroup.c_str();
  3890. vector<Location>* locations = 0;
  3891. int i = 7;
  3892. while (true) {
  3893. Location loc;
  3894. loc.x = lua_interface->GetFloatValue(state, i);
  3895. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3896. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3897. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3898. break;
  3899. if (locations == 0)
  3900. locations = new vector<Location>;
  3901. locations->push_back(loc);
  3902. i += 3;
  3903. }
  3904. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3905. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3906. if (quest_step && icon > 0)
  3907. quest_step->SetIcon(icon);
  3908. if (quest->GetPlayer()) {
  3909. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3910. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3911. }
  3912. }
  3913. lua_interface->ResetFunctionStack(state);
  3914. return 0;
  3915. }
  3916. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3917. Quest* quest = lua_interface->GetQuest(state);
  3918. int32 step = lua_interface->GetInt32Value(state, 2);
  3919. string description = lua_interface->GetStringValue(state, 3);
  3920. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3921. float percentage = lua_interface->GetFloatValue(state, 5);
  3922. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3923. int16 icon = lua_interface->GetInt16Value(state, 7);
  3924. if (quest) {
  3925. const char* taskgroup = 0;
  3926. if (str_taskgroup.length() > 0)
  3927. taskgroup = str_taskgroup.c_str();
  3928. int32 spell_id = 0;
  3929. vector<int32>* ids = 0;
  3930. int i = 0;
  3931. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3932. if (ids == 0)
  3933. ids = new vector<int32>;
  3934. ids->push_back(spell_id);
  3935. i++;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3938. if (quest_step && icon > 0 && quantity > 0)
  3939. quest_step->SetIcon(icon);
  3940. if (quest->GetPlayer()) {
  3941. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3942. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3943. }
  3944. safe_delete(ids);
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3956. float percentage = lua_interface->GetFloatValue(state, 5);
  3957. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3958. int16 icon = lua_interface->GetInt16Value(state, 7);
  3959. if (quest) {
  3960. const char* taskgroup = 0;
  3961. if (str_taskgroup.length() > 0)
  3962. taskgroup = str_taskgroup.c_str();
  3963. int32 item_id = 0;
  3964. vector<int32>* ids = 0;
  3965. int i = 0;
  3966. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3967. if (ids == 0)
  3968. ids = new vector<int32>;
  3969. ids->push_back(item_id);
  3970. i++;
  3971. }
  3972. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3973. if (quest_step && icon > 0 && quantity > 0)
  3974. quest_step->SetIcon(icon);
  3975. if (quest->GetPlayer()) {
  3976. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3977. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3978. }
  3979. safe_delete(ids);
  3980. }
  3981. lua_interface->ResetFunctionStack(state);
  3982. return 0;
  3983. }
  3984. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3985. if (!lua_interface)
  3986. return 0;
  3987. Quest* quest = lua_interface->GetQuest(state);
  3988. int32 step = lua_interface->GetInt32Value(state, 2);
  3989. string description = lua_interface->GetStringValue(state, 3);
  3990. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3991. float percentage = lua_interface->GetFloatValue(state, 5);
  3992. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3993. int16 icon = lua_interface->GetInt16Value(state, 7);
  3994. if (quest) {
  3995. const char* taskgroup = 0;
  3996. if (str_taskgroup.length() > 0)
  3997. taskgroup = str_taskgroup.c_str();
  3998. int32 item_id = 0;
  3999. vector<int32>* ids = 0;
  4000. int i = 0;
  4001. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4002. if (ids == 0)
  4003. ids = new vector<int32>;
  4004. ids->push_back(item_id);
  4005. i++;
  4006. }
  4007. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4008. if (quest_step && icon > 0 && quantity > 0)
  4009. quest_step->SetIcon(icon);
  4010. if (quest->GetPlayer()) {
  4011. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4012. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4013. }
  4014. safe_delete(ids);
  4015. }
  4016. lua_interface->ResetFunctionStack(state);
  4017. return 0;
  4018. }
  4019. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4020. if (!lua_interface)
  4021. return 0;
  4022. Quest* quest = lua_interface->GetQuest(state);
  4023. string action = lua_interface->GetStringValue(state, 2);
  4024. lua_interface->ResetFunctionStack(state);
  4025. if (quest) {
  4026. if (action.length() > 0)
  4027. quest->SetCompleteAction(action);
  4028. }
  4029. return 0;
  4030. }
  4031. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4032. if (!lua_interface)
  4033. return 0;
  4034. Quest* quest = lua_interface->GetQuest(state);
  4035. int32 step = lua_interface->GetInt32Value(state, 2);
  4036. string action = lua_interface->GetStringValue(state, 3);
  4037. lua_interface->ResetFunctionStack(state);
  4038. if (quest) {
  4039. if (step > 0 && action.length() > 0)
  4040. quest->AddCompleteAction(step, action);
  4041. }
  4042. return 0;
  4043. }
  4044. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4045. if (!lua_interface)
  4046. return 0;
  4047. Quest* quest = lua_interface->GetQuest(state);
  4048. int32 step = lua_interface->GetInt32Value(state, 2);
  4049. string action = lua_interface->GetStringValue(state, 3);
  4050. lua_interface->ResetFunctionStack(state);
  4051. if (quest) {
  4052. if (step > 0 && action.length() > 0)
  4053. quest->AddProgressAction(step, action);
  4054. }
  4055. return 0;
  4056. }
  4057. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4058. if (!lua_interface)
  4059. return 0;
  4060. Quest* quest = lua_interface->GetQuest(state);
  4061. string description = lua_interface->GetStringValue(state, 2);
  4062. lua_interface->ResetFunctionStack(state);
  4063. if (quest && description.length() > 0)
  4064. quest->SetDescription(description);
  4065. return 0;
  4066. }
  4067. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4068. if (!lua_interface)
  4069. return 0;
  4070. Quest* quest = lua_interface->GetQuest(state);
  4071. string description = lua_interface->GetStringValue(state, 2);
  4072. lua_interface->ResetFunctionStack(state);
  4073. if (quest && description.length() > 0)
  4074. quest->SetCompletedDescription(description);
  4075. return 0;
  4076. }
  4077. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4078. if (!lua_interface)
  4079. return 0;
  4080. Quest* quest = lua_interface->GetQuest(state);
  4081. int32 step = lua_interface->GetInt32Value(state, 2);
  4082. string description = lua_interface->GetStringValue(state, 3);
  4083. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4084. lua_interface->ResetFunctionStack(state);
  4085. if (quest && step > 0 && description.length() > 0) {
  4086. quest->SetTaskGroupDescription(step, description, display_bullets);
  4087. /* if (quest->GetPlayer()) {
  4088. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4089. if (client)
  4090. client->SendQuestUpdateStep(quest, step, false);
  4091. }*/
  4092. }
  4093. return 0;
  4094. }
  4095. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4096. if (!lua_interface)
  4097. return 0;
  4098. Quest* quest = lua_interface->GetQuest(state);
  4099. int32 step = lua_interface->GetInt32Value(state, 2);
  4100. string description = lua_interface->GetStringValue(state, 3);
  4101. lua_interface->ResetFunctionStack(state);
  4102. if (quest && step > 0 && description.length() > 0) {
  4103. quest->SetStepDescription(step, description);
  4104. /*if (quest->GetPlayer()) {
  4105. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4106. if (client)
  4107. client->SendQuestUpdateStepImmediately(quest, step);
  4108. }*/
  4109. }
  4110. return 0;
  4111. }
  4112. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4113. Quest* quest = lua_interface->GetQuest(state);
  4114. string zone = lua_interface->GetStringValue(state, 2);
  4115. lua_interface->ResetFunctionStack(state);
  4116. if (quest && zone.length() > 0)
  4117. quest->SetZone(zone);
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4121. if (!lua_interface)
  4122. return 0;
  4123. Quest* quest = lua_interface->GetQuest(state);
  4124. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4125. lua_interface->ResetFunctionStack(state);
  4126. if (quest && spawn) {
  4127. if (spawn->IsPlayer()) {
  4128. Client* client = ((Player*)spawn)->GetClient();
  4129. if (client) {
  4130. client->AddPendingQuestReward(quest);
  4131. }
  4132. }
  4133. }
  4134. return 0;
  4135. }
  4136. int EQ2Emu_lua_Harvest(lua_State* state) {
  4137. if (!lua_interface)
  4138. return 0;
  4139. Spawn* player = lua_interface->GetSpawn(state);
  4140. Spawn* node = lua_interface->GetSpawn(state, 2);
  4141. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4142. Client* client = ((Player*)player)->GetClient();
  4143. if (client) {
  4144. ((GroundSpawn*)node)->ProcessHarvest(client);
  4145. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4146. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4147. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4148. }
  4149. }
  4150. }
  4151. else if (player && player->IsPlayer()) {
  4152. Client* client = ((Player*)player)->GetClient();
  4153. if (client)
  4154. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4155. }
  4156. lua_interface->ResetFunctionStack(state);
  4157. return 0;
  4158. }
  4159. int EQ2Emu_lua_Bind(lua_State* state) {
  4160. if (!lua_interface)
  4161. return 0;
  4162. Spawn* spawn = lua_interface->GetSpawn(state);
  4163. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4164. float x = lua_interface->GetFloatValue(state, 3);
  4165. float y = lua_interface->GetFloatValue(state, 4);
  4166. float z = lua_interface->GetFloatValue(state, 5);
  4167. float h = lua_interface->GetFloatValue(state, 6);
  4168. lua_interface->ResetFunctionStack(state);
  4169. if (!spawn) {
  4170. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4171. return 0;
  4172. }
  4173. if (!spawn->IsPlayer()) {
  4174. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4175. return 0;
  4176. }
  4177. if (zone_id == 0) {
  4178. Client* client = ((Player*)spawn)->GetClient();
  4179. if (!client) {
  4180. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4181. return 0;
  4182. }
  4183. if (!client->Bind())
  4184. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4185. }
  4186. else {
  4187. Player* player = (Player*)spawn;
  4188. player->GetPlayerInfo()->SetBindZone(zone_id);
  4189. player->GetPlayerInfo()->SetBindX(x);
  4190. player->GetPlayerInfo()->SetBindY(y);
  4191. player->GetPlayerInfo()->SetBindZ(z);
  4192. player->GetPlayerInfo()->SetBindHeading(h);
  4193. }
  4194. return 0;
  4195. }
  4196. int EQ2Emu_lua_Gate(lua_State* state) {
  4197. if (!lua_interface)
  4198. return 0;
  4199. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4200. Spawn* spawn = lua_interface->GetSpawn(state);
  4201. lua_interface->ResetFunctionStack(state);
  4202. if (spawn) {
  4203. if (spawn->IsPlayer()) {
  4204. Client* client = ((Player*)spawn)->GetClient();
  4205. if (client) {
  4206. if (!client->Gate((spell != nullptr) ? true : false))
  4207. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4208. }
  4209. }
  4210. }
  4211. return 0;
  4212. }
  4213. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4214. if (!lua_interface)
  4215. return 0;
  4216. bool ret = false;
  4217. Spawn* spawn = lua_interface->GetSpawn(state);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (spawn) {
  4220. if (spawn->IsPlayer()) {
  4221. Client* client = ((Player*)spawn)->GetClient();
  4222. if (client)
  4223. ret = client->BindAllowed();
  4224. }
  4225. }
  4226. lua_interface->SetBooleanValue(state, ret);
  4227. return 1;
  4228. }
  4229. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4230. if (!lua_interface)
  4231. return 0;
  4232. bool ret = false;
  4233. Spawn* spawn = lua_interface->GetSpawn(state);
  4234. lua_interface->ResetFunctionStack(state);
  4235. if (spawn) {
  4236. if (spawn->IsPlayer()) {
  4237. Client* client = ((Player*)spawn)->GetClient();
  4238. ZoneServer* zone = lua_interface->GetZone(state);
  4239. if (client && zone){
  4240. ret = zone->GetCanGate();
  4241. }
  4242. }
  4243. }
  4244. lua_interface->SetBooleanValue(state, ret);
  4245. return 1;
  4246. }
  4247. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4248. Spawn* spawn = lua_interface->GetSpawn(state);
  4249. lua_interface->ResetFunctionStack(state);
  4250. if (spawn) {
  4251. lua_interface->SetBooleanValue(state, spawn->Alive());
  4252. return 1;
  4253. }
  4254. return 0;
  4255. }
  4256. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4257. if (!lua_interface)
  4258. return 0;
  4259. Spawn* spawn = lua_interface->GetSpawn(state);
  4260. lua_interface->ResetFunctionStack(state);
  4261. if (spawn && spawn->IsEntity()) {
  4262. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4263. return 1;
  4264. }
  4265. return 0;
  4266. }
  4267. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4268. Spawn* spawn = lua_interface->GetSpawn(state);
  4269. string message = lua_interface->GetStringValue(state, 2);
  4270. string color_str = lua_interface->GetStringValue(state, 3);
  4271. lua_interface->ResetFunctionStack(state);
  4272. int8 color = CHANNEL_NARRATIVE;
  4273. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4274. Client* client = ((Player*)spawn)->GetClient();
  4275. if (client) {
  4276. if (color_str.length() > 0) {
  4277. // leave for backwards compat, but all future should just use the number
  4278. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4279. color = CHANNEL_COLOR_RED;
  4280. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4281. color = CHANNEL_COLOR_YELLOW;
  4282. else
  4283. {
  4284. // use a number to specify the channel as per Commands/Commands.h defines
  4285. color = (int8)atoul(color_str.c_str());
  4286. }
  4287. }
  4288. client->SimpleMessage(color, message.c_str());
  4289. }
  4290. }
  4291. return 0;
  4292. }
  4293. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4294. Spawn* spawn = lua_interface->GetSpawn(state);
  4295. string message = lua_interface->GetStringValue(state, 2);
  4296. int8 red = lua_interface->GetInt8Value(state, 3);
  4297. int8 green = lua_interface->GetInt8Value(state, 4);
  4298. int8 blue = lua_interface->GetInt8Value(state, 5);
  4299. lua_interface->ResetFunctionStack(state);
  4300. if (!spawn) {
  4301. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4302. return 0;
  4303. }
  4304. if (!spawn->IsPlayer()) {
  4305. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4306. return 0;
  4307. }
  4308. int32 words = ::CountWordsInString(message.c_str());
  4309. if (words < 5)
  4310. words = 5;
  4311. Client* client = ((Player*)spawn)->GetClient();
  4312. if (client)
  4313. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4317. Spawn* spawn = lua_interface->GetSpawn(state);
  4318. int8 param = lua_interface->GetInt8Value(state, 2);
  4319. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4320. int8 value = lua_interface->GetInt8Value(state, 4);
  4321. lua_interface->ResetFunctionStack(state);
  4322. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4323. Client* client = ((Player*)spawn)->GetClient();
  4324. if (client) {
  4325. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4326. switch (param) {
  4327. case 1: {
  4328. packet->setDataByName("parameter1", param_value);
  4329. break;
  4330. }
  4331. case 2: {
  4332. packet->setDataByName("parameter2", param_value);
  4333. break;
  4334. }
  4335. case 3: {
  4336. packet->setDataByName("parameter3", param_value);
  4337. break;
  4338. }
  4339. case 4: {
  4340. packet->setDataByName("parameter4", param_value);
  4341. break;
  4342. }
  4343. case 5: {
  4344. packet->setDataByName("parameter5", param_value);
  4345. break;
  4346. }
  4347. }
  4348. packet->setDataByName("value", value);
  4349. client->QueuePacket(packet->serialize());
  4350. safe_delete(packet);
  4351. }
  4352. }
  4353. return 0;
  4354. }
  4355. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4356. Spawn* spawn = lua_interface->GetSpawn(state);
  4357. lua_interface->ResetFunctionStack(state);
  4358. if (spawn && spawn->IsPlayer()) {
  4359. if (((Player*)spawn)->GetIsTracking())
  4360. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4361. else
  4362. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4363. }
  4364. return 0;
  4365. }
  4366. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4367. Spawn* player = lua_interface->GetSpawn(state);
  4368. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4369. string name = lua_interface->GetStringValue(state, 3);
  4370. float distance = lua_interface->GetFloatValue(state, 4);
  4371. string command = lua_interface->GetStringValue(state, 5);
  4372. string error_text = lua_interface->GetStringValue(state, 6);
  4373. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4374. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4375. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4376. lua_interface->ResetFunctionStack(state);
  4377. if (spawn) {
  4378. if (distance == 0)
  4379. distance = 10.0f;
  4380. if (command.length() == 0)
  4381. command = name;
  4382. if (command.length() < 1 && name.length() < 1)
  4383. {
  4384. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4385. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4386. spawn->RemovePrimaryCommands();
  4387. }
  4388. else
  4389. {
  4390. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4391. }
  4392. }
  4393. return 0;
  4394. }
  4395. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4396. if (!lua_interface)
  4397. return 0;
  4398. Spawn* player = lua_interface->GetSpawn(state);
  4399. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4400. int16 tier = lua_interface->GetInt16Value(state, 3);
  4401. lua_interface->ResetFunctionStack(state);
  4402. if (player && player->IsPlayer()) {
  4403. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4404. return 1;
  4405. }
  4406. return 0;
  4407. }
  4408. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4409. if (!lua_interface)
  4410. return 0;
  4411. Spawn* player = lua_interface->GetSpawn(state);
  4412. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4413. int16 tier = lua_interface->GetInt16Value(state, 3);
  4414. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4415. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4416. bool add_to_hotbar = true;
  4417. if (num_args > 4) {
  4418. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4419. }
  4420. lua_interface->ResetFunctionStack(state);
  4421. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4422. if (player && spell && player->IsPlayer()) {
  4423. Client* client = player->GetClient();
  4424. if (client) {
  4425. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4426. {
  4427. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4428. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4429. client->GetPlayer()->UnlockSpell(spell);
  4430. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4431. }
  4432. else
  4433. {
  4434. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4435. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4436. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4437. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4438. client->GetPlayer()->UnlockSpell(spell);
  4439. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4440. }
  4441. //if (client ) {
  4442. // ((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);
  4443. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4444. if (outapp)
  4445. client->QueuePacket(outapp);
  4446. }
  4447. }
  4448. return 0;
  4449. }
  4450. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4451. if (!lua_interface)
  4452. return 0;
  4453. Spawn* player = lua_interface->GetSpawn(state);
  4454. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4455. lua_interface->ResetFunctionStack(state);
  4456. if (player && player->IsPlayer()) {
  4457. Client* client = player->GetClient();
  4458. if (client) {
  4459. ((Player*)player)->DeleteSpellBook(type_selection);
  4460. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4461. if (outapp)
  4462. client->QueuePacket(outapp);
  4463. }
  4464. }
  4465. return 0;
  4466. }
  4467. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4468. if (!lua_interface)
  4469. return 0;
  4470. Spawn* player = lua_interface->GetSpawn(state);
  4471. lua_interface->ResetFunctionStack(state);
  4472. if (player && player->IsPlayer()) {
  4473. Client* client = player->GetClient();
  4474. if (client) {
  4475. client->SendNewAdventureSpells();
  4476. }
  4477. }
  4478. return 0;
  4479. }
  4480. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4481. if (!lua_interface)
  4482. return 0;
  4483. Spawn* player = lua_interface->GetSpawn(state);
  4484. lua_interface->ResetFunctionStack(state);
  4485. if (player && player->IsPlayer()) {
  4486. Client* client = player->GetClient();
  4487. if (client) {
  4488. client->SendNewTradeskillSpells();
  4489. }
  4490. }
  4491. return 0;
  4492. }
  4493. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4494. if (!lua_interface)
  4495. return 0;
  4496. Spawn* player = lua_interface->GetSpawn(state);
  4497. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4498. lua_interface->ResetFunctionStack(state);
  4499. if (player && player->IsPlayer()) {
  4500. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4501. Client* client = player->GetClient();
  4502. if (sbe && client) {
  4503. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4504. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4505. if (outapp)
  4506. client->QueuePacket(outapp);
  4507. }
  4508. }
  4509. return 0;
  4510. }
  4511. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4512. if (!lua_interface)
  4513. return 0;
  4514. Spawn* player = lua_interface->GetSpawn(state);
  4515. lua_interface->ResetFunctionStack(state);
  4516. if (player && player->IsPlayer()) {
  4517. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4518. return 1;
  4519. }
  4520. return 0;
  4521. }
  4522. int EQ2Emu_lua_Attack(lua_State* state) {
  4523. if (lua_interface) {
  4524. Spawn* npc = lua_interface->GetSpawn(state);
  4525. Spawn* player = lua_interface->GetSpawn(state, 2);
  4526. lua_interface->ResetFunctionStack(state);
  4527. if (npc && player && npc->IsNPC() && player->IsEntity())
  4528. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4529. }
  4530. return 0;
  4531. }
  4532. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4533. if (lua_interface) {
  4534. Spawn* target = lua_interface->GetSpawn(state);
  4535. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4536. lua_interface->ResetFunctionStack(state);
  4537. if (target && target->GetZone())
  4538. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4539. }
  4540. return 0;
  4541. }
  4542. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4543. Spawn* player;
  4544. if (lua_interface) {
  4545. player = lua_interface->GetSpawn(state);
  4546. lua_interface->ResetFunctionStack(state);
  4547. if (player && player->IsPlayer()) {
  4548. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4549. return 1;
  4550. }
  4551. }
  4552. return 0;
  4553. }
  4554. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4555. Spawn* player;
  4556. Client* client;
  4557. if (lua_interface) {
  4558. player = lua_interface->GetSpawn(state);
  4559. lua_interface->ResetFunctionStack(state);
  4560. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4561. if ((client = ((Player*)player)->GetClient()))
  4562. client->HandInCollections();
  4563. }
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4567. Spawn* widget;
  4568. if (lua_interface) {
  4569. widget = lua_interface->GetSpawn(state);
  4570. lua_interface->ResetFunctionStack(state);
  4571. if (widget && widget->IsWidget())
  4572. ((Widget*)widget)->HandleUse(nullptr, "");
  4573. }
  4574. return 0;
  4575. }
  4576. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4577. Spawn* spawn = 0;
  4578. int32 primary_list = 0;
  4579. int32 secondary_list = 0;
  4580. if (lua_interface) {
  4581. spawn = lua_interface->GetSpawn(state);
  4582. primary_list = lua_interface->GetInt32Value(state, 2);
  4583. secondary_list = lua_interface->GetInt32Value(state, 3);
  4584. lua_interface->ResetFunctionStack(state);
  4585. if (!spawn->IsNPC()) {
  4586. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4587. return 0;
  4588. }
  4589. NPC* npc = (NPC*)spawn;
  4590. npc->SetPrimarySpellList(primary_list);
  4591. npc->SetSecondarySpellList(secondary_list);
  4592. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4593. }
  4594. return 0;
  4595. }
  4596. int EQ2Emu_lua_GetPet(lua_State* state) {
  4597. if (!lua_interface)
  4598. return 0;
  4599. Spawn* spawn = lua_interface->GetSpawn(state);
  4600. lua_interface->ResetFunctionStack(state);
  4601. if (spawn) {
  4602. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4603. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4604. return 1;
  4605. }
  4606. }
  4607. return 0;
  4608. }
  4609. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4610. if (!lua_interface)
  4611. return 0;
  4612. Spawn* spawn = lua_interface->GetSpawn(state);
  4613. lua_interface->ResetFunctionStack(state);
  4614. if (spawn) {
  4615. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4616. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4617. return 1;
  4618. }
  4619. }
  4620. return 0;
  4621. }
  4622. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4623. if (!lua_interface)
  4624. return 0;
  4625. Spawn* spawn = lua_interface->GetSpawn(state);
  4626. lua_interface->ResetFunctionStack(state);
  4627. if (spawn) {
  4628. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4629. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4630. return 1;
  4631. }
  4632. }
  4633. return 0;
  4634. }
  4635. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4636. if (!lua_interface)
  4637. return 0;
  4638. Spawn* spawn = lua_interface->GetSpawn(state);
  4639. lua_interface->ResetFunctionStack(state);
  4640. if (spawn) {
  4641. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4642. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4643. return 1;
  4644. }
  4645. }
  4646. return 0;
  4647. }
  4648. int EQ2Emu_lua_Charm(lua_State* state) {
  4649. if (!lua_interface)
  4650. return 0;
  4651. Spawn* owner = lua_interface->GetSpawn(state);
  4652. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4653. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4654. lua_interface->ResetFunctionStack(state);
  4655. if (!luaspell) {
  4656. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4657. return 0;
  4658. }
  4659. if(luaspell->resisted) {
  4660. return 0;
  4661. }
  4662. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4663. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4664. pet->SetPet(true);
  4665. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4666. ((NPC*)pet)->SetOwner((Entity*)owner);
  4667. // If owner is player and player does not have a summoned pet set the players charsheet
  4668. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4669. Player* player = (Player*)owner;
  4670. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4671. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4672. player->GetInfoStruct()->set_pet_movement(2);
  4673. player->GetInfoStruct()->set_pet_behavior(3);
  4674. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4675. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4676. // Make sure the values get sent to the client
  4677. player->SetCharSheetChanged(true);
  4678. }
  4679. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4680. pet->SetSpawnScript("");
  4681. // Set faction to the same as the owner
  4682. pet->SetFactionID(owner->GetFactionID());
  4683. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4684. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4685. // Clear hate list
  4686. ((NPC*)pet)->Brain()->ClearHate();
  4687. // Set the brain to a pet brain
  4688. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4689. }
  4690. return 0;
  4691. }
  4692. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4693. if (!lua_interface)
  4694. return 0;
  4695. Spawn* spawn = lua_interface->GetSpawn(state);
  4696. lua_interface->ResetFunctionStack(state);
  4697. if (!spawn) {
  4698. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4699. return 0;
  4700. }
  4701. vector<Spawn*> groupMembers;
  4702. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4703. groupMembers = *spawn->GetSpawnGroup();
  4704. }
  4705. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4706. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4707. deque<GroupMemberInfo*>::iterator itr;
  4708. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4709. if (group)
  4710. {
  4711. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4712. deque<GroupMemberInfo*>* members = group->GetMembers();
  4713. GroupMemberInfo* info = 0;
  4714. for (itr = members->begin(); itr != members->end(); itr++) {
  4715. info = *itr;
  4716. if (info->client)
  4717. groupMembers.push_back(info->client->GetPlayer());
  4718. }
  4719. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4720. }
  4721. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4722. }
  4723. else
  4724. return 0;
  4725. lua_createtable(state, groupMembers.size(), 0);
  4726. int newTable = lua_gettop(state);
  4727. for (int32 i = 0; i < groupMembers.size(); i++) {
  4728. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4729. lua_rawseti(state, newTable, i + 1);
  4730. }
  4731. return 1;
  4732. }
  4733. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4734. if (!lua_interface)
  4735. return 0;
  4736. lua_interface->ResetFunctionStack(state);
  4737. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4738. lua_interface->SetOptionWindowValue(state, option_window);
  4739. return 1;
  4740. }
  4741. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4742. if (!lua_interface)
  4743. return 0;
  4744. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4745. if (option_window) {
  4746. OptionWindowOption option_window_option;
  4747. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4748. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4749. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4750. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4751. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4752. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4753. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4754. option_window->push_back(option_window_option);
  4755. }
  4756. lua_interface->ResetFunctionStack(state);
  4757. return 0;
  4758. }
  4759. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4760. if (!lua_interface)
  4761. return 0;
  4762. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4763. Spawn* player = lua_interface->GetSpawn(state, 2);
  4764. string window_title = lua_interface->GetStringValue(state, 3);
  4765. string cancel_command = lua_interface->GetStringValue(state, 4);
  4766. lua_interface->ResetFunctionStack(state);
  4767. if (!player->IsPlayer()) {
  4768. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4769. return 0;
  4770. }
  4771. Client* client = ((Player*)player)->GetClient();
  4772. if (option_window && window_title.length() > 0 && client) {
  4773. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4774. if (!packet)
  4775. return 0;
  4776. packet->setDataByName("title_text", window_title.c_str());
  4777. if (cancel_command.length() > 0)
  4778. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4779. packet->setArrayLengthByName("num_selections", option_window->size());
  4780. vector<OptionWindowOption>::iterator itr;
  4781. int8 i = 0;
  4782. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4783. OptionWindowOption opt = *itr;
  4784. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4785. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4786. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4787. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4788. if (opt.optionCommand.length() > 0)
  4789. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4790. if (opt.optionConfirmTitle.length() > 0)
  4791. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4792. i++;
  4793. }
  4794. client->QueuePacket(packet->serialize());
  4795. lua_interface->SetLuaUserDataStale(option_window);
  4796. safe_delete(option_window);
  4797. safe_delete(packet);
  4798. }
  4799. return 0;
  4800. }
  4801. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4802. if (!lua_interface)
  4803. return 0;
  4804. Spawn* spawn = lua_interface->GetSpawn(state);
  4805. lua_interface->ResetFunctionStack(state);
  4806. if (spawn) {
  4807. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4808. return 1;
  4809. }
  4810. else
  4811. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4812. return 0;
  4813. }
  4814. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4815. if (!lua_interface)
  4816. return 0;
  4817. Spawn* spawn = lua_interface->GetSpawn(state);
  4818. lua_interface->ResetFunctionStack(state);
  4819. if (spawn) {
  4820. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4821. return 1;
  4822. }
  4823. else
  4824. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4825. return 0;
  4826. }
  4827. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4828. if (!lua_interface)
  4829. return 0;
  4830. Spawn* spawn = lua_interface->GetSpawn(state);
  4831. lua_interface->ResetFunctionStack(state);
  4832. if (spawn) {
  4833. int8 class_id = spawn->GetTradeskillClass();
  4834. // Need to add 42 for the offset in the array
  4835. class_id += 44;
  4836. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4837. return 1;
  4838. }
  4839. else
  4840. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4841. return 0;
  4842. }
  4843. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4844. if (!lua_interface)
  4845. return 0;
  4846. Spawn* spawn = lua_interface->GetSpawn(state);
  4847. int16 level = lua_interface->GetInt8Value(state, 2);
  4848. lua_interface->ResetFunctionStack(state);
  4849. if (spawn) {
  4850. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4851. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4852. else
  4853. spawn->SetTSLevel(level);
  4854. }
  4855. else
  4856. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4857. return 0;
  4858. }
  4859. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4860. if (!lua_interface)
  4861. return 0;
  4862. Spawn* spawn = lua_interface->GetSpawn(state);
  4863. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4864. lua_interface->ResetFunctionStack(state);
  4865. if (spawn) {
  4866. spawn->SetAttackable(attackable);
  4867. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4868. }
  4869. return 0;
  4870. }
  4871. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4872. // Check to see if we have a valid lua_interface
  4873. if (!lua_interface)
  4874. return 0;
  4875. // Get the spawn that is getting the pet
  4876. Spawn* spawn = lua_interface->GetSpawn(state);
  4877. // Get the DB ID of the pet
  4878. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4879. // The max level the pet can gain
  4880. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4881. // Get the spell that this command was called from
  4882. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4883. lua_interface->ResetFunctionStack(state);
  4884. // Check to make sure the spawn pointer is valid
  4885. if (!spawn) {
  4886. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4887. return 0;
  4888. }
  4889. // Check to make sure the spawn is an entity
  4890. if (!spawn->IsEntity()) {
  4891. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4892. return 0;
  4893. }
  4894. // Check to make sure the spawn doesn't already have a pet of this type
  4895. if (((Entity*)spawn)->GetPet()) {
  4896. if (spawn->IsPlayer()) {
  4897. Client* client = ((Player*)spawn)->GetClient();
  4898. if (client)
  4899. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4900. }
  4901. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4902. return 0;
  4903. }
  4904. // Check to see if the DB ID for the pet is set
  4905. if (pet_id == 0) {
  4906. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4907. return 0;
  4908. }
  4909. // Check to see if the pointer to the spell is valid
  4910. if (!luaspell) {
  4911. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4912. return 0;
  4913. }
  4914. if(luaspell->resisted) {
  4915. return 0;
  4916. }
  4917. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4918. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4919. if (!pet) {
  4920. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4921. return 0;
  4922. }
  4923. // Check to make sure the pet is an npc
  4924. if (!pet->IsNPC()) {
  4925. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4926. return 0;
  4927. }
  4928. // Spawn the pet at the same location as the owner
  4929. pet->SetX(spawn->GetX());
  4930. pet->SetY(spawn->GetY());
  4931. pet->SetZ(spawn->GetZ());
  4932. pet->SetLocation(spawn->GetLocation());
  4933. pet->SetHeading(spawn->GetHeading());
  4934. std::string petName = std::string("");
  4935. if(spawn->IsEntity()) {
  4936. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4937. }
  4938. if(petName.size() < 1) {
  4939. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4940. petName = spawn->GetZone()->pet_names.at(rand_index);
  4941. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4942. }
  4943. // If player set various values for the char sheet (pet window)
  4944. if (spawn->IsPlayer()) {
  4945. Player* player = (Player*)spawn;
  4946. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4947. player->GetInfoStruct()->set_pet_name(petName);
  4948. player->GetInfoStruct()->set_pet_movement(2);
  4949. player->GetInfoStruct()->set_pet_behavior(3);
  4950. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4951. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4952. // Make sure the values get sent to the client
  4953. player->SetCharSheetChanged(true);
  4954. }
  4955. // Set the pets name
  4956. pet->SetName(petName.c_str());
  4957. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4958. if (max_level > 0)
  4959. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4960. else
  4961. pet->SetLevel(spawn->GetLevel());
  4962. // Set the max level this pet can reach
  4963. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4964. ((NPC*)pet)->UpdateWeapons();
  4965. // Set the faction of the pet to the same faction as the owner
  4966. pet->SetFactionID(spawn->GetFactionID());
  4967. // Set the spawn as a pet
  4968. pet->SetPet(true);
  4969. // Give a pointer of the owner to the pet
  4970. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4971. // Give a pointer of the pet to the owner
  4972. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4973. // Set the pet type
  4974. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4975. // Set the spell id used to create this pet
  4976. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4977. // Set the spell tier used to create this pet
  4978. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4979. // Set the pets spawn type to 6
  4980. pet->SetSpawnType(6);
  4981. // Set the pets brain
  4982. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4983. // Check to see if the pet has a subtitle
  4984. if (strlen(pet->GetSubTitle()) > 0) {
  4985. // Add the players name to the front of the sub title
  4986. string pet_subtitle;
  4987. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4988. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4989. // Set the pets subtitle to the new one
  4990. pet->SetSubTitle(pet_subtitle.c_str());
  4991. }
  4992. // Add the "Pet Options" entity command to the pet
  4993. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4994. const char* spawn_script = world.GetSpawnScript(pet_id);
  4995. bool runScript = false;
  4996. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4997. runScript = true;
  4998. pet->SetSpawnScript(string(spawn_script));
  4999. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5000. }
  5001. spawn->GetZone()->AddSpawn(pet);
  5002. if(runScript){
  5003. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5004. }
  5005. // Set the pet as the return value for this function
  5006. lua_interface->SetSpawnValue(state, pet);
  5007. return 1;
  5008. }
  5009. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5010. if (!lua_interface)
  5011. return 0;
  5012. Spawn* spawn = lua_interface->GetSpawn(state);
  5013. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5014. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5015. lua_interface->ResetFunctionStack(state);
  5016. if (!spawn) {
  5017. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5018. return 0;
  5019. }
  5020. if (!spawn->IsEntity()) {
  5021. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5022. return 0;
  5023. }
  5024. if (((Entity*)spawn)->GetDeityPet()) {
  5025. if (spawn->IsPlayer()) {
  5026. Client* client = ((Player*)spawn)->GetClient();
  5027. if (client)
  5028. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5029. }
  5030. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5031. return 0;
  5032. }
  5033. if (pet_id == 0) {
  5034. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5035. return 0;
  5036. }
  5037. if (!luaspell) {
  5038. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5039. return 0;
  5040. }
  5041. if(luaspell->resisted) {
  5042. return 0;
  5043. }
  5044. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5045. if (!pet) {
  5046. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5047. return 0;
  5048. }
  5049. if (!pet->IsNPC()) {
  5050. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5051. return 0;
  5052. }
  5053. pet->SetX(spawn->GetX());
  5054. pet->SetY(spawn->GetY());
  5055. pet->SetZ(spawn->GetZ());
  5056. pet->SetLocation(spawn->GetLocation());
  5057. pet->SetHeading(spawn->GetHeading());
  5058. spawn->GetZone()->AddSpawn(pet);
  5059. string random_pet_name;
  5060. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5061. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5062. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5063. pet->SetName(random_pet_name.c_str());
  5064. pet->SetLevel(spawn->GetLevel());
  5065. pet->SetFactionID(spawn->GetFactionID());
  5066. pet->SetPet(true);
  5067. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5068. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5069. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5070. pet->SetSpawnType(6);
  5071. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5072. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5073. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5074. if (strlen(pet->GetSubTitle()) > 0) {
  5075. string pet_subtitle;
  5076. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5077. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5078. pet->SetSubTitle(pet_subtitle.c_str());
  5079. }
  5080. // deity and cosmetic pets are not attackable
  5081. pet->SetAttackable(false);
  5082. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5083. lua_interface->SetSpawnValue(state, pet);
  5084. return 1;
  5085. }
  5086. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5087. if (!lua_interface)
  5088. return 0;
  5089. Spawn* spawn = lua_interface->GetSpawn(state);
  5090. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5091. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5092. lua_interface->ResetFunctionStack(state);
  5093. if (!spawn) {
  5094. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5095. return 0;
  5096. }
  5097. if (!spawn->IsEntity()) {
  5098. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5099. return 0;
  5100. }
  5101. if (((Entity*)spawn)->GetCosmeticPet()) {
  5102. if (spawn->IsPlayer()) {
  5103. Client* client = ((Player*)spawn)->GetClient();
  5104. if (client)
  5105. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5106. }
  5107. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5108. return 0;
  5109. }
  5110. if (pet_id == 0) {
  5111. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5112. return 0;
  5113. }
  5114. if (!luaspell) {
  5115. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5116. return 0;
  5117. }
  5118. if(luaspell->resisted) {
  5119. return 0;
  5120. }
  5121. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5122. if (!pet) {
  5123. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5124. return 0;
  5125. }
  5126. if (!pet->IsNPC()) {
  5127. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5128. return 0;
  5129. }
  5130. pet->SetX(spawn->GetX());
  5131. pet->SetY(spawn->GetY());
  5132. pet->SetZ(spawn->GetZ());
  5133. pet->SetLocation(spawn->GetLocation());
  5134. pet->SetHeading(spawn->GetHeading());
  5135. spawn->GetZone()->AddSpawn(pet);
  5136. string random_pet_name;
  5137. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5138. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5139. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5140. pet->SetName(random_pet_name.c_str());
  5141. pet->SetLevel(spawn->GetLevel());
  5142. pet->SetFactionID(spawn->GetFactionID());
  5143. pet->SetPet(true);
  5144. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5145. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5146. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5147. pet->SetSpawnType(6);
  5148. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5149. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5150. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5151. if (strlen(pet->GetSubTitle()) > 0) {
  5152. string pet_subtitle;
  5153. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5154. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5155. pet->SetSubTitle(pet_subtitle.c_str());
  5156. }
  5157. pet->SetAttackable(false);
  5158. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5159. lua_interface->SetSpawnValue(state, pet);
  5160. return 1;
  5161. }
  5162. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5163. if (!lua_interface)
  5164. return 0;
  5165. Spawn* spawn = lua_interface->GetSpawn(state);
  5166. lua_interface->ResetFunctionStack(state);
  5167. if (!spawn) {
  5168. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5169. return 0;
  5170. }
  5171. if (!spawn->IsPet()) {
  5172. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5173. return 0;
  5174. }
  5175. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5176. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5177. return 0;
  5178. }
  5179. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5180. if (!lua_interface)
  5181. return 0;
  5182. Quest* quest = lua_interface->GetQuest(state);
  5183. if (!quest) {
  5184. 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));
  5185. lua_interface->ResetFunctionStack(state);
  5186. return 0;
  5187. }
  5188. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5189. lua_interface->ResetFunctionStack(state);
  5190. if (feather_color > 0)
  5191. quest->SetFeatherColor(feather_color);
  5192. return 0;
  5193. }
  5194. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5195. if (!lua_interface)
  5196. return 0;
  5197. Spawn* spawn = lua_interface->GetSpawn(state);
  5198. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5199. lua_interface->ResetFunctionStack(state);
  5200. if (!spawn) {
  5201. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. if (!spawn2) {
  5205. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5206. return 0;
  5207. }
  5208. spawn->RemoveSpawnAccess(spawn2);
  5209. return 0;
  5210. }
  5211. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5212. if (!lua_interface)
  5213. return 0;
  5214. ZoneServer* zone = lua_interface->GetZone(state);
  5215. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5216. lua_interface->ResetFunctionStack(state);
  5217. if (!zone) {
  5218. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5219. return 0;
  5220. }
  5221. if (location_id == 0) {
  5222. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5223. return 0;
  5224. }
  5225. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5226. if (!location) {
  5227. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5228. return 0;
  5229. }
  5230. Spawn* spawn = 0;
  5231. if (location->entities[0]) {
  5232. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5233. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5234. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5235. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5236. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5237. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5238. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5239. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5240. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5241. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5242. if(spawn && spawn->IsOmittedByDBFlag())
  5243. {
  5244. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5245. safe_delete(spawn);
  5246. spawn = 0;
  5247. return 0;
  5248. }
  5249. if (spawn) {
  5250. const char* script = 0;
  5251. for (int x = 0; x < 3; x++) {
  5252. switch (x) {
  5253. case 0:
  5254. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5255. break;
  5256. case 1:
  5257. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5258. break;
  5259. case 2:
  5260. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5261. break;
  5262. }
  5263. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5264. spawn->SetSpawnScript(string(script));
  5265. break;
  5266. }
  5267. }
  5268. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5269. lua_interface->SetSpawnValue(state, spawn);
  5270. return 1;
  5271. }
  5272. else {
  5273. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5274. safe_delete(spawn);
  5275. }
  5276. }
  5277. return 0;
  5278. }
  5279. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5280. if (!lua_interface)
  5281. return 0;
  5282. Spawn* caster = lua_interface->GetSpawn(state);
  5283. Spawn* target = lua_interface->GetSpawn(state, 2);
  5284. int32 id = lua_interface->GetInt32Value(state, 3);
  5285. string command = lua_interface->GetStringValue(state, 4);
  5286. lua_interface->ResetFunctionStack(state);
  5287. if (!caster) {
  5288. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5289. return 0;
  5290. }
  5291. if (!target) {
  5292. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5293. return 0;
  5294. }
  5295. if (!caster->IsPlayer()) {
  5296. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5297. return 0;
  5298. }
  5299. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5300. if (!entity_command) {
  5301. 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());
  5302. return 0;
  5303. }
  5304. Client* client = ((Player*)caster)->GetClient();
  5305. if (!client) {
  5306. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. Spawn* spawn = lua_interface->GetSpawn(state);
  5316. lua_interface->ResetFunctionStack(state);
  5317. if (!spawn) {
  5318. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (!spawn->IsNPC()) {
  5322. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5323. return 0;
  5324. }
  5325. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5326. return 0;
  5327. }
  5328. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5329. if (!lua_interface)
  5330. return 0;
  5331. Spawn* spawn = lua_interface->GetSpawn(state);
  5332. int16 tick = lua_interface->GetInt16Value(state, 2);
  5333. lua_interface->ResetFunctionStack(state);
  5334. if (!spawn) {
  5335. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5336. return 0;
  5337. }
  5338. if (!spawn->IsNPC()) {
  5339. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5340. return 0;
  5341. }
  5342. if (tick < 20) {
  5343. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5344. return 0;
  5345. }
  5346. ((NPC*)spawn)->Brain()->SetTick(tick);
  5347. return 0;
  5348. }
  5349. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5350. if (!lua_interface)
  5351. return 0;
  5352. Spawn* spawn = lua_interface->GetSpawn(state);
  5353. Spawn* target = lua_interface->GetSpawn(state, 2);
  5354. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5355. lua_interface->ResetFunctionStack(state);
  5356. if (!spawn) {
  5357. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5358. return 0;
  5359. }
  5360. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5361. spawn->SetFollowTarget(target, follow_distance);
  5362. return 0;
  5363. }
  5364. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5365. if (!lua_interface)
  5366. return 0;
  5367. Spawn* spawn = lua_interface->GetSpawn(state);
  5368. lua_interface->ResetFunctionStack(state);
  5369. if (!spawn) {
  5370. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5371. return 0;
  5372. }
  5373. Spawn* target = spawn->GetFollowTarget();
  5374. if (target) {
  5375. lua_interface->SetSpawnValue(state, target);
  5376. return 1;
  5377. }
  5378. return 0;
  5379. }
  5380. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5381. if (!lua_interface)
  5382. return 0;
  5383. Spawn* spawn = lua_interface->GetSpawn(state);
  5384. lua_interface->ResetFunctionStack(state);
  5385. if (!spawn) {
  5386. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5387. return 0;
  5388. }
  5389. if (spawn->following)
  5390. spawn->following = false;
  5391. else
  5392. spawn->following = true;
  5393. return 0;
  5394. }
  5395. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5396. if (!lua_interface)
  5397. return 0;
  5398. Spawn* spawn = lua_interface->GetSpawn(state);
  5399. lua_interface->ResetFunctionStack(state);
  5400. if (!spawn) {
  5401. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5402. return 0;
  5403. }
  5404. lua_interface->SetBooleanValue(state, spawn->following);
  5405. return 1;
  5406. }
  5407. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5408. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5409. // I will attempt to explain how this function works for future refrence
  5410. // Fist lets make sure lua_interface is valid, if not return out
  5411. if (!lua_interface)
  5412. return 0;
  5413. // Next we grab the first 2 params same as we usually would
  5414. Spawn* spawn = lua_interface->GetSpawn(state);
  5415. string var = lua_interface->GetStringValue(state, 2);
  5416. // 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
  5417. // 1 = Spawn
  5418. // 2 = Zone
  5419. // 3 = Item
  5420. // 4 = Quest
  5421. // 5 = String
  5422. // 6 = nil (null)
  5423. int8 dataType = 0;
  5424. // Define pointers for each potential type
  5425. Spawn* spawnVal = 0;
  5426. ZoneServer* zone = 0;
  5427. Item* item = 0;
  5428. Quest* quest = 0;
  5429. string val;
  5430. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5431. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5432. // options window are also light user data be we do not handle those.
  5433. // We check with lua_islightuserdata(lua_State*, index)
  5434. if (lua_islightuserdata(state, 3)) {
  5435. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5436. // and convert it to LUAUserData*
  5437. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5438. // Check to make sure the data we got is valid, if not give an error
  5439. if (!data || !data->IsCorrectlyInitialized()) {
  5440. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5441. }
  5442. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5443. else if (data->IsSpawn()) {
  5444. spawnVal = data->spawn;
  5445. dataType = 1;
  5446. }
  5447. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5448. else if (data->IsZone()) {
  5449. zone = data->zone;
  5450. dataType = 2;
  5451. }
  5452. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5453. else if (data->IsItem()) {
  5454. item = data->item;
  5455. dataType = 3;
  5456. }
  5457. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5458. else if (data->IsQuest()) {
  5459. quest = data->quest;
  5460. dataType = 4;
  5461. }
  5462. }
  5463. // Wasn't light user data, check if it is nil(null)
  5464. else if (lua_isnil(state, 3)) {
  5465. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5466. dataType = 6;
  5467. }
  5468. // Wasn't light user data or nil (null), must be a string
  5469. else {
  5470. // Set the string and dataType variable
  5471. val = lua_interface->GetStringValue(state, 3);
  5472. dataType = 5;
  5473. }
  5474. lua_interface->ResetFunctionStack(state);
  5475. // We now have all the params, lets check to make sure they are valid
  5476. if (!spawn) {
  5477. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. if (var.length() == 0) {
  5481. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5482. return 0;
  5483. }
  5484. if (dataType == 0) {
  5485. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5486. return 0;
  5487. }
  5488. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5489. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5490. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5491. switch (dataType) {
  5492. case 1:
  5493. // 1 = Spawn
  5494. spawn->AddTempVariable(var, spawnVal);
  5495. break;
  5496. case 2:
  5497. // 2 = Zone
  5498. spawn->AddTempVariable(var, zone);
  5499. break;
  5500. case 3:
  5501. // 3 = Item
  5502. spawn->AddTempVariable(var, item);
  5503. break;
  5504. case 4:
  5505. // 4 = Quest
  5506. spawn->AddTempVariable(var, quest);
  5507. break;
  5508. case 5:
  5509. // 5 = String
  5510. spawn->AddTempVariable(var, val);
  5511. break;
  5512. case 6:
  5513. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5514. spawn->DeleteTempVariable(var);
  5515. break;
  5516. }
  5517. // And we are done so return out
  5518. return 0;
  5519. }
  5520. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5521. if (!lua_interface)
  5522. return 0;
  5523. Spawn* spawn = lua_interface->GetSpawn(state);
  5524. string var = lua_interface->GetStringValue(state, 2);
  5525. lua_interface->ResetFunctionStack(state);
  5526. if (!spawn) {
  5527. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5528. return 0;
  5529. }
  5530. if (var.length() == 0) {
  5531. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5532. return 0;
  5533. }
  5534. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5535. int8 type = spawn->GetTempVariableType(var);
  5536. Spawn* spawn2 = 0;
  5537. ZoneServer* zone = 0;
  5538. Item* item = 0;
  5539. Quest* quest = 0;
  5540. // Set the lua function return value based on the type of data the variable contains
  5541. switch (type) {
  5542. case 1:
  5543. spawn2 = spawn->GetTempVariableSpawn(var);
  5544. if (!spawn2)
  5545. return 0;
  5546. lua_interface->SetSpawnValue(state, spawn2);
  5547. break;
  5548. case 2:
  5549. zone = spawn->GetTempVariableZone(var);
  5550. if (!zone)
  5551. return 0;
  5552. lua_interface->SetZoneValue(state, zone);
  5553. break;
  5554. case 3:
  5555. item = spawn->GetTempVariableItem(var);
  5556. if (!item)
  5557. return 0;
  5558. lua_interface->SetItemValue(state, item);
  5559. break;
  5560. case 4:
  5561. quest = spawn->GetTempVariableQuest(var);
  5562. if (!quest)
  5563. return 0;
  5564. lua_interface->SetQuestValue(state, quest);
  5565. break;
  5566. case 5:
  5567. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5568. break;
  5569. default:
  5570. // Not a valid type then the variable was not set so return out
  5571. return 0;
  5572. }
  5573. // Return value was set so return out
  5574. return 1;
  5575. }
  5576. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5577. {
  5578. if (!lua_interface)
  5579. return 0;
  5580. Quest* quest = lua_interface->GetQuest(state);
  5581. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5582. string description = lua_interface->GetStringValue(state, 3);
  5583. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5584. if (!quest) {
  5585. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5586. lua_interface->ResetFunctionStack(state);
  5587. lua_interface->SetBooleanValue(state, false);
  5588. return 1;
  5589. }
  5590. if (!spawn) {
  5591. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5592. lua_interface->ResetFunctionStack(state);
  5593. lua_interface->SetBooleanValue(state, false);
  5594. return 1;
  5595. }
  5596. if (!spawn->IsPlayer()) {
  5597. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5598. lua_interface->ResetFunctionStack(state);
  5599. lua_interface->SetBooleanValue(state, false);
  5600. return 1;
  5601. }
  5602. if (item_id == 0) {
  5603. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5604. lua_interface->ResetFunctionStack(state);
  5605. lua_interface->SetBooleanValue(state, false);
  5606. return 1;
  5607. }
  5608. Client* client = ((Player*)spawn)->GetClient();
  5609. if (!client) {
  5610. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5611. lua_interface->ResetFunctionStack(state);
  5612. lua_interface->SetBooleanValue(state, false);
  5613. return 1;
  5614. }
  5615. Item* item = master_item_list.GetItem(item_id);
  5616. if (!item) {
  5617. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5618. lua_interface->ResetFunctionStack(state);
  5619. lua_interface->SetBooleanValue(state, false);
  5620. return 1;
  5621. }
  5622. Item* firstItem = new Item(item);
  5623. quest->AddTmpRewardItem(firstItem);
  5624. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5625. bool itemsAddedSuccessfully = true;
  5626. if(num_args > 4)
  5627. {
  5628. for(int8 n=5;n<num_args+1;n++)
  5629. {
  5630. int32 new_item = lua_interface->GetInt32Value(state, n);
  5631. Item* tmpItem = master_item_list.GetItem(new_item);
  5632. if(tmpItem)
  5633. {
  5634. Item* newTmpItem = new Item(tmpItem);
  5635. quest->AddTmpRewardItem(newTmpItem);
  5636. }
  5637. else
  5638. itemsAddedSuccessfully = false;
  5639. }
  5640. }
  5641. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5642. lua_interface->ResetFunctionStack(state);
  5643. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5644. return 1;
  5645. }
  5646. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5647. if (!lua_interface)
  5648. return 0;
  5649. Quest* quest = lua_interface->GetQuest(state);
  5650. lua_interface->ResetFunctionStack(state);
  5651. if (!quest) {
  5652. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5653. return 0;
  5654. }
  5655. quest->SetRepeatable(true);
  5656. return 0;
  5657. }
  5658. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5659. if (!lua_interface)
  5660. return 0;
  5661. Spawn* spawn = lua_interface->GetSpawn(state);
  5662. lua_interface->ResetFunctionStack(state);
  5663. if (!spawn) {
  5664. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5665. return 0;
  5666. }
  5667. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5668. string ret = classes.GetClassNameCase(base_class);
  5669. if (ret.length() > 0) {
  5670. lua_interface->SetStringValue(state, ret.c_str());
  5671. return 1;
  5672. }
  5673. return 0;
  5674. }
  5675. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5676. if (!lua_interface)
  5677. return 0;
  5678. Spawn* player = lua_interface->GetSpawn(state);
  5679. lua_interface->ResetFunctionStack(state);
  5680. if (player && player->IsPlayer()) {
  5681. Client* client = player->GetClient();
  5682. if (client)
  5683. client->SendWaypoints();
  5684. }
  5685. return 0;
  5686. }
  5687. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5688. if (!lua_interface)
  5689. return 0;
  5690. Spawn* player = lua_interface->GetSpawn(state);
  5691. string name = lua_interface->GetStringValue(state, 2);
  5692. int32 type = lua_interface->GetInt32Value(state, 3);
  5693. lua_interface->ResetFunctionStack(state);
  5694. if (type == 0)
  5695. type = 2;
  5696. if (name.length() > 0) {
  5697. if (player && player->IsPlayer()) {
  5698. Client* client = player->GetClient();
  5699. if (client)
  5700. client->AddWaypoint(name, type);
  5701. }
  5702. }
  5703. return 0;
  5704. }
  5705. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5706. if (!lua_interface)
  5707. return 0;
  5708. Spawn* player = lua_interface->GetSpawn(state);
  5709. string name = lua_interface->GetStringValue(state, 2);
  5710. lua_interface->ResetFunctionStack(state);
  5711. if (name.length() > 0) {
  5712. if (player && player->IsPlayer()) {
  5713. Client* client = player->GetClient();
  5714. if (client)
  5715. client->RemoveWaypoint(name);
  5716. }
  5717. }
  5718. return 0;
  5719. }
  5720. int EQ2Emu_lua_AddWard(lua_State* state) {
  5721. if (!lua_interface)
  5722. return 0;
  5723. int32 damage = lua_interface->GetInt32Value(state);
  5724. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5725. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5726. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5727. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5728. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5729. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5730. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5731. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5732. lua_interface->ResetFunctionStack(state);
  5733. if(!spell || spell->resisted) {
  5734. return 0;
  5735. }
  5736. bool ward_was_added = false;
  5737. ZoneServer* zone = spell->caster->GetZone();
  5738. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5739. for (int32 i = 0; i < spell->targets.size(); i++) {
  5740. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5741. if (!target)
  5742. continue;
  5743. if (target->IsEntity()) {
  5744. // If the ward is already active remove it
  5745. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5746. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5747. // Create new ward info
  5748. WardInfo* ward = new WardInfo;
  5749. ward->Spell = spell;
  5750. ward->BaseDamage = damage;
  5751. ward->DamageLeft = damage;
  5752. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5753. ward->keepWard = keepWard;
  5754. ward->WardType = wardType;
  5755. if (damageAbsorptionPercent > 100)
  5756. damageAbsorptionPercent = 100;
  5757. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5758. if (damageAbsorptionMaxHealthPercent > 100)
  5759. damageAbsorptionMaxHealthPercent = 100;
  5760. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5761. ward->RedirectDamagePercent = redirectDamagePercent;
  5762. ward->LastRedirectDamage = 0;
  5763. ward->LastAbsorbedDamage = 0;
  5764. ward->HitCount = 0;
  5765. spell->num_triggers = maxHitCount;
  5766. spell->had_triggers = true;
  5767. spell->cancel_after_all_triggers = false;
  5768. ward->MaxHitCount = maxHitCount;
  5769. ward->RoundTriggered = false;
  5770. if (wardType == WARD_TYPE_MAGICAL)
  5771. ward->DamageType = damageTypes;
  5772. // Add the ward to the entity
  5773. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5774. ward_was_added = true;
  5775. }
  5776. }
  5777. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5778. if (ward_was_added && spell->caster->IsPlayer()) {
  5779. spell->had_dmg_remaining = true;
  5780. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5781. }
  5782. return 0;
  5783. }
  5784. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5785. if (!lua_interface)
  5786. return 0;
  5787. int32 amount = lua_interface->GetInt32Value(state);
  5788. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5789. lua_interface->ResetFunctionStack(state);
  5790. WardInfo* ward = 0;
  5791. if(!spell || spell->resisted) {
  5792. return 0;
  5793. }
  5794. ZoneServer* zone = spell->caster->GetZone();
  5795. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5796. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5797. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5798. ward = target->GetWard(spell->spell->GetSpellID());
  5799. if (target && ward) {
  5800. ward->DamageLeft += amount;
  5801. if (ward->DamageLeft > ward->BaseDamage)
  5802. ward->DamageLeft = ward->BaseDamage;
  5803. for (int32 i = 0; i < spell->targets.size(); i++) {
  5804. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5805. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5806. }
  5807. }
  5808. }
  5809. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5810. if (ward && spell->caster->IsPlayer())
  5811. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5812. return 0;
  5813. }
  5814. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5815. if (!lua_interface)
  5816. return 0;
  5817. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5818. lua_interface->ResetFunctionStack(state);
  5819. if (!spell) {
  5820. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5821. return 0;
  5822. }
  5823. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5824. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5825. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5826. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5827. if (ward) {
  5828. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5829. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5830. return 1;
  5831. }
  5832. }
  5833. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5834. return 0;
  5835. }
  5836. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5837. if (!lua_interface)
  5838. return 0;
  5839. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5840. if (!spell) {
  5841. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5842. lua_interface->ResetFunctionStack(state);
  5843. return 0;
  5844. }
  5845. string type = lua_interface->GetStringValue(state, 2);
  5846. lua_interface->ResetFunctionStack(state);
  5847. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5848. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5849. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5850. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5851. if (ward) {
  5852. if (boost::iequals(type, "damageleft"))
  5853. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5854. else if (boost::iequals(type, "basedamage"))
  5855. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5856. else if (boost::iequals(type, "keepward"))
  5857. lua_interface->SetBooleanValue(state, ward->keepWard);
  5858. else if (boost::iequals(type, "wardtype"))
  5859. lua_interface->SetInt32Value(state, ward->WardType);
  5860. else if (boost::iequals(type, "dmgabsorptionpct"))
  5861. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5862. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5863. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5864. else if (boost::iequals(type, "redirectdamagepercent"))
  5865. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5866. else if (boost::iequals(type, "lastredirectdamage"))
  5867. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5868. else if (boost::iequals(type, "lastabsorbeddamage"))
  5869. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5870. else if (boost::iequals(type, "hitcount"))
  5871. lua_interface->SetInt32Value(state, ward->HitCount);
  5872. else if (boost::iequals(type, "maxhitcount"))
  5873. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5874. else
  5875. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5876. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5877. return 1;
  5878. }
  5879. }
  5880. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5881. return 0;
  5882. }
  5883. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5884. if (!lua_interface)
  5885. return 0;
  5886. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5887. lua_interface->ResetFunctionStack(state);
  5888. if(!spell) {
  5889. return 0;
  5890. }
  5891. ZoneServer* zone = spell->caster->GetZone();
  5892. Spawn* target = 0;
  5893. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5894. for (int32 i = 0; i < spell->targets.size(); i++) {
  5895. target = zone->GetSpawnByID(spell->targets.at(i));
  5896. if (target && target->IsEntity()) {
  5897. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5898. }
  5899. }
  5900. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5901. return 0;
  5902. }
  5903. int EQ2Emu_lua_Interrupt(lua_State* state)
  5904. {
  5905. if (!lua_interface)
  5906. return 0;
  5907. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5908. Spawn* target = lua_interface->GetSpawn(state, 2);
  5909. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5910. lua_interface->ResetFunctionStack(state);
  5911. if (!caster)
  5912. {
  5913. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. if (!target)
  5917. {
  5918. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5919. return 0;
  5920. }
  5921. if (!spell) {
  5922. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5923. return 0;
  5924. }
  5925. if (!target->IsEntity() && !spell)
  5926. {
  5927. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. if (!target && spell) {
  5931. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5932. for (int8 i = 0; i < spell->targets.size(); i++) {
  5933. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5934. if (!target || !target->IsEntity())
  5935. continue;
  5936. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5937. }
  5938. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5939. }
  5940. else
  5941. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5942. return 0;
  5943. }
  5944. int EQ2Emu_lua_Stealth(lua_State* state) {
  5945. if (!lua_interface)
  5946. return 0;
  5947. int8 type = lua_interface->GetInt8Value(state);
  5948. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5949. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5950. lua_interface->ResetFunctionStack(state);
  5951. if (!spell) {
  5952. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. ZoneServer* zone = spell->caster->GetZone();
  5956. if (spawn) {
  5957. if (spawn->IsEntity()) {
  5958. if (type == 1) {
  5959. ((Entity*)spawn)->AddStealthSpell(spell);
  5960. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5961. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5962. }
  5963. else if (type == 2) {
  5964. ((Entity*)spawn)->AddInvisSpell(spell);
  5965. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5966. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5967. }
  5968. return 0;
  5969. }
  5970. else {
  5971. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5972. return 0;
  5973. }
  5974. }
  5975. else {
  5976. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5977. for (int32 i = 0; i < spell->targets.size(); i++) {
  5978. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5979. if (!spawn || !spawn->IsEntity())
  5980. continue;
  5981. if (type == 1) {
  5982. ((Entity*)spawn)->AddStealthSpell(spell);
  5983. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5984. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5985. }
  5986. else if (type == 2) {
  5987. ((Entity*)spawn)->AddInvisSpell(spell);
  5988. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5989. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5990. }
  5991. else {
  5992. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5993. break;
  5994. }
  5995. }
  5996. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5997. }
  5998. return 0;
  5999. }
  6000. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6001. if (!lua_interface)
  6002. return 0;
  6003. Spawn* spawn = lua_interface->GetSpawn(state);
  6004. lua_interface->ResetFunctionStack(state);
  6005. if (!spawn) {
  6006. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. if (spawn->IsEntity()) {
  6010. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6011. return 1;
  6012. }
  6013. else
  6014. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6015. return 0;
  6016. }
  6017. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6018. if (!lua_interface)
  6019. return 0;
  6020. Spawn* spawn = lua_interface->GetSpawn(state);
  6021. lua_interface->ResetFunctionStack(state);
  6022. if (!spawn) {
  6023. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. if (spawn->IsEntity()) {
  6027. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6028. return 1;
  6029. }
  6030. else
  6031. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6035. if (!lua_interface)
  6036. return 0;
  6037. Spawn* player = lua_interface->GetSpawn(state);
  6038. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6039. lua_interface->ResetFunctionStack(state);
  6040. if (!player->IsPlayer()) {
  6041. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6045. return 1;
  6046. }
  6047. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6048. if (!lua_interface)
  6049. return 0;
  6050. Spawn* spawn = lua_interface->GetSpawn(state);
  6051. int8 slot = lua_interface->GetInt8Value(state, 2);
  6052. lua_interface->ResetFunctionStack(state);
  6053. if (!spawn) {
  6054. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6055. return 0;
  6056. }
  6057. if (!spawn->IsEntity()) {
  6058. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6059. return 0;
  6060. }
  6061. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6062. if (!item) {
  6063. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. lua_interface->SetItemValue(state, item);
  6067. return 1;
  6068. }
  6069. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6070. if (!lua_interface)
  6071. return 0;
  6072. Spawn* player = lua_interface->GetSpawn(state);
  6073. int32 id = lua_interface->GetInt32Value(state, 2);
  6074. lua_interface->ResetFunctionStack(state);
  6075. if (!player) {
  6076. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6077. return 0;
  6078. }
  6079. if (!player->IsPlayer()) {
  6080. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6081. return 0;
  6082. }
  6083. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6084. if (!item) {
  6085. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. lua_interface->SetItemValue(state, item);
  6089. return 1;
  6090. }
  6091. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6092. if (!lua_interface)
  6093. return 0;
  6094. Spawn* spawn = lua_interface->GetSpawn(state);
  6095. int8 slot = lua_interface->GetInt8Value(state, 2);
  6096. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6097. lua_interface->ResetFunctionStack(state);
  6098. if (!spawn) {
  6099. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!spawn->IsEntity()) {
  6103. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. Item* item = master_item_list.GetItem(item_id);
  6107. if (!item) {
  6108. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6109. return 0;
  6110. }
  6111. Item* copy = new Item(item);
  6112. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6113. if(result)
  6114. {
  6115. ((Entity*)spawn)->SetEquipment(copy, slot);
  6116. spawn->vis_changed = true;
  6117. if(spawn->IsPlayer())
  6118. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6119. }
  6120. else
  6121. {
  6122. safe_delete(copy);
  6123. }
  6124. lua_interface->SetBooleanValue(state, result);
  6125. return 1;
  6126. }
  6127. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6128. if (!lua_interface)
  6129. return 0;
  6130. Spawn* spawn = lua_interface->GetSpawn(state);
  6131. int8 slot = lua_interface->GetInt8Value(state, 2);
  6132. Item* item = lua_interface->GetItem(state, 3);
  6133. lua_interface->ResetFunctionStack(state);
  6134. if (!spawn) {
  6135. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. if (!spawn->IsEntity()) {
  6139. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6140. return 0;
  6141. }
  6142. if (!item) {
  6143. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6147. if(result)
  6148. {
  6149. ((Entity*)spawn)->SetEquipment(item, slot);
  6150. spawn->vis_changed = true;
  6151. if(spawn->IsPlayer())
  6152. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6153. }
  6154. lua_interface->SetBooleanValue(state, result);
  6155. return 1;
  6156. }
  6157. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6158. if (!lua_interface)
  6159. return 0;
  6160. Spawn* spawn = lua_interface->GetSpawn(state);
  6161. int8 slot = lua_interface->GetInt8Value(state, 2);
  6162. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6163. lua_interface->ResetFunctionStack(state);
  6164. if (!spawn) {
  6165. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!spawn->IsEntity()) {
  6169. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. if(slot >= NUM_SLOTS) {
  6173. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6174. return 0;
  6175. }
  6176. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6177. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6178. if(item) {
  6179. item->save_needed = true;
  6180. if(no_delete_item) {
  6181. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6182. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6183. }
  6184. else{
  6185. Client* client = ((Player*)spawn)->GetClient();
  6186. client->UnequipItem(item->details.index);
  6187. }
  6188. }
  6189. }
  6190. else
  6191. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6192. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6193. spawn->vis_changed = true;
  6194. if(spawn->IsPlayer())
  6195. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6196. lua_interface->SetBooleanValue(state, true);
  6197. return 1;
  6198. }
  6199. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6200. if (!lua_interface)
  6201. return 0;
  6202. Spawn* spawn = lua_interface->GetSpawn(state);
  6203. int8 slot = lua_interface->GetInt8Value(state, 2);
  6204. int16 type = lua_interface->GetInt16Value(state, 3);
  6205. int8 r = lua_interface->GetInt8Value(state, 4);
  6206. int8 g = lua_interface->GetInt8Value(state, 5);
  6207. int8 b = lua_interface->GetInt8Value(state, 6);
  6208. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6209. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6210. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6211. lua_interface->ResetFunctionStack(state);
  6212. if (!spawn) {
  6213. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. if (!spawn->IsEntity()) {
  6217. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6221. spawn->vis_changed = true;
  6222. lua_interface->SetBooleanValue(state, true);
  6223. return 1;
  6224. }
  6225. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6226. if (!lua_interface)
  6227. return 0;
  6228. Spawn* player = lua_interface->GetSpawn(state);
  6229. int32 id = lua_interface->GetInt32Value(state, 2);
  6230. int8 count = lua_interface->GetInt8Value(state, 3);
  6231. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6232. lua_interface->ResetFunctionStack(state);
  6233. if (!player) {
  6234. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6235. return 0;
  6236. }
  6237. if (!player->IsPlayer()) {
  6238. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6239. return 0;
  6240. }
  6241. if (!count)
  6242. count = 1;
  6243. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6244. if (!item) {
  6245. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6246. return 0;
  6247. }
  6248. lua_interface->SetItemValue(state, item);
  6249. return 1;
  6250. }
  6251. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6252. if (!lua_interface)
  6253. return 0;
  6254. Spawn* spawn = lua_interface->GetSpawn(state);
  6255. int32 anim = lua_interface->GetInt32Value(state, 2);
  6256. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6257. int8 type = lua_interface->GetInt8Value(state, 4);
  6258. lua_interface->ResetFunctionStack(state);
  6259. if (!spawn) {
  6260. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. if (spawn2) {
  6264. if (spawn2->IsPlayer()) {
  6265. if (type != 1 && type != 2)
  6266. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6267. else
  6268. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6269. return 0;
  6270. }
  6271. else {
  6272. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6273. return 0;
  6274. }
  6275. }
  6276. else
  6277. spawn->GetZone()->PlayAnimation(spawn, anim);
  6278. return 0;
  6279. }
  6280. int EQ2Emu_lua_IsPet(lua_State* state) {
  6281. if (!lua_interface)
  6282. return 0;
  6283. Spawn* spawn = lua_interface->GetSpawn(state);
  6284. lua_interface->ResetFunctionStack(state);
  6285. if (!spawn) {
  6286. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6290. return 1;
  6291. }
  6292. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6293. if (!lua_interface)
  6294. return 0;
  6295. Spawn* spawn = lua_interface->GetSpawn(state);
  6296. lua_interface->ResetFunctionStack(state);
  6297. if (!spawn) {
  6298. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. if (!spawn->IsNPC()) {
  6302. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6303. return 0;
  6304. }
  6305. if (((NPC*)spawn)->GetOwner()) {
  6306. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6307. return 1;
  6308. }
  6309. return 0;
  6310. }
  6311. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6312. if (!lua_interface)
  6313. return 0;
  6314. Spawn* spawn = lua_interface->GetSpawn(state);
  6315. Spawn* target = lua_interface->GetSpawn(state, 2);
  6316. lua_interface->ResetFunctionStack(state);
  6317. if (!spawn) {
  6318. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6319. return 0;
  6320. }
  6321. if (!spawn) {
  6322. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6323. return 0;
  6324. }
  6325. spawn->SetTarget(target);
  6326. return 0;
  6327. }
  6328. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6329. if (!lua_interface)
  6330. return 0;
  6331. Spawn* spawn = lua_interface->GetSpawn(state);
  6332. bool val = lua_interface->GetBooleanValue(state, 2);
  6333. lua_interface->ResetFunctionStack(state);
  6334. if (!spawn) {
  6335. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. if (!spawn->IsEntity()) {
  6339. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. ((Entity*)spawn)->InCombat(val);
  6343. if (val) {
  6344. spawn->ClearRunningLocations();
  6345. spawn->CalculateRunningLocation(true);
  6346. }
  6347. return 0;
  6348. }
  6349. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6350. if (!lua_interface)
  6351. return 0;
  6352. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6353. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6354. lua_interface->ResetFunctionStack(state);
  6355. if (!spawn1) {
  6356. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6357. return 0;
  6358. }
  6359. if (!spawn2) {
  6360. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6361. return 0;
  6362. }
  6363. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6364. return 1;
  6365. }
  6366. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6367. if (!lua_interface)
  6368. return 0;
  6369. Spawn* spawn = lua_interface->GetSpawn(state);
  6370. lua_interface->ResetFunctionStack(state);
  6371. if (!spawn) {
  6372. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6373. return 0;
  6374. }
  6375. if (!spawn->IsNPC()) {
  6376. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6377. return 0;
  6378. }
  6379. ((NPC*)spawn)->ClearRunback();
  6380. return 0;
  6381. }
  6382. int EQ2Emu_lua_Runback(lua_State* state) {
  6383. if (!lua_interface)
  6384. return 0;
  6385. Spawn* spawn = lua_interface->GetSpawn(state);
  6386. lua_interface->ResetFunctionStack(state);
  6387. if (!spawn) {
  6388. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (!spawn->IsNPC()) {
  6392. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6393. return 0;
  6394. }
  6395. ((NPC*)spawn)->Runback();
  6396. return 0;
  6397. }
  6398. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6399. if (!lua_interface)
  6400. return 0;
  6401. Spawn* spawn = lua_interface->GetSpawn(state);
  6402. lua_interface->ResetFunctionStack(state);
  6403. if (!spawn) {
  6404. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6405. return 0;
  6406. }
  6407. if (!spawn->IsNPC()) {
  6408. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6409. return 0;
  6410. }
  6411. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6412. return 1;
  6413. }
  6414. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. lua_interface->ResetFunctionStack(state);
  6419. if (!spawn) {
  6420. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6421. return 0;
  6422. }
  6423. if (!spawn->IsEntity()) {
  6424. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6425. return 0;
  6426. }
  6427. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6428. return 1;
  6429. }
  6430. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6431. if (!lua_interface)
  6432. return 0;
  6433. Spawn* spawn = lua_interface->GetSpawn(state);
  6434. lua_interface->ResetFunctionStack(state);
  6435. if (!spawn) {
  6436. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. if (!spawn->IsEntity()) {
  6440. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6441. return 0;
  6442. }
  6443. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6444. return 1;
  6445. }
  6446. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6447. if (!lua_interface)
  6448. return 0;
  6449. Spawn* spawn = lua_interface->GetSpawn(state);
  6450. lua_interface->ResetFunctionStack(state);
  6451. if (!spawn) {
  6452. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6453. return 0;
  6454. }
  6455. if (!spawn->IsEntity()) {
  6456. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6457. return 0;
  6458. }
  6459. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6460. return 1;
  6461. }
  6462. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6463. if (!lua_interface)
  6464. return 0;
  6465. Spawn* spawn = lua_interface->GetSpawn(state);
  6466. lua_interface->ResetFunctionStack(state);
  6467. if (!spawn) {
  6468. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6469. return 0;
  6470. }
  6471. if (!spawn->IsEntity()) {
  6472. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6473. return 0;
  6474. }
  6475. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6476. return 1;
  6477. }
  6478. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6479. if (!lua_interface)
  6480. return 0;
  6481. Spawn* spawn = lua_interface->GetSpawn(state);
  6482. Spawn* target = lua_interface->GetSpawn(state, 2);
  6483. float distance = lua_interface->GetFloatValue(state, 3);
  6484. lua_interface->ResetFunctionStack(state);
  6485. if (!spawn) {
  6486. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6487. return 0;
  6488. }
  6489. if (!target) {
  6490. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (!spawn->IsNPC()) {
  6494. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. if (!target->IsEntity()) {
  6498. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6499. return 0;
  6500. }
  6501. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6502. return 1;
  6503. }
  6504. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6505. if (!lua_interface)
  6506. return 0;
  6507. Spawn* spawn = lua_interface->GetSpawn(state);
  6508. Spawn* target = lua_interface->GetSpawn(state, 2);
  6509. float distance = lua_interface->GetFloatValue(state, 3);
  6510. lua_interface->ResetFunctionStack(state);
  6511. if (!spawn) {
  6512. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6513. return 0;
  6514. }
  6515. if (!target) {
  6516. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6517. return 0;
  6518. }
  6519. if (!spawn->IsNPC()) {
  6520. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6521. return 0;
  6522. }
  6523. if (!target->IsEntity()) {
  6524. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6528. return 0;
  6529. }
  6530. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6531. if (!lua_interface)
  6532. return 0;
  6533. Spawn* spawn = lua_interface->GetSpawn(state);
  6534. lua_interface->ResetFunctionStack(state);
  6535. if (!spawn) {
  6536. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6537. return 0;
  6538. }
  6539. if (!spawn->IsNPC()) {
  6540. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6541. return 0;
  6542. }
  6543. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6544. return 1;
  6545. }
  6546. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6547. if (!lua_interface)
  6548. return 0;
  6549. Spawn* spawn = lua_interface->GetSpawn(state);
  6550. lua_interface->ResetFunctionStack(state);
  6551. if (!spawn) {
  6552. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6553. return 0;
  6554. }
  6555. if (!spawn->IsNPC()) {
  6556. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6557. return 0;
  6558. }
  6559. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6560. return 1;
  6561. }
  6562. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6563. if (!lua_interface)
  6564. return 0;
  6565. Spawn* spawn = lua_interface->GetSpawn(state);
  6566. lua_interface->ResetFunctionStack(state);
  6567. if (!spawn) {
  6568. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6569. return 0;
  6570. }
  6571. if (!spawn->IsNPC()) {
  6572. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6573. return 0;
  6574. }
  6575. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6576. if (hated) {
  6577. lua_interface->SetSpawnValue(state, hated);
  6578. return 1;
  6579. }
  6580. return 0;
  6581. }
  6582. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6583. if (!lua_interface)
  6584. return 0;
  6585. Spawn* spawn = lua_interface->GetSpawn(state);
  6586. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6587. lua_interface->ResetFunctionStack(state);
  6588. if (!spawn) {
  6589. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. if (!spawn->IsNPC()) {
  6593. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6594. return 0;
  6595. }
  6596. if (!hated) {
  6597. ((NPC*)spawn)->Brain()->ClearHate();
  6598. return 0;
  6599. }
  6600. else
  6601. {
  6602. if (!hated->IsEntity()) {
  6603. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6604. return 0;
  6605. }
  6606. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6607. return 0;
  6608. }
  6609. return 0;
  6610. }
  6611. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6612. if (!lua_interface)
  6613. return 0;
  6614. Spawn* spawn = lua_interface->GetSpawn(state);
  6615. lua_interface->ResetFunctionStack(state);
  6616. if (!spawn) {
  6617. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6618. return 0;
  6619. }
  6620. if (!spawn->IsNPC()) {
  6621. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. ((NPC*)spawn)->Brain()->ClearEncounter();
  6625. return 0;
  6626. }
  6627. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6628. if (!lua_interface)
  6629. return 0;
  6630. Spawn* spawn = lua_interface->GetSpawn(state);
  6631. lua_interface->ResetFunctionStack(state);
  6632. if (!spawn) {
  6633. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6634. return 0;
  6635. }
  6636. if (!spawn->IsNPC()) {
  6637. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. // Temp list to store hate list
  6641. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6642. if (encounterList->size() == 0) {
  6643. safe_delete(encounterList);
  6644. return 0;
  6645. }
  6646. lua_createtable(state, encounterList->size(), 0);
  6647. int newTable = lua_gettop(state);
  6648. for (int32 i = 0; i < encounterList->size(); i++) {
  6649. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6650. if (temp)
  6651. lua_interface->SetSpawnValue(state, temp);
  6652. lua_rawseti(state, newTable, i + 1);
  6653. }
  6654. safe_delete(encounterList);
  6655. return 1;
  6656. }
  6657. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6658. if (!lua_interface)
  6659. return 0;
  6660. Spawn* spawn = lua_interface->GetSpawn(state);
  6661. lua_interface->ResetFunctionStack(state);
  6662. if (!spawn) {
  6663. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6664. return 0;
  6665. }
  6666. if (!spawn->IsNPC()) {
  6667. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. // Temp list to store hate list
  6671. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6672. if (hateList->size() == 0) {
  6673. safe_delete(hateList);
  6674. return 0;
  6675. }
  6676. lua_createtable(state, hateList->size(), 0);
  6677. int newTable = lua_gettop(state);
  6678. for (int32 i = 0; i < hateList->size(); i++) {
  6679. lua_interface->SetSpawnValue(state, hateList->at(i));
  6680. lua_rawseti(state, newTable, i + 1);
  6681. }
  6682. safe_delete(hateList);
  6683. return 1;
  6684. }
  6685. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6686. if (!lua_interface)
  6687. return 0;
  6688. Spawn* spawn = lua_interface->GetSpawn(state);
  6689. lua_interface->ResetFunctionStack(state);
  6690. if (!spawn) {
  6691. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. if (spawn->IsPlayer()) {
  6695. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6696. lua_interface->SetBooleanValue(state, true);
  6697. else
  6698. lua_interface->SetBooleanValue(state, false);
  6699. return 1;
  6700. }
  6701. else {
  6702. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6703. return 1;
  6704. }
  6705. }
  6706. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6707. if (!lua_interface)
  6708. return 0;
  6709. Quest* quest = lua_interface->GetQuest(state);
  6710. lua_interface->ResetFunctionStack(state);
  6711. if (!quest) {
  6712. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. quest->SetCompletedFlag(true);
  6716. return 0;
  6717. }
  6718. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6719. if (!lua_interface)
  6720. return 0;
  6721. Spawn* spawn = lua_interface->GetSpawn(state);
  6722. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6723. int8 tier = lua_interface->GetInt8Value(state, 3);
  6724. lua_interface->ResetFunctionStack(state);
  6725. if (!spawn) {
  6726. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6727. return 0;
  6728. }
  6729. if (!spawn->IsEntity()) {
  6730. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6731. return 0;
  6732. }
  6733. if (spellID == 0) {
  6734. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6738. if (effect) {
  6739. if (tier > 0) {
  6740. // If a tier was passed chec to see if it is the same as the effect
  6741. if (tier == effect->tier)
  6742. lua_interface->SetBooleanValue(state, true);
  6743. else
  6744. lua_interface->SetBooleanValue(state, false);
  6745. return 1;
  6746. }
  6747. else {
  6748. // Have an effect but no tier was passed so return true
  6749. lua_interface->SetBooleanValue(state, true);
  6750. }
  6751. return 1;
  6752. }
  6753. // no effect so return false
  6754. lua_interface->SetBooleanValue(state, false);
  6755. return 1;
  6756. }
  6757. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6758. if (!lua_interface)
  6759. return 0;
  6760. Spawn* spawn = lua_interface->GetSpawn(state);
  6761. int32 id = lua_interface->GetInt32Value(state, 2);
  6762. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6763. lua_interface->ResetFunctionStack(state);
  6764. Spawn* spawn2 = 0;
  6765. vector<Spawn*> list;
  6766. if (!spawn) {
  6767. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6768. return 0;
  6769. }
  6770. //If zone not provided, use spawn's zone
  6771. if (!zone)
  6772. zone = spawn->GetZone();
  6773. list = zone->GetSpawnsByID(id);
  6774. if (list.size() == 0) {
  6775. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6776. return 0;
  6777. }
  6778. vector<Spawn*>::iterator itr = list.begin();
  6779. for (int8 i = 0; i < list.size(); i++) {
  6780. spawn2 = itr[i];
  6781. if (spawn2)
  6782. spawn2->AddAllowAccessSpawn(spawn);
  6783. }
  6784. return 0;
  6785. }
  6786. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6787. if (!lua_interface)
  6788. return 0;
  6789. Spawn* spawn = lua_interface->GetSpawn(state);
  6790. int32 id = lua_interface->GetInt32Value(state, 2);
  6791. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6792. lua_interface->ResetFunctionStack(state);
  6793. Spawn* spawn2 = 0;
  6794. if (!spawn) {
  6795. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6796. return 0;
  6797. }
  6798. //If zone not provided, use spawn's zone
  6799. if (!zone)
  6800. zone = spawn->GetZone();
  6801. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6802. vector<Spawn*>::iterator itr = list.begin();
  6803. if (list.size() == 0) {
  6804. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. for (int8 i = 0; i < list.size(); i++) {
  6808. spawn2 = itr[i];
  6809. if (spawn2)
  6810. spawn2->RemoveSpawnAccess(spawn);
  6811. }
  6812. return 0;
  6813. }
  6814. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6815. if (!lua_interface)
  6816. return 0;
  6817. Quest* quest = lua_interface->GetQuest(state);
  6818. lua_interface->ResetFunctionStack(state);
  6819. if (!quest) {
  6820. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6821. return 0;
  6822. }
  6823. quest->SetYellowName(true);
  6824. return 0;
  6825. }
  6826. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6827. if (!lua_interface)
  6828. return 0;
  6829. Spawn* spawn = lua_interface->GetSpawn(state);
  6830. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6831. lua_interface->ResetFunctionStack(state);
  6832. if (!spawn) {
  6833. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. if (!spawn->IsPlayer()) {
  6837. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6841. return 1;
  6842. }
  6843. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6844. if (!lua_interface)
  6845. return 0;
  6846. Spawn* spawn = lua_interface->GetSpawn(state);
  6847. lua_interface->ResetFunctionStack(state);
  6848. if (!spawn) {
  6849. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6850. return 0;
  6851. }
  6852. if (!spawn->IsPlayer()) {
  6853. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6854. return 0;
  6855. }
  6856. ZoneServer* zone = spawn->GetZone();
  6857. if (!zone) {
  6858. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6859. return 0;
  6860. }
  6861. Instance_Type iType = zone->GetInstanceType();
  6862. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6863. iType == GROUP_LOCKOUT_INSTANCE ||
  6864. iType == RAID_LOCKOUT_INSTANCE ||
  6865. iType == SOLO_PERSIST_INSTANCE ||
  6866. iType == GROUP_PERSIST_INSTANCE ||
  6867. iType == RAID_PERSIST_INSTANCE) {
  6868. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6869. if (data) {
  6870. // Check to see if the timer has already been set, if it has return out.
  6871. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6872. return 0;
  6873. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6874. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6875. if(spawn->IsPlayer()) {
  6876. Client* client = ((Player*)spawn)->GetClient();
  6877. if (client) {
  6878. string time_msg = "";
  6879. int32 time = data->success_lockout_time;
  6880. int16 hour;
  6881. int8 min;
  6882. int8 sec;
  6883. hour = time / 3600;
  6884. time = time % 3600;
  6885. min = time / 60;
  6886. time = time % 60;
  6887. sec = time;
  6888. if (hour > 0) {
  6889. char temp[10];
  6890. sprintf(temp, " %i", hour);
  6891. time_msg.append(temp);
  6892. time_msg.append(" hour");
  6893. time_msg.append((hour > 1) ? "s" : "");
  6894. }
  6895. if (min > 0) {
  6896. char temp[5];
  6897. sprintf(temp, " %i", min);
  6898. time_msg.append(temp);
  6899. time_msg.append(" minute");
  6900. time_msg.append((min > 1) ? "s" : "");
  6901. }
  6902. // Only add seconds if minutes and hours are 0
  6903. if (hour == 0 && min == 0 && sec > 0) {
  6904. char temp[5];
  6905. sprintf(temp, " %i", sec);
  6906. time_msg.append(temp);
  6907. time_msg.append(" second");
  6908. time_msg.append((sec > 1) ? "s" : "");
  6909. }
  6910. 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());
  6911. }
  6912. else {
  6913. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6914. }
  6915. }
  6916. }
  6917. else
  6918. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6919. }
  6920. else
  6921. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6922. return 0;
  6923. }
  6924. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6925. if (!lua_interface)
  6926. return 0;
  6927. Spawn* spawn = lua_interface->GetSpawn(state);
  6928. lua_interface->ResetFunctionStack(state);
  6929. if (!spawn) {
  6930. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6931. return 0;
  6932. }
  6933. if (!spawn->IsPlayer()) {
  6934. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6935. return 0;
  6936. }
  6937. ZoneServer* zone = spawn->GetZone();
  6938. if (!zone) {
  6939. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6940. return 0;
  6941. }
  6942. Instance_Type iType = zone->GetInstanceType();
  6943. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6944. iType == GROUP_LOCKOUT_INSTANCE ||
  6945. iType == RAID_LOCKOUT_INSTANCE ||
  6946. iType == SOLO_PERSIST_INSTANCE ||
  6947. iType == GROUP_PERSIST_INSTANCE ||
  6948. iType == RAID_PERSIST_INSTANCE) {
  6949. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6950. if (data) {
  6951. // Check to see if the timer has already been set, if it has return out.
  6952. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6953. return 0;
  6954. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6955. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6956. if(spawn->IsPlayer()) {
  6957. Client* client = ((Player*)spawn)->GetClient();
  6958. if (client) {
  6959. string time_msg = "";
  6960. int32 time = data->failure_lockout_time;
  6961. int16 hour;
  6962. int8 min;
  6963. int8 sec;
  6964. hour = time / 3600;
  6965. time = time % 3600;
  6966. min = time / 60;
  6967. time = time % 60;
  6968. sec = time;
  6969. if (hour > 0) {
  6970. char temp[10];
  6971. sprintf(temp, " %i", hour);
  6972. time_msg.append(temp);
  6973. time_msg.append(" hour");
  6974. time_msg.append((hour > 1) ? "s" : "");
  6975. }
  6976. if (min > 0) {
  6977. char temp[5];
  6978. sprintf(temp, " %i", min);
  6979. time_msg.append(temp);
  6980. time_msg.append(" minute");
  6981. time_msg.append((min > 1) ? "s" : "");
  6982. }
  6983. // Only add seconds if minutes and hours are 0
  6984. if (hour == 0 && min == 0 && sec > 0) {
  6985. char temp[5];
  6986. sprintf(temp, " %i", sec);
  6987. time_msg.append(temp);
  6988. time_msg.append(" second");
  6989. time_msg.append((sec > 1) ? "s" : "");
  6990. }
  6991. 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());
  6992. }
  6993. }
  6994. else {
  6995. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6996. }
  6997. }
  6998. else
  6999. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7000. }
  7001. else
  7002. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7003. return 0;
  7004. }
  7005. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7006. if (!lua_interface)
  7007. return 0;
  7008. Spawn* spawn = lua_interface->GetSpawn(state);
  7009. lua_interface->ResetFunctionStack(state);
  7010. if (!spawn) {
  7011. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7015. return 1;
  7016. }
  7017. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7018. if (!lua_interface)
  7019. return 0;
  7020. Spawn* player = lua_interface->GetSpawn(state);
  7021. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7022. if (!player) {
  7023. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7024. lua_interface->ResetFunctionStack(state);
  7025. return 0;
  7026. }
  7027. if (!player->IsPlayer()) {
  7028. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7029. lua_interface->ResetFunctionStack(state);
  7030. return 0;
  7031. }
  7032. if (!ground) {
  7033. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7034. lua_interface->ResetFunctionStack(state);
  7035. return 0;
  7036. }
  7037. if (!ground->IsGroundSpawn()) {
  7038. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7039. lua_interface->ResetFunctionStack(state);
  7040. return 0;
  7041. }
  7042. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7043. if (!groundspawn_entries) {
  7044. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7045. lua_interface->ResetFunctionStack(state);
  7046. return 0;
  7047. }
  7048. Skill* skill = 0;
  7049. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7050. if (collection_skill == "Collecting")
  7051. skill = ((Player*)player)->GetSkillByName("Gathering");
  7052. else
  7053. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7054. if (!skill) {
  7055. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7056. lua_interface->ResetFunctionStack(state);
  7057. return 0;
  7058. }
  7059. vector<GroundSpawnEntry*>::iterator itr;
  7060. GroundSpawnEntry* entry = 0;
  7061. bool can_harvest = false;
  7062. sint32 min_skill = -1;
  7063. int16 totalSkill = skill->current_val;
  7064. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7065. if(skillID != 0xFFFFFFFF)
  7066. {
  7067. ((Entity*)player)->MStats.lock();
  7068. totalSkill += ((Entity*)player)->stats[skillID];
  7069. ((Entity*)player)->MStats.unlock();
  7070. }
  7071. // first, iterate through groundspawn_entries, discard tables player cannot use
  7072. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7073. {
  7074. entry = *itr;
  7075. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7076. min_skill = entry->min_skill_level;
  7077. // if player lacks skill, skip table
  7078. if (entry->min_skill_level > totalSkill)
  7079. continue;
  7080. // if bonus, but player lacks level, skip table
  7081. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7082. continue;
  7083. can_harvest = true;
  7084. break;
  7085. }
  7086. lua_interface->SetBooleanValue(state, can_harvest);
  7087. // If false, send the message to the client
  7088. if (!can_harvest) {
  7089. Client* client = ((Player*)player)->GetClient();
  7090. if (client) {
  7091. string msg = "You do not have enough skill to ";
  7092. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7093. msg.append("gather");
  7094. else if (collection_skill == "Mining")
  7095. msg.append("mine");
  7096. else if (collection_skill == "Trapping")
  7097. msg.append("trap");
  7098. else if (collection_skill == "Foresting")
  7099. msg.append("forest");
  7100. else if (collection_skill == "Fishing")
  7101. msg.append("catch");
  7102. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7103. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7104. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7105. }
  7106. }
  7107. lua_interface->ResetFunctionStack(state);
  7108. return 1;
  7109. }
  7110. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7111. if (!lua_interface)
  7112. return 0;
  7113. Spawn* player = lua_interface->GetSpawn(state);
  7114. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7115. lua_interface->ResetFunctionStack(state);
  7116. if (!player) {
  7117. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!player->IsPlayer()) {
  7121. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7125. lua_interface->SetBooleanValue(state, ret);
  7126. return 1;
  7127. }
  7128. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7129. // Check to see if we have a valid lua_interface
  7130. if (!lua_interface)
  7131. return 0;
  7132. // Get the spawn that is getting the pet
  7133. Spawn* spawn = lua_interface->GetSpawn(state);
  7134. Spawn* target = lua_interface->GetSpawn(state, 2);
  7135. // Get the DB ID of the pet
  7136. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7137. float x = lua_interface->GetFloatValue(state, 4);
  7138. float y = lua_interface->GetFloatValue(state, 5);
  7139. float z = lua_interface->GetFloatValue(state, 6);
  7140. // Get the spell that this command was called from
  7141. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7142. lua_interface->ResetFunctionStack(state);
  7143. // Check to make sure the spawn pointer is valid
  7144. if (!spawn) {
  7145. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7146. return 0;
  7147. }
  7148. // Check to make sure the spawn is an entity
  7149. if (!spawn->IsEntity()) {
  7150. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7151. return 0;
  7152. }
  7153. if (!target) {
  7154. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7155. return 0;
  7156. }
  7157. if (!target->IsEntity()) {
  7158. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7159. return 0;
  7160. }
  7161. // Check to see if the DB ID for the pet is set
  7162. if (pet_id == 0) {
  7163. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7164. return 0;
  7165. }
  7166. // Check to see if the pointer to the spell is valid
  7167. if (!luaspell) {
  7168. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7169. return 0;
  7170. }
  7171. if(luaspell->resisted) {
  7172. return 0;
  7173. }
  7174. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7175. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7176. if (!pet) {
  7177. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7178. return 0;
  7179. }
  7180. // Check to make sure the pet is an npc
  7181. if (!pet->IsNPC()) {
  7182. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7183. return 0;
  7184. }
  7185. if (x == 0)
  7186. x = spawn->GetX();
  7187. if (y == 0)
  7188. y = spawn->GetY();
  7189. if (z == 0)
  7190. z = spawn->GetZ();
  7191. // Spawn the pet at the same location as the owner
  7192. pet->SetX(x);
  7193. pet->SetY(y);
  7194. pet->SetZ(z);
  7195. pet->SetLocation(spawn->GetLocation());
  7196. pet->SetHeading(spawn->GetHeading());
  7197. spawn->GetZone()->AddSpawn(pet);
  7198. const char* spawn_script = world.GetSpawnScript(pet_id);
  7199. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7200. spawn->SetSpawnScript(string(spawn_script));
  7201. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7202. }
  7203. std::string petName = std::string("");
  7204. if(spawn->IsEntity()) {
  7205. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7206. }
  7207. if(petName.size() < 1) {
  7208. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7209. petName = spawn->GetZone()->pet_names.at(rand_index);
  7210. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7211. }
  7212. // Set the pets name
  7213. pet->SetName(petName.c_str());
  7214. // Set the level of the pet to the owners level
  7215. pet->SetLevel(spawn->GetLevel());
  7216. // Set the faction of the pet to the same faction as the owner
  7217. pet->SetFactionID(spawn->GetFactionID());
  7218. // Set the spawn as a pet
  7219. pet->SetPet(true);
  7220. // Give a pointer of the owner to the pet
  7221. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7222. // Set the pet type
  7223. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7224. // Set the spell id used to create this pet
  7225. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7226. // Set the spell tier used to create this pet
  7227. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7228. // Set the pets spawn type to 6
  7229. pet->SetSpawnType(6);
  7230. // Set the pets brain
  7231. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7232. // Check to see if the pet has a subtitle
  7233. if (strlen(pet->GetSubTitle()) > 0) {
  7234. // Add the players name to the front of the sub title
  7235. string pet_subtitle;
  7236. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7237. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7238. // Set the pets subtitle to the new one
  7239. pet->SetSubTitle(pet_subtitle.c_str());
  7240. }
  7241. // Set the pet as the return value for this function
  7242. lua_interface->SetSpawnValue(state, pet);
  7243. return 1;
  7244. }
  7245. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7246. if (!lua_interface)
  7247. return 0;
  7248. Spawn* spawn = lua_interface->GetSpawn(state);
  7249. Spawn* player = lua_interface->GetSpawn(state, 2);
  7250. float max_distance = lua_interface->GetFloatValue(state, 3);
  7251. string type = lua_interface->GetStringValue(state, 4);
  7252. lua_interface->ResetFunctionStack(state);
  7253. if (!spawn || (spawn && spawn->IsPlayer())) {
  7254. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (!player || !player->IsPlayer()) {
  7258. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. Client* client = ((Player*)player)->GetClient();
  7262. if (!client) {
  7263. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7264. return 0;
  7265. }
  7266. //Set max_distance to default if not set or not proper value
  7267. if (max_distance <= 0)
  7268. max_distance = 500;
  7269. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7270. if (packet) {
  7271. float unknown2_3 = 0;
  7272. int8 placement_mode = 0;
  7273. if (type == "wall") {
  7274. placement_mode = 2;
  7275. unknown2_3 = 150;
  7276. }
  7277. else if (type == "ceiling")
  7278. placement_mode = 1;
  7279. packet->setDataByName("placement_mode", placement_mode);
  7280. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7281. packet->setDataByName("model_type", spawn->GetModelType());
  7282. packet->setDataByName("unknown", 1); //size
  7283. packet->setDataByName("unknown2", 1); //size 2
  7284. packet->setDataByName("unknown2", .5, 1); //size 3
  7285. packet->setDataByName("unknown2", 3, 2);
  7286. packet->setDataByName("unknown2", unknown2_3, 3);
  7287. packet->setDataByName("max_distance", max_distance);
  7288. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7289. client->QueuePacket(packet->serialize());
  7290. safe_delete(packet);
  7291. }
  7292. return 0;
  7293. }
  7294. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7295. if (!lua_interface)
  7296. return 0;
  7297. Item* item = lua_interface->GetItem(state);
  7298. lua_interface->ResetFunctionStack(state);
  7299. if (!item) {
  7300. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7301. return 0;
  7302. }
  7303. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7304. return 1;
  7305. }
  7306. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7307. if (!lua_interface)
  7308. return 0;
  7309. Item* item = lua_interface->GetItem(state);
  7310. lua_interface->ResetFunctionStack(state);
  7311. if (!item) {
  7312. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7313. return 0;
  7314. }
  7315. lua_interface->SetInt32Value(state, item->effect_type);
  7316. return 1;
  7317. }
  7318. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7319. if (!lua_interface)
  7320. return 0;
  7321. Spawn* spawn = lua_interface->GetSpawn(state);
  7322. lua_interface->ResetFunctionStack(state);
  7323. if (!spawn) {
  7324. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7325. return 0;
  7326. }
  7327. if (spawn->GetZone())
  7328. spawn->GetZone()->AddTransportSpawn(spawn);
  7329. return 0;
  7330. }
  7331. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7332. if (!lua_interface)
  7333. return 0;
  7334. Spawn* spawn = lua_interface->GetSpawn(state);
  7335. lua_interface->ResetFunctionStack(state);
  7336. if (!spawn) {
  7337. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7338. return 0;
  7339. }
  7340. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7341. return 1;
  7342. }
  7343. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7344. if (!lua_interface)
  7345. return 0;
  7346. Skill* skill = lua_interface->GetSkill(state);
  7347. lua_interface->ResetFunctionStack(state);
  7348. if (!skill) {
  7349. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7350. return 0;
  7351. }
  7352. lua_interface->SetInt32Value(state, skill->current_val);
  7353. return 1;
  7354. }
  7355. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7356. if (!lua_interface)
  7357. return 0;
  7358. Skill* skill = lua_interface->GetSkill(state);
  7359. lua_interface->ResetFunctionStack(state);
  7360. if (!skill) {
  7361. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. lua_interface->SetInt32Value(state, skill->max_val);
  7365. return 1;
  7366. }
  7367. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7368. if (!lua_interface)
  7369. return 0;
  7370. Skill* skill = lua_interface->GetSkill(state);
  7371. lua_interface->ResetFunctionStack(state);
  7372. if (!skill) {
  7373. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7374. return 0;
  7375. }
  7376. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7377. return 1;
  7378. }
  7379. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7380. if (!lua_interface)
  7381. return 0;
  7382. Skill* skill = lua_interface->GetSkill(state);
  7383. int16 value = lua_interface->GetInt16Value(state, 2);
  7384. lua_interface->ResetFunctionStack(state);
  7385. if (!skill) {
  7386. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7387. return 0;
  7388. }
  7389. skill->max_val = value;
  7390. if (skill->max_val < skill->current_val)
  7391. skill->current_val = skill->max_val;
  7392. return 0;
  7393. }
  7394. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7395. if (!lua_interface)
  7396. return 0;
  7397. Skill* skill = lua_interface->GetSkill(state);
  7398. int16 value = lua_interface->GetInt16Value(state, 2);
  7399. lua_interface->ResetFunctionStack(state);
  7400. if (!skill) {
  7401. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7402. return 0;
  7403. }
  7404. if (value > skill->max_val)
  7405. skill->current_val = skill->max_val;
  7406. else
  7407. skill->current_val = value;
  7408. return 0;
  7409. }
  7410. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7411. if (!lua_interface)
  7412. return 0;
  7413. Spawn* player = lua_interface->GetSpawn(state);
  7414. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7415. lua_interface->ResetFunctionStack(state);
  7416. if (skill_id > 0 && player && player->IsPlayer()) {
  7417. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7418. return 1;
  7419. }
  7420. return 0;
  7421. }
  7422. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7423. if (!lua_interface)
  7424. return 0;
  7425. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7426. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7427. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7428. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7429. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7430. lua_interface->ResetFunctionStack(state);
  7431. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7432. if (player_spawn && player_spawn->IsPlayer()) {
  7433. Player* player = (Player*)player_spawn;
  7434. bool added = false;
  7435. if (!player->skill_list.HasSkill(skill_id)) {
  7436. player->AddSkill(skill_id, current_val, max_val, true);
  7437. added = true;
  7438. }
  7439. 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
  7440. Client* client = player->GetClient();
  7441. if (client) {
  7442. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7443. if (packet)
  7444. client->QueuePacket(packet);
  7445. }
  7446. }
  7447. if (added) {
  7448. lua_interface->SetBooleanValue(state, true);
  7449. return 1;
  7450. }
  7451. }
  7452. else {
  7453. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7454. }
  7455. }
  7456. else {
  7457. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7458. }
  7459. lua_interface->SetBooleanValue(state, false);
  7460. return 1;
  7461. }
  7462. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7463. if (!lua_interface)
  7464. return 0;
  7465. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7466. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7467. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7468. lua_interface->ResetFunctionStack(state);
  7469. if (skill_id > 0) {
  7470. if (player_spawn && player_spawn->IsPlayer()) {
  7471. Player* player = (Player*)player_spawn;
  7472. if (player->skill_list.HasSkill(skill_id)) {
  7473. player->RemovePlayerSkill(skill_id, true);
  7474. if (!more_to_remove) {
  7475. Client* client = player->GetClient();
  7476. if (client) {
  7477. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7478. if (packet)
  7479. client->QueuePacket(packet);
  7480. }
  7481. }
  7482. }
  7483. }
  7484. else {
  7485. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7486. }
  7487. }
  7488. else {
  7489. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7490. }
  7491. return 0;
  7492. }
  7493. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7494. if (!lua_interface)
  7495. return 0;
  7496. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7497. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7498. int16 amount = lua_interface->GetInt8Value(state, 3);
  7499. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7500. lua_interface->ResetFunctionStack(state);
  7501. if (amount > 0 && skill_type < 100) {
  7502. if (player_spawn && player_spawn->IsPlayer()) {
  7503. Player* player = (Player*)player_spawn;
  7504. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7505. if (!more_to_increase) {
  7506. Client* client = player->GetClient();
  7507. if (client) {
  7508. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7509. if (packet)
  7510. client->QueuePacket(packet);
  7511. }
  7512. }
  7513. }
  7514. else {
  7515. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7516. }
  7517. }
  7518. else {
  7519. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7520. }
  7521. return 0;
  7522. }
  7523. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7524. if (!lua_interface)
  7525. return 0;
  7526. Spawn* spawn = lua_interface->GetSpawn(state);
  7527. string name = lua_interface->GetStringValue(state, 2);
  7528. lua_interface->ResetFunctionStack(state);
  7529. if (!spawn) {
  7530. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. if (!spawn->IsEntity()) {
  7534. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7535. return 0;
  7536. }
  7537. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7538. if (skill) {
  7539. lua_interface->SetSkillValue(state, skill);
  7540. return 1;
  7541. }
  7542. return 0;
  7543. }
  7544. int EQ2Emu_lua_AddProc(lua_State* state) {
  7545. if (!lua_interface)
  7546. return 0;
  7547. Spawn* spawn = lua_interface->GetSpawn(state);
  7548. int8 type = lua_interface->GetInt8Value(state, 2);
  7549. float chance = lua_interface->GetFloatValue(state, 3);
  7550. Item* item = lua_interface->GetItem(state, 4);
  7551. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7552. LuaSpell* spell = 0;
  7553. if (!spawn && (!spell || !use_all_spelltargets)) {
  7554. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7558. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7559. return 0;
  7560. }
  7561. if (!item)
  7562. spell = lua_interface->GetCurrentSpell(state);
  7563. if (!item && !spell) {
  7564. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7565. return 0;
  7566. }
  7567. if(spell && spell->resisted) {
  7568. return 0;
  7569. }
  7570. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7571. Spawn* target;
  7572. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7573. for (int8 i = 0; i < spell->targets.size(); i++) {
  7574. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7575. if (!target || !target->IsEntity())
  7576. continue;
  7577. ((Entity*)target)->AddProc(type, chance, item, spell);
  7578. }
  7579. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7580. }
  7581. else
  7582. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7583. return 0;
  7584. }
  7585. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7586. if (!lua_interface)
  7587. return 0;
  7588. Spawn* spawn = lua_interface->GetSpawn(state);
  7589. Item* item = lua_interface->GetItem(state, 2);
  7590. LuaSpell* spell = 0;
  7591. if (!spawn) {
  7592. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7593. lua_interface->ResetFunctionStack(state);
  7594. return 0;
  7595. }
  7596. if (!spawn->IsEntity()) {
  7597. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7598. lua_interface->ResetFunctionStack(state);
  7599. return 0;
  7600. }
  7601. if (!item)
  7602. spell = lua_interface->GetCurrentSpell(state);
  7603. lua_interface->ResetFunctionStack(state);
  7604. if (!item && !spell) {
  7605. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7606. return 0;
  7607. }
  7608. if (spell && spell->caster && spell->caster->GetZone()) {
  7609. Spawn* target;
  7610. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7611. for (int8 i = 0; i < spell->targets.size(); i++) {
  7612. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7613. if (!target || !target->IsEntity())
  7614. continue;
  7615. ((Entity*)target)->RemoveProc(item, spell);
  7616. }
  7617. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7618. spell->caster->RemoveProc(item, spell);
  7619. }
  7620. else
  7621. ((Entity*)spawn)->RemoveProc(item, spell);
  7622. return 0;
  7623. }
  7624. int EQ2Emu_lua_Knockback(lua_State* state) {
  7625. if (!lua_interface)
  7626. return 0;
  7627. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7628. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7629. int32 duration = lua_interface->GetInt32Value(state, 3);
  7630. float vertical = lua_interface->GetFloatValue(state, 4);
  7631. float horizontal = lua_interface->GetFloatValue(state, 5);
  7632. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7633. lua_interface->ResetFunctionStack(state);
  7634. if (!target_spawn) {
  7635. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7636. return 0;
  7637. }
  7638. if (!spawn) {
  7639. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7640. return 0;
  7641. }
  7642. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7643. Client* client = ((Player*)spawn)->GetClient();
  7644. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7645. if (packet) {
  7646. packet->setDataByName("target_x", target_spawn->GetX());
  7647. packet->setDataByName("target_y", target_spawn->GetY());
  7648. packet->setDataByName("target_z", target_spawn->GetZ());
  7649. packet->setDataByName("vertical_movement", vertical);
  7650. packet->setDataByName("horizontal_movement", horizontal);
  7651. if (use_heading)
  7652. packet->setDataByName("use_player_heading", 1);
  7653. client->QueuePacket(packet->serialize());
  7654. }
  7655. safe_delete(packet);
  7656. }
  7657. return 0;
  7658. }
  7659. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7660. if (!lua_interface)
  7661. return 0;
  7662. Spawn* spawn = lua_interface->GetSpawn(state);
  7663. lua_interface->ResetFunctionStack(state);
  7664. if (!spawn) {
  7665. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7666. return 0;
  7667. }
  7668. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7669. return 1;
  7670. }
  7671. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7672. if (!lua_interface)
  7673. return 0;
  7674. Spawn* caster = lua_interface->GetSpawn(state);
  7675. Spawn* target = lua_interface->GetSpawn(state, 2);
  7676. string name = lua_interface->GetStringValue(state, 3);
  7677. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7678. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7679. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7680. string success_msg = lua_interface->GetStringValue(state, 7);
  7681. string effect_msg = lua_interface->GetStringValue(state, 8);
  7682. lua_interface->ResetFunctionStack(state);
  7683. if (!caster) {
  7684. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7685. return 0;
  7686. }
  7687. if (!caster->IsEntity()) {
  7688. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7689. return 0;
  7690. }
  7691. if (!target) {
  7692. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7693. return 0;
  7694. }
  7695. if (!target->IsEntity()) {
  7696. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. if (name.length() == 0) {
  7700. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7701. return 0;
  7702. }
  7703. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7704. return 0;
  7705. }
  7706. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7707. if (!lua_interface)
  7708. return 0;
  7709. string name = lua_interface->GetStringValue(state);
  7710. lua_interface->ResetFunctionStack(state);
  7711. if (name.length() == 0) {
  7712. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7713. return 0;
  7714. }
  7715. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7716. if (!skill) {
  7717. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7718. return 0;
  7719. }
  7720. lua_interface->SetInt32Value(state, skill->skill_id);
  7721. return 1;
  7722. }
  7723. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7724. if (!lua_interface)
  7725. return 0;
  7726. Spawn* spawn = lua_interface->GetSpawn(state);
  7727. lua_interface->ResetFunctionStack(state);
  7728. if (!spawn) {
  7729. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7730. return 0;
  7731. }
  7732. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7733. return 1;
  7734. }
  7735. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7736. if (!lua_interface)
  7737. return 0;
  7738. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7739. lua_interface->ResetFunctionStack(state);
  7740. if (!luaspell) {
  7741. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7742. return 0;
  7743. }
  7744. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7745. return 1;
  7746. }
  7747. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7748. if (!lua_interface)
  7749. return 0;
  7750. Spawn* spawn = lua_interface->GetSpawn(state);
  7751. Spawn* target = lua_interface->GetSpawn(state, 2);
  7752. lua_interface->ResetFunctionStack(state);
  7753. if (!spawn) {
  7754. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (!spawn->IsEntity()) {
  7758. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. if (!target) {
  7762. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7763. return 0;
  7764. }
  7765. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7766. return 1;
  7767. }
  7768. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7769. if (!lua_interface)
  7770. return 0;
  7771. Spawn* spawn = lua_interface->GetSpawn(state);
  7772. Spawn* target = lua_interface->GetSpawn(state, 2);
  7773. lua_interface->ResetFunctionStack(state);
  7774. if (!spawn) {
  7775. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7776. return 0;
  7777. }
  7778. if (!spawn->IsEntity()) {
  7779. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7780. return 0;
  7781. }
  7782. if (!target) {
  7783. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7784. return 0;
  7785. }
  7786. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7787. return 1;
  7788. }
  7789. int EQ2Emu_lua_InFront(lua_State* state) {
  7790. if (!lua_interface)
  7791. return 0;
  7792. Spawn* spawn = lua_interface->GetSpawn(state);
  7793. Spawn* target = lua_interface->GetSpawn(state, 2);
  7794. lua_interface->ResetFunctionStack(state);
  7795. if (!spawn) {
  7796. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. if (!spawn->IsEntity()) {
  7800. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7801. return 0;
  7802. }
  7803. if (!target) {
  7804. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7805. return 0;
  7806. }
  7807. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7808. return 1;
  7809. }
  7810. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7811. if (!lua_interface)
  7812. return 0;
  7813. Item* item = lua_interface->GetItem(state);
  7814. lua_interface->ResetFunctionStack(state);
  7815. if (!item) {
  7816. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7817. return 0;
  7818. }
  7819. lua_interface->SetInt32Value(state, item->details.count);
  7820. return 1;
  7821. }
  7822. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7823. if (!lua_interface)
  7824. return 0;
  7825. Item* item = lua_interface->GetItem(state);
  7826. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7827. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7828. lua_interface->ResetFunctionStack(state);
  7829. if (!item) {
  7830. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7831. return 0;
  7832. }
  7833. if (!owner) {
  7834. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7835. return 0;
  7836. }
  7837. if (!owner->IsPlayer()) {
  7838. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7839. return 0;
  7840. }
  7841. if (item->stack_count < new_count) {
  7842. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. if (new_count > 0) {
  7846. item->details.count = new_count;
  7847. item->save_needed = true;
  7848. }
  7849. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7850. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7851. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7852. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7853. else
  7854. {
  7855. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7856. return 0;
  7857. }
  7858. Client* client = ((Player*)owner)->GetClient();
  7859. if (!client)
  7860. return 0;
  7861. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7862. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7863. if (app)
  7864. client->QueuePacket(app);
  7865. return 0;
  7866. }
  7867. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7868. if (!lua_interface)
  7869. return 0;
  7870. int32 time = lua_interface->GetInt32Value(state);
  7871. string function = lua_interface->GetStringValue(state, 2);
  7872. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7873. Spawn* target = lua_interface->GetSpawn(state, 4);
  7874. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7875. lua_interface->ResetFunctionStack(state);
  7876. if (time == 0) {
  7877. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. if (function.length() == 0) {
  7881. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7885. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7886. return 0;
  7887. }
  7888. SpellScriptTimer* timer = new SpellScriptTimer;
  7889. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7890. #ifdef WIN32
  7891. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7892. #else
  7893. bzero(timer, sizeof(SpellScriptTimer));
  7894. #endif*/
  7895. timer->caster = 0;
  7896. timer->deleteWhenDone = false;
  7897. timer->target = 0;
  7898. timer->time = Timer::GetCurrentTime2() + time;
  7899. timer->customFunction = function;
  7900. timer->spell = spell;
  7901. if (caster)
  7902. timer->caster = caster->GetID();
  7903. if (target)
  7904. timer->target = target->GetID();
  7905. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7906. return 0;
  7907. }
  7908. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7909. if (!lua_interface)
  7910. return 0;
  7911. float hp_perc = lua_interface->GetFloatValue(state);
  7912. float power_perc = lua_interface->GetFloatValue(state, 2);
  7913. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7914. Spawn* target = lua_interface->GetSpawn(state, 4);
  7915. string heal_name = lua_interface->GetStringValue(state, 5);
  7916. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7917. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7918. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7919. lua_interface->ResetFunctionStack(state);
  7920. if (!spell) {
  7921. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7922. return 0;
  7923. }
  7924. Entity* caster = spell->caster;
  7925. if (!caster) {
  7926. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7927. return 0;
  7928. }
  7929. Client* client = 0;
  7930. PendingResurrection* rez = 0;
  7931. ZoneServer* zone = spell->caster->GetZone();
  7932. if (!target) {
  7933. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7934. if (spell->targets.size() > 0) {
  7935. vector<int32> spell_targets = spell->targets;
  7936. for (int8 i = 0; i < spell_targets.size(); i++) {
  7937. target = zone->GetSpawnByID(spell_targets.at(i));
  7938. if (!target)
  7939. continue;
  7940. if (!target->IsPlayer())
  7941. continue;
  7942. client = ((Player*)target)->GetClient();
  7943. if (!client)
  7944. continue;
  7945. rez = client->GetCurrentRez();
  7946. if (rez->active)
  7947. continue;
  7948. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7949. rez->active = true;
  7950. rez->caster = caster;
  7951. rez->expire_timer = new Timer;
  7952. int32 duration = spell->spell->GetSpellDuration();
  7953. rez->expire_timer->Start(duration * 100);
  7954. rez->hp_perc = hp_perc;
  7955. rez->mp_perc = power_perc;
  7956. rez->range = spell->spell->GetSpellData()->range;
  7957. rez->spell_name = spell->spell->GetName();
  7958. if (heal_name.length() > 0)
  7959. rez->heal_name = heal_name;
  7960. else
  7961. rez->heal_name = rez->spell_name;
  7962. rez->no_calcs = no_calcs;
  7963. rez->crit_mod = crit_mod;
  7964. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7965. if (send_window)
  7966. client->SendResurrectionWindow();
  7967. else {
  7968. target->GetZone()->ResurrectSpawn(target, client);
  7969. rez->should_delete = true;
  7970. }
  7971. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7972. }
  7973. }
  7974. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7975. }
  7976. else {
  7977. if(!target->IsPlayer())
  7978. return 0;
  7979. client = ((Player*)target)->GetClient();
  7980. if (!client)
  7981. return 0;
  7982. rez = client->GetCurrentRez();
  7983. if (rez->active)
  7984. return 0;
  7985. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7986. rez->active = true;
  7987. rez->caster = caster;
  7988. rez->expire_timer = new Timer;
  7989. int32 duration = spell->spell->GetSpellDuration();
  7990. rez->expire_timer->Start(duration * 100);
  7991. rez->hp_perc = hp_perc;
  7992. rez->mp_perc = power_perc;
  7993. rez->range = spell->spell->GetSpellData()->range;
  7994. rez->spell_name = spell->spell->GetName();
  7995. if (heal_name.length() > 0)
  7996. rez->heal_name = heal_name;
  7997. else
  7998. rez->heal_name = rez->spell_name;
  7999. rez->no_calcs = no_calcs;
  8000. rez->crit_mod = crit_mod;
  8001. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8002. if (send_window)
  8003. client->SendResurrectionWindow();
  8004. else {
  8005. target->GetZone()->ResurrectSpawn(target, client);
  8006. rez->should_delete = true;
  8007. }
  8008. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8009. }
  8010. return 0;
  8011. }
  8012. int EQ2Emu_lua_SetVision(lua_State* state) {
  8013. if (!lua_interface)
  8014. return 0;
  8015. Spawn* spawn = lua_interface->GetSpawn(state);
  8016. int32 vision = lua_interface->GetInt32Value(state, 2);
  8017. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8018. lua_interface->ResetFunctionStack(state);
  8019. if (!spawn) {
  8020. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. if (!spawn->IsEntity()) {
  8024. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (spell && spell->targets.size() > 0) {
  8028. ZoneServer* zone = spell->caster->GetZone();
  8029. for (int8 i = 0; i < spell->targets.size(); i++) {
  8030. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8031. if (target && target->IsEntity()) {
  8032. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8033. if (target->IsPlayer())
  8034. ((Player*)target)->SetCharSheetChanged(true);
  8035. }
  8036. }
  8037. }
  8038. else {
  8039. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8040. if (spawn->IsPlayer())
  8041. ((Player*)spawn)->SetCharSheetChanged(true);
  8042. }
  8043. return 0;
  8044. }
  8045. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8046. if (!lua_interface)
  8047. return 0;
  8048. Spawn* spawn = lua_interface->GetSpawn(state);
  8049. float intensity = lua_interface->GetFloatValue(state, 2);
  8050. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8051. lua_interface->ResetFunctionStack(state);
  8052. if (!spawn) {
  8053. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8054. return 0;
  8055. }
  8056. if (!spawn->IsEntity()) {
  8057. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8058. return 0;
  8059. }
  8060. if (spell && spell->targets.size() > 0) {
  8061. ZoneServer* zone = spell->caster->GetZone();
  8062. for (int8 i = 0; i < spell->targets.size(); i++) {
  8063. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8064. if (target && target->IsEntity()) {
  8065. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8066. if (target->IsPlayer())
  8067. ((Player*)target)->SetCharSheetChanged(true);
  8068. }
  8069. }
  8070. }
  8071. else {
  8072. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8073. if (spawn->IsPlayer())
  8074. ((Player*)spawn)->SetCharSheetChanged(true);
  8075. }
  8076. return 0;
  8077. }
  8078. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8079. if (!lua_interface)
  8080. return 0;
  8081. Spawn* spawn = lua_interface->GetSpawn(state);
  8082. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8083. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8084. lua_interface->ResetFunctionStack(state);
  8085. if (!spawn) {
  8086. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8087. return 0;
  8088. }
  8089. if (!spawn->IsEntity()) {
  8090. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8091. return 0;
  8092. }
  8093. if (spell && spell->targets.size() > 0) {
  8094. ZoneServer* zone = spell->caster->GetZone();
  8095. for (int8 i = 0; i < spell->targets.size(); i++) {
  8096. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8097. if (target && target->IsEntity()) {
  8098. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8099. if (target->IsPlayer())
  8100. ((Player*)target)->SetCharSheetChanged(true);
  8101. }
  8102. }
  8103. }
  8104. else {
  8105. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8106. if (spawn->IsPlayer())
  8107. ((Player*)spawn)->SetCharSheetChanged(true);
  8108. }
  8109. return 0;
  8110. }
  8111. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8112. if (!lua_interface)
  8113. return 0;
  8114. Item* item = lua_interface->GetItem(state);
  8115. int8 type = lua_interface->GetInt32Value(state, 2);
  8116. lua_interface->ResetFunctionStack(state);
  8117. if (!item) {
  8118. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8119. return 0;
  8120. }
  8121. if (type == 1)
  8122. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8123. else if (type == 2)
  8124. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8125. return 1;
  8126. }
  8127. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8128. if (!lua_interface)
  8129. return 0;
  8130. Spawn* target = lua_interface->GetSpawn(state);
  8131. float val = lua_interface->GetFloatValue(state, 2);
  8132. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8133. lua_interface->ResetFunctionStack(state);
  8134. // Added from Gangrenous post
  8135. if (spell && spell->resisted)
  8136. return 0;
  8137. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8138. if (val > 1.0f)
  8139. val = 1.0f - (val / 100.0f);
  8140. if (spell && spell->spell && spell->targets.size() > 0) {
  8141. ZoneServer* zone = spell->caster->GetZone();
  8142. for (int32 i = 0; i != spell->targets.size(); i++) {
  8143. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8144. if (spawn && spawn->IsEntity()) {
  8145. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8146. if (spawn->IsPlayer())
  8147. ((Player*)spawn)->SetCharSheetChanged(true);
  8148. }
  8149. }
  8150. }
  8151. else {
  8152. if (target && target->IsEntity()) {
  8153. ((Entity*)target)->SetSpeedMultiplier(val);
  8154. if (target->IsPlayer())
  8155. ((Player*)target)->SetCharSheetChanged(true);
  8156. }
  8157. }
  8158. return 0;
  8159. }
  8160. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8161. if (!lua_interface)
  8162. return 0;
  8163. Spawn* spawn = lua_interface->GetSpawn(state);
  8164. int16 model = lua_interface->GetInt16Value(state, 2);
  8165. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8166. lua_interface->ResetFunctionStack(state);
  8167. if (spell && spell->spell && spell->targets.size() > 0) {
  8168. ZoneServer* zone = spell->caster->GetZone();
  8169. for (int32 i = 0; i < spell->targets.size(); i++) {
  8170. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8171. if (target)
  8172. target->SetIllusionModel(model);
  8173. }
  8174. }
  8175. else {
  8176. if (!spawn) {
  8177. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8178. return 0;
  8179. }
  8180. spawn->SetIllusionModel(model);
  8181. }
  8182. return 0;
  8183. }
  8184. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8185. if (!lua_interface)
  8186. return 0;
  8187. Spawn* spawn = lua_interface->GetSpawn(state);
  8188. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8189. lua_interface->ResetFunctionStack(state);
  8190. if (spell && spell->spell && spell->targets.size() > 0) {
  8191. ZoneServer* zone = spell->caster->GetZone();
  8192. for (int32 i = 0; i < spell->targets.size(); i++) {
  8193. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8194. if (target)
  8195. target->SetIllusionModel(0);
  8196. }
  8197. }
  8198. else {
  8199. if (!spawn) {
  8200. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8201. return 0;
  8202. }
  8203. spawn->SetIllusionModel(0);
  8204. }
  8205. return 0;
  8206. }
  8207. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8208. if (!lua_interface)
  8209. return 0;
  8210. Spawn* caster = lua_interface->GetSpawn(state);
  8211. Spawn* target = lua_interface->GetSpawn(state, 2);
  8212. float chance = lua_interface->GetFloatValue(state, 3);
  8213. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8214. lua_interface->ResetFunctionStack(state);
  8215. if (!caster) {
  8216. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8217. return 0;
  8218. }
  8219. if (!caster->IsEntity()) {
  8220. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8221. return 0;
  8222. }
  8223. if (!target) {
  8224. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8225. return 0;
  8226. }
  8227. if (!target->IsEntity()) {
  8228. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8229. return 0;
  8230. }
  8231. if (chance <= 0) {
  8232. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8233. return 0;
  8234. }
  8235. if (!spell) {
  8236. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. if(spell->resisted) {
  8240. return 0;
  8241. }
  8242. if (((Entity*)caster)->GetThreatTransfer()) {
  8243. return 0;
  8244. }
  8245. ThreatTransfer* transfer = new ThreatTransfer;
  8246. transfer->Target = target->GetID();
  8247. transfer->Amount = chance;
  8248. transfer->Spell = spell;
  8249. ((Entity*)caster)->SetThreatTransfer(transfer);
  8250. return 0;
  8251. }
  8252. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8253. if (!lua_interface)
  8254. return 0;
  8255. Spawn* spawn = lua_interface->GetSpawn(state);
  8256. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8257. lua_interface->ResetFunctionStack(state);
  8258. if (!spawn) {
  8259. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8260. return 0;
  8261. }
  8262. if (!spell) {
  8263. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8264. return 0;
  8265. }
  8266. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8267. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8268. if(transfer && transfer->Spell != spell) {
  8269. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8270. return 0;
  8271. }
  8272. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8273. }
  8274. return 0;
  8275. }
  8276. int EQ2Emu_lua_CureByType(lua_State* state) {
  8277. if (!lua_interface)
  8278. return 0;
  8279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8280. int8 cure_count = lua_interface->GetInt8Value(state);
  8281. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8282. string cure_name = lua_interface->GetStringValue(state, 3);
  8283. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8284. Spawn* target = lua_interface->GetSpawn(state, 5);
  8285. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8286. lua_interface->ResetFunctionStack(state);
  8287. if(spell && spell->resisted) {
  8288. return 0;
  8289. }
  8290. if (target) {
  8291. if (!target->IsEntity()) {
  8292. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8293. return 0;
  8294. }
  8295. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8296. std::string alternate_name = "item";
  8297. if(spell)
  8298. alternate_name = std::string(spell->spell->GetName());
  8299. if(!caster && spell)
  8300. caster = (Spawn*)spell->caster;
  8301. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8302. }
  8303. }
  8304. else {
  8305. ZoneServer* zone = spell->caster->GetZone();
  8306. vector<int32> targets = spell->targets;
  8307. vector<Entity*> targets_to_cure;
  8308. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8309. for (int8 i = 0; i < targets.size(); i++) {
  8310. target = zone->GetSpawnByID(targets.at(i));
  8311. if (!target || !target->IsEntity())
  8312. continue;
  8313. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8314. targets_to_cure.push_back((Entity*)target);
  8315. }
  8316. }
  8317. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8318. vector<Entity*>::iterator itr;
  8319. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8320. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8321. }
  8322. }
  8323. return 0;
  8324. }
  8325. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8326. if (!lua_interface)
  8327. return 0;
  8328. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8329. if (!spell) {
  8330. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8331. lua_interface->ResetFunctionStack(state);
  8332. return 0;
  8333. }
  8334. if(spell->resisted) {
  8335. lua_interface->ResetFunctionStack(state);
  8336. return 0;
  8337. }
  8338. int8 cure_count = lua_interface->GetInt8Value(state);
  8339. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8340. string cure_name = lua_interface->GetStringValue(state, 3);
  8341. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8342. Spawn* target = lua_interface->GetSpawn(state, 5);
  8343. lua_interface->ResetFunctionStack(state);
  8344. if (target) {
  8345. if (!target->IsEntity()) {
  8346. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. if (((Entity*)target)->GetDetCount() > 0)
  8350. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8351. }
  8352. else {
  8353. ZoneServer* zone = spell->caster->GetZone();
  8354. vector<int32> targets = spell->targets;
  8355. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8356. for (int8 i = 0; i < targets.size(); i++) {
  8357. target = zone->GetSpawnByID(targets.at(i));
  8358. if (!target || !target->IsEntity())
  8359. continue;
  8360. if (((Entity*)target)->GetDetCount() > 0)
  8361. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8362. }
  8363. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8364. }
  8365. return 0;
  8366. }
  8367. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8368. if (!lua_interface)
  8369. return 0;
  8370. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8371. lua_interface->ResetFunctionStack(state);
  8372. if (!spell) {
  8373. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. if (!spell->caster) {
  8377. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8378. return 0;
  8379. }
  8380. if (!spell->caster->GetZone()) {
  8381. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8382. return 0;
  8383. }
  8384. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8385. return 0;
  8386. }
  8387. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8388. if (!lua_interface)
  8389. return 0;
  8390. Spawn* spawn = lua_interface->GetSpawn(state);
  8391. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8392. lua_interface->ResetFunctionStack(state);
  8393. if (!spell) {
  8394. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8395. return 0;
  8396. }
  8397. if (spawn && spawn->IsEntity())
  8398. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8399. else {
  8400. ZoneServer* zone = spell->caster->GetZone();
  8401. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8402. for (int32 i = 0; i < spell->targets.size(); i++) {
  8403. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8404. if (!spawn || !spawn->IsEntity())
  8405. continue;
  8406. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8407. }
  8408. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8409. }
  8410. return 0;
  8411. }
  8412. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8413. if (!lua_interface)
  8414. return 0;
  8415. Spawn* spawn = lua_interface->GetSpawn(state);
  8416. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8417. lua_interface->ResetFunctionStack(state);
  8418. if (!spell) {
  8419. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8420. return 0;
  8421. }
  8422. if (spawn && spawn->IsEntity())
  8423. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8424. else {
  8425. ZoneServer* zone = spell->caster->GetZone();
  8426. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8427. for (int32 i = 0; i < spell->targets.size(); i++) {
  8428. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8429. if (!spawn || !spawn->IsEntity())
  8430. continue;
  8431. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8432. }
  8433. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8434. }
  8435. return 0;
  8436. }
  8437. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8438. if (!lua_interface)
  8439. return 0;
  8440. Spawn* caster = lua_interface->GetSpawn(state);
  8441. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8442. lua_interface->ResetFunctionStack(state);
  8443. if (!caster) {
  8444. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8445. return 0;
  8446. }
  8447. if (!caster->IsPlayer()) {
  8448. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8449. return 0;
  8450. }
  8451. Spawn* target = caster->GetTarget();
  8452. if (!target) {
  8453. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8454. return 0;
  8455. }
  8456. Client* client = ((Player*)caster)->GetClient();
  8457. if (!client) {
  8458. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8459. return 0;
  8460. }
  8461. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8462. if (ho) {
  8463. ho->SetTarget(target->GetID());
  8464. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8465. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8466. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8467. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8468. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8469. deque<GroupMemberInfo*>::iterator itr;
  8470. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8471. if (group)
  8472. {
  8473. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8474. deque<GroupMemberInfo*>* members = group->GetMembers();
  8475. for (itr = members->begin(); itr != members->end(); itr++) {
  8476. if ((*itr)->client)
  8477. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8478. }
  8479. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8480. }
  8481. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8482. }
  8483. else
  8484. safe_delete(ho);
  8485. }
  8486. else {
  8487. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8488. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8489. }
  8490. else
  8491. safe_delete(ho);
  8492. }
  8493. }
  8494. return 0;
  8495. }
  8496. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8497. if (!lua_interface)
  8498. return 0;
  8499. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8500. if (!spell) {
  8501. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8502. return 0;
  8503. }
  8504. int16 triggerCount = lua_interface->GetInt16Value(state);
  8505. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8506. if (!triggerCount) {
  8507. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. spell->num_triggers = triggerCount;
  8511. spell->had_triggers = true;
  8512. spell->cancel_after_all_triggers = cancel_after_triggers;
  8513. return 0;
  8514. }
  8515. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8516. if (!lua_interface)
  8517. return 0;
  8518. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8519. lua_interface->ResetFunctionStack(state);
  8520. if (!spell) {
  8521. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8522. return 0;
  8523. }
  8524. lua_interface->SetInt32Value(state, spell->num_triggers);
  8525. return 1;
  8526. }
  8527. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8528. if (!lua_interface)
  8529. return 0;
  8530. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8531. if (!spell) {
  8532. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8533. lua_interface->ResetFunctionStack(state);
  8534. return 0;
  8535. }
  8536. if (!spell->caster || !spell->caster->GetZone()) {
  8537. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8538. lua_interface->ResetFunctionStack(state);
  8539. return 0;
  8540. }
  8541. int16 remove_count = lua_interface->GetInt16Value(state);
  8542. lua_interface->ResetFunctionStack(state);
  8543. if (!remove_count)
  8544. remove_count = 1;
  8545. if (remove_count >= spell->num_triggers) {
  8546. spell->num_triggers = 0;
  8547. if (spell->cancel_after_all_triggers)
  8548. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8549. }
  8550. else {
  8551. spell->num_triggers -= remove_count;
  8552. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8553. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8554. }
  8555. return 0;
  8556. }
  8557. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8558. if (!lua_interface)
  8559. return 0;
  8560. Spawn* spawn = lua_interface->GetSpawn(state);
  8561. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8562. lua_interface->ResetFunctionStack(state);
  8563. if (!spawn) {
  8564. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8565. return 0;
  8566. }
  8567. if (!copy_spawn) {
  8568. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8569. return 0;
  8570. }
  8571. spawn->CopySpawnAppearance(copy_spawn);
  8572. return 0;
  8573. }
  8574. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8575. Spawn* spawn = lua_interface->GetSpawn(state);
  8576. int8 type = lua_interface->GetInt8Value(state, 2);
  8577. lua_interface->ResetFunctionStack(state);
  8578. if (!spawn) {
  8579. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8580. return 0;
  8581. }
  8582. else if (!spawn->IsEntity()) {
  8583. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8584. return 0;
  8585. }
  8586. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8587. return 1;
  8588. }
  8589. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8590. if (!lua_interface)
  8591. return 0;
  8592. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8593. int8 type = lua_interface->GetInt8Value(state);
  8594. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8595. lua_interface->ResetFunctionStack(state);
  8596. if (!spell) {
  8597. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8598. return 0;
  8599. }
  8600. if(spell->resisted) {
  8601. return 0;
  8602. }
  8603. if (spawn) {
  8604. if (!spawn->IsEntity()) {
  8605. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8606. return 0;
  8607. }
  8608. Entity* entity = ((Entity*)spawn);
  8609. entity->AddImmunity(spell, type);
  8610. }
  8611. else if(spell->caster && spell->caster->GetZone()) {
  8612. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8613. for (int8 i = 0; i < spell->targets.size(); i++) {
  8614. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8615. if (!spawn || !spawn->IsEntity())
  8616. continue;
  8617. Entity* entity = ((Entity*)spawn);
  8618. entity->AddImmunity(spell, type);
  8619. }
  8620. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8621. }
  8622. return 0;
  8623. }
  8624. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8625. if (!lua_interface)
  8626. return 0;
  8627. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8628. int8 type = lua_interface->GetInt8Value(state);
  8629. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8630. lua_interface->ResetFunctionStack(state);
  8631. if (!spell) {
  8632. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8633. return 0;
  8634. }
  8635. if (spawn) {
  8636. if (!spawn->IsEntity()) {
  8637. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8638. return 0;
  8639. }
  8640. Entity* entity = ((Entity*)spawn);
  8641. entity->RemoveImmunity(spell, type);
  8642. }
  8643. else if(spell->caster && spell->caster->GetZone()) {
  8644. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8645. for (int8 i = 0; i < spell->targets.size(); i++) {
  8646. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8647. if (!spawn || !spawn->IsEntity())
  8648. continue;
  8649. Entity* entity = ((Entity*)spawn);
  8650. entity->RemoveImmunity(spell, type);
  8651. }
  8652. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8653. }
  8654. return 0;
  8655. }
  8656. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8657. if (!lua_interface)
  8658. return 0;
  8659. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8660. if (!spell) {
  8661. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8662. lua_interface->ResetFunctionStack(state);
  8663. return 0;
  8664. }
  8665. if(spell->resisted) {
  8666. lua_interface->ResetFunctionStack(state);
  8667. return 0;
  8668. }
  8669. float snare = lua_interface->GetFloatValue(state);
  8670. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8671. lua_interface->ResetFunctionStack(state);
  8672. // convert the val to the speed multipler value (100 - val)
  8673. float val = 100.0 - snare;
  8674. val /= 100.0;
  8675. if (spawn) {
  8676. if (!spawn->IsEntity()) {
  8677. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8678. return 0;
  8679. }
  8680. ((Entity*)spawn)->SetSnareValue(spell, val);
  8681. }
  8682. else if(spell->caster && spell->caster->GetZone()) {
  8683. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8684. for (int8 i = 0; i < spell->targets.size(); i++) {
  8685. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8686. if (!spawn || !spawn->IsEntity())
  8687. continue;
  8688. ((Entity*)spawn)->SetSnareValue(spell, val);
  8689. }
  8690. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8691. }
  8692. return 0;
  8693. }
  8694. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8695. if (!lua_interface)
  8696. return 0;
  8697. Spawn* spawn = lua_interface->GetSpawn(state);
  8698. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8699. lua_interface->ResetFunctionStack(state);
  8700. if (!spawn) {
  8701. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8702. return 0;
  8703. }
  8704. if (race_id == 0) {
  8705. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8706. return 0;
  8707. }
  8708. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8709. return 1;
  8710. }
  8711. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8712. if (!lua_interface)
  8713. return 0;
  8714. Spawn* spawn = lua_interface->GetSpawn(state);
  8715. lua_interface->ResetFunctionStack(state);
  8716. if (!spawn) {
  8717. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8718. return 0;
  8719. }
  8720. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8721. return 1;
  8722. }
  8723. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8724. if (!lua_interface)
  8725. return 0;
  8726. Spawn* spawn = lua_interface->GetSpawn(state);
  8727. lua_interface->ResetFunctionStack(state);
  8728. if (!spawn) {
  8729. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8733. return 1;
  8734. }
  8735. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8736. if (!lua_interface)
  8737. return 0;
  8738. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8739. lua_interface->ResetFunctionStack(state);
  8740. if (!spell) {
  8741. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8742. return 0;
  8743. }
  8744. lua_interface->SetStringValue(state, spell->spell->GetName());
  8745. return 1;
  8746. }
  8747. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8748. if (!lua_interface)
  8749. return 0;
  8750. Quest* quest = lua_interface->GetQuest(state);
  8751. lua_interface->ResetFunctionStack(state);
  8752. if (!quest) {
  8753. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8754. return 0;
  8755. }
  8756. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8757. return 1;
  8758. }
  8759. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8760. if (!lua_interface)
  8761. return 0;
  8762. Quest* quest = lua_interface->GetQuest(state);
  8763. int32 flags = lua_interface->GetInt32Value(state, 2);
  8764. lua_interface->ResetFunctionStack(state);
  8765. if (!quest) {
  8766. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8767. return 0;
  8768. }
  8769. quest->SetQuestFlags(flags);
  8770. return 0;
  8771. }
  8772. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8773. if (!lua_interface)
  8774. return 0;
  8775. Quest* quest = lua_interface->GetQuest(state);
  8776. Spawn* player = lua_interface->GetSpawn(state, 2);
  8777. int32 step = lua_interface->GetInt32Value(state, 3);
  8778. int32 duration = lua_interface->GetInt32Value(state, 4);
  8779. string action = lua_interface->GetStringValue(state, 5);
  8780. lua_interface->ResetFunctionStack(state);
  8781. if (!quest) {
  8782. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8783. return 0;
  8784. }
  8785. if (!player) {
  8786. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. if (!player->IsPlayer()) {
  8790. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8791. return 0;
  8792. }
  8793. if (step == 0) {
  8794. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. if (duration == 0) {
  8798. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. if (action.length() == 0) {
  8802. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. Client* client = ((Player*)player)->GetClient();
  8806. if (!client) {
  8807. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8808. return 0;
  8809. }
  8810. quest->SetTimerStep(step);
  8811. quest->AddFailedAction(step, action);
  8812. quest->SetStepTimer(duration);
  8813. client->AddQuestTimer(quest->GetQuestID());
  8814. return 0;
  8815. }
  8816. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8817. if (!lua_interface)
  8818. return 0;
  8819. Quest* quest = lua_interface->GetQuest(state);
  8820. Spawn* player = lua_interface->GetSpawn(state, 2);
  8821. lua_interface->ResetFunctionStack(state);
  8822. if (!quest) {
  8823. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. if (!player) {
  8827. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. if (!player->IsPlayer()) {
  8831. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. Client* client = ((Player*)player)->GetClient();
  8835. if (!client) {
  8836. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8837. return 0;
  8838. }
  8839. quest->SetTimerStep(0);
  8840. quest->SetStepTimer(0);
  8841. client->RemoveQuestTimer(quest->GetQuestID());
  8842. return 0;
  8843. }
  8844. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8845. if (!lua_interface)
  8846. return 0;
  8847. Spawn* player = lua_interface->GetSpawn(state);
  8848. Quest* quest = lua_interface->GetQuest(state, 2);
  8849. int32 step = lua_interface->GetInt32Value(state, 3);
  8850. lua_interface->ResetFunctionStack(state);
  8851. if (!player) {
  8852. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8853. return 0;
  8854. }
  8855. if (!player->IsPlayer()) {
  8856. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8857. return 0;
  8858. }
  8859. if (!quest) {
  8860. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8861. return 0;
  8862. }
  8863. if (step == 0) {
  8864. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. Client* client = ((Player*)player)->GetClient();
  8868. if (!client) {
  8869. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8870. return 0;
  8871. }
  8872. if (quest->RemoveQuestStep(step, client)) {
  8873. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8874. client->GetCurrentZone()->SendQuestUpdates(client);
  8875. }
  8876. else
  8877. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8878. return 0;
  8879. }
  8880. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8881. if (!lua_interface)
  8882. return 0;
  8883. Quest* quest = lua_interface->GetQuest(state, 1);
  8884. int32 step = lua_interface->GetInt32Value(state, 2);
  8885. string desc = lua_interface->GetStringValue(state, 3);
  8886. string task_group = lua_interface->GetStringValue(state, 4);
  8887. lua_interface->ResetFunctionStack(state);
  8888. if (!quest) {
  8889. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. if (step == 0) {
  8893. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. QuestStep* quest_step = quest->GetQuestStep(step);
  8897. if (!quest_step) {
  8898. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8899. return 0;
  8900. }
  8901. quest_step->SetStepProgress(0);
  8902. quest_step->SetTaskGroup(task_group);
  8903. quest_step->SetDescription(desc);
  8904. return 0;
  8905. }
  8906. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8907. if (!lua_interface)
  8908. return 0;
  8909. Quest* quest = lua_interface->GetQuest(state);
  8910. int32 step = lua_interface->GetInt32Value(state, 2);
  8911. string action = lua_interface->GetStringValue(state, 3);
  8912. lua_interface->ResetFunctionStack(state);
  8913. if (!quest) {
  8914. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. if (step == 0) {
  8918. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. if (action.length() == 0) {
  8922. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8923. return 0;
  8924. }
  8925. quest->AddFailedAction(step, action);
  8926. return 0;
  8927. }
  8928. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8929. if (!lua_interface)
  8930. return 0;
  8931. Spawn* player = lua_interface->GetSpawn(state);
  8932. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8933. int32 step = lua_interface->GetInt32Value(state, 3);
  8934. lua_interface->ResetFunctionStack(state);
  8935. if (!player) {
  8936. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8937. return 0;
  8938. }
  8939. if (!player->IsPlayer()) {
  8940. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8941. return 0;
  8942. }
  8943. if (quest_id == 0) {
  8944. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8945. return 0;
  8946. }
  8947. if (step == 0) {
  8948. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8949. return 0;
  8950. }
  8951. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8952. if (!quest) {
  8953. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8954. return 0;
  8955. }
  8956. quest->StepFailed(step);
  8957. return 0;
  8958. }
  8959. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8960. if (!lua_interface)
  8961. return 0;
  8962. Spawn* player = lua_interface->GetSpawn(state);
  8963. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8964. lua_interface->ResetFunctionStack(state);
  8965. if (!player) {
  8966. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. if (!player->IsPlayer()) {
  8970. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8971. return 0;
  8972. }
  8973. if (quest_id == 0) {
  8974. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8975. return 0;
  8976. }
  8977. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  8978. return 1;
  8979. }
  8980. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8981. if (!lua_interface)
  8982. return 0;
  8983. string name = lua_interface->GetStringValue(state);
  8984. string value = lua_interface->GetStringValue(state, 2);
  8985. string comment = lua_interface->GetStringValue(state, 3);
  8986. lua_interface->ResetFunctionStack(state);
  8987. if (name.length() == 0) {
  8988. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8989. return 0;
  8990. }
  8991. if (value.length() == 0) {
  8992. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8993. return 0;
  8994. }
  8995. string varname = string("lua_").append(name);
  8996. Variable* var = variables.FindVariable(varname);
  8997. if (var)
  8998. var->SetValue(value.c_str());
  8999. else {
  9000. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9001. variables.AddVariable(var);
  9002. }
  9003. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9004. return 0;
  9005. }
  9006. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9007. if (!lua_interface)
  9008. return 0;
  9009. string name = lua_interface->GetStringValue(state);
  9010. lua_interface->ResetFunctionStack(state);
  9011. if (name.length() == 0) {
  9012. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9013. return 0;
  9014. }
  9015. string varname = string("lua_").append(name);
  9016. Variable* var = variables.FindVariable(varname);
  9017. if (var)
  9018. lua_interface->SetStringValue(state, var->GetValue());
  9019. else
  9020. lua_interface->SetStringValue(state, "NULL");
  9021. return 1;
  9022. }
  9023. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9024. if (!lua_interface)
  9025. return 0;
  9026. Spawn* player = lua_interface->GetSpawn(state);
  9027. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9028. lua_interface->ResetFunctionStack(state);
  9029. if (!player) {
  9030. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9031. return 0;
  9032. }
  9033. if (!player->IsPlayer()) {
  9034. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9035. return 0;
  9036. }
  9037. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9038. return 1;
  9039. }
  9040. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9041. if (!lua_interface)
  9042. return 0;
  9043. Spawn* player = lua_interface->GetSpawn(state);
  9044. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9045. lua_interface->ResetFunctionStack(state);
  9046. if (!player) {
  9047. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9048. return 0;
  9049. }
  9050. if (!player->IsPlayer()) {
  9051. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. Language* language = master_languages_list.GetLanguage(language_id);
  9055. if (language)
  9056. {
  9057. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9058. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9059. }
  9060. return 0;
  9061. }
  9062. int EQ2Emu_lua_IsNight(lua_State* state) {
  9063. if (!lua_interface)
  9064. return 0;
  9065. ZoneServer* zone = lua_interface->GetZone(state);
  9066. lua_interface->ResetFunctionStack(state);
  9067. if (!zone) {
  9068. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9072. return 1;
  9073. }
  9074. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9075. if (!lua_interface)
  9076. return 0;
  9077. Spawn* spawn = lua_interface->GetSpawn(state);
  9078. lua_interface->ResetFunctionStack(state);
  9079. if (!spawn) {
  9080. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9081. return 0;
  9082. }
  9083. if (!spawn->IsWidget()) {
  9084. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9085. return 0;
  9086. }
  9087. ((Widget*)spawn)->SetMultiFloorLift(true);
  9088. if (spawn->GetZone())
  9089. spawn->GetZone()->AddTransportSpawn(spawn);
  9090. return 0;
  9091. }
  9092. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9093. if (!lua_interface)
  9094. return 0;
  9095. Spawn* player = lua_interface->GetSpawn(state);
  9096. int32 path = lua_interface->GetInt32Value(state, 2);
  9097. lua_interface->ResetFunctionStack(state);
  9098. if (!player) {
  9099. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9100. return 0;
  9101. }
  9102. if (!player->IsPlayer()) {
  9103. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9104. return 0;
  9105. }
  9106. if (path == 0) {
  9107. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9108. return 0;
  9109. }
  9110. Client* client = ((Player*)player)->GetClient();
  9111. if (!client) {
  9112. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9113. return 0;
  9114. }
  9115. client->SendFlightAutoMount(path);
  9116. return 0;
  9117. }
  9118. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9119. if (!lua_interface)
  9120. return 0;
  9121. Spawn* player = lua_interface->GetSpawn(state);
  9122. if (!player) {
  9123. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9124. return 0;
  9125. }
  9126. if (!player->IsPlayer()) {
  9127. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9128. return 0;
  9129. }
  9130. Client* client = ((Player*)player)->GetClient();
  9131. if (!client) {
  9132. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9133. return 0;
  9134. }
  9135. client->EndAutoMount();
  9136. return 0;
  9137. }
  9138. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9139. if (!lua_interface)
  9140. return 0;
  9141. Spawn* player = lua_interface->GetSpawn(state);
  9142. lua_interface->ResetFunctionStack(state);
  9143. if (!player) {
  9144. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9145. return 0;
  9146. }
  9147. if (!player->IsPlayer()) {
  9148. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9149. return 0;
  9150. }
  9151. Client* client = ((Player*)player)->GetClient();
  9152. if (!client) {
  9153. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9154. return 0;
  9155. }
  9156. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9157. return 1;
  9158. }
  9159. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9160. if (!lua_interface)
  9161. return 0;
  9162. Spawn* player = lua_interface->GetSpawn(state);
  9163. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9164. int32 value = lua_interface->GetInt32Value(state, 3);
  9165. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9166. lua_interface->ResetFunctionStack(state);
  9167. if (!player) {
  9168. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9169. return 0;
  9170. }
  9171. if (!player->IsPlayer()) {
  9172. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9173. return 0;
  9174. }
  9175. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9176. return 0;
  9177. }
  9178. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9179. if (!lua_interface)
  9180. return 0;
  9181. Spawn* player = lua_interface->GetSpawn(state);
  9182. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9183. lua_interface->ResetFunctionStack(state);
  9184. if (!player) {
  9185. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9186. return 0;
  9187. }
  9188. if (!player->IsPlayer()) {
  9189. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9190. return 0;
  9191. }
  9192. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9193. if (!hd)
  9194. return 0;
  9195. lua_interface->SetInt32Value(state, hd->Value);
  9196. lua_interface->SetInt32Value(state, hd->Value2);
  9197. return 2;
  9198. }
  9199. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9200. if (!lua_interface)
  9201. return 0;
  9202. Spawn* spawn = lua_interface->GetSpawn(state);
  9203. int32 grid = lua_interface->GetInt32Value(state, 2);
  9204. lua_interface->ResetFunctionStack(state);
  9205. if (!spawn) {
  9206. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9207. return 0;
  9208. }
  9209. if (grid == 0) {
  9210. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9211. return 0;
  9212. }
  9213. spawn->SetLocation(grid);
  9214. return 0;
  9215. }
  9216. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9217. if (!lua_interface)
  9218. return 0;
  9219. Spawn* spawn = lua_interface->GetSpawn(state);
  9220. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9221. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9222. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9223. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9224. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9225. lua_interface->ResetFunctionStack(state);
  9226. if (!spawn) {
  9227. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9228. return 0;
  9229. }
  9230. //Add this quest to the list of required quests for this spawn
  9231. spawn->SetRequiredHistory(event_id, value1, value2);
  9232. //If private spawn value set
  9233. if (private_spawn) {
  9234. //Set the spawn to be private when not granted access via history
  9235. spawn->AddAllowAccessSpawn(spawn);
  9236. spawn->SetPrivateQuestSpawn(true);
  9237. }
  9238. //This value will override vis_flags in the vis packet
  9239. if (flag_override > 0)
  9240. spawn->SetQuestsRequiredOverride(flag_override);
  9241. return 0;
  9242. }
  9243. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9244. if (!lua_interface)
  9245. return 0;
  9246. Spawn* player = lua_interface->GetSpawn(state);
  9247. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9248. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9249. lua_interface->ResetFunctionStack(state);
  9250. if (!player) {
  9251. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9252. return 0;
  9253. }
  9254. if (!player->IsPlayer()) {
  9255. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9256. return 0;
  9257. }
  9258. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9259. return 1;
  9260. }
  9261. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9262. if (!lua_interface)
  9263. return 0;
  9264. Spawn* player = lua_interface->GetSpawn(state);
  9265. int8 level = lua_interface->GetInt8Value(state, 2);
  9266. lua_interface->ResetFunctionStack(state);
  9267. if (!player) {
  9268. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9269. return 0;
  9270. }
  9271. if (!player->IsPlayer()) {
  9272. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. if (level == 0) {
  9276. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9277. return 0;
  9278. }
  9279. Client* client = ((Player*)player)->GetClient();
  9280. if (!client) {
  9281. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9282. return 0;
  9283. }
  9284. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9285. return 0;
  9286. }
  9287. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9288. if (!lua_interface)
  9289. return 0;
  9290. Spawn* player = lua_interface->GetSpawn(state);
  9291. int32 amount = lua_interface->GetInt32Value(state, 2);
  9292. lua_interface->ResetFunctionStack(state);
  9293. if (!player) {
  9294. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9295. return 0;
  9296. }
  9297. if (!player->IsPlayer()) {
  9298. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. if (amount == 0) {
  9302. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9303. return 0;
  9304. }
  9305. ((Player*)player)->AddCoins(amount);
  9306. return 0;
  9307. }
  9308. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9309. if (!lua_interface)
  9310. return 0;
  9311. Spawn* player = lua_interface->GetSpawn(state);
  9312. int32 amount = lua_interface->GetInt32Value(state, 2);
  9313. lua_interface->ResetFunctionStack(state);
  9314. if (!player) {
  9315. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9316. return 0;
  9317. }
  9318. if (!player->IsPlayer()) {
  9319. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9320. return 0;
  9321. }
  9322. if (amount == 0) {
  9323. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9324. return 0;
  9325. }
  9326. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9327. return 1;
  9328. }
  9329. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9330. if (!lua_interface)
  9331. return 0;
  9332. ZoneServer* zone = lua_interface->GetZone(state);
  9333. lua_interface->ResetFunctionStack(state);
  9334. if (!zone) {
  9335. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9336. return 0;
  9337. }
  9338. vector<Entity*> players = zone->GetPlayers();
  9339. if (players.size() == 0)
  9340. return 0;
  9341. lua_createtable(state, players.size(), 0);
  9342. int newTable = lua_gettop(state);
  9343. for (int32 i = 0; i < players.size(); i++) {
  9344. lua_interface->SetSpawnValue(state, players.at(i));
  9345. lua_rawseti(state, newTable, i + 1);
  9346. }
  9347. return 1;
  9348. }
  9349. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9350. if (!lua_interface)
  9351. return 0;
  9352. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9353. if (!zone) {
  9354. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9355. return 0;
  9356. }
  9357. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9358. lua_interface->ResetFunctionStack(state);
  9359. //Map of <placement_id, location_id>
  9360. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9361. map<int32, int32>::iterator itr;
  9362. vector<Spawn*> group;
  9363. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9364. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9365. if (!location) {
  9366. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9367. return 0;
  9368. }
  9369. Spawn* spawn = 0;
  9370. if (location->entities[0]) {
  9371. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9372. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9373. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9374. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9375. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9376. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9377. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9378. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9379. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9380. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9381. if(spawn && spawn->IsOmittedByDBFlag())
  9382. {
  9383. 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);
  9384. safe_delete(spawn);
  9385. continue;
  9386. }
  9387. if (spawn) {
  9388. const char* script = 0;
  9389. for (int x = 0; x < 3; x++) {
  9390. switch (x) {
  9391. case 0:
  9392. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9393. break;
  9394. case 1:
  9395. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9396. break;
  9397. case 2:
  9398. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9399. break;
  9400. }
  9401. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9402. spawn->SetSpawnScript(string(script));
  9403. break;
  9404. }
  9405. }
  9406. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9407. lua_interface->SetSpawnValue(state, spawn);
  9408. group.push_back(spawn);
  9409. }
  9410. else {
  9411. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9412. safe_delete(spawn);
  9413. }
  9414. }
  9415. }
  9416. if (!group.empty()) {
  9417. lua_createtable(state, group.size(), 0);
  9418. int newTable = lua_gettop(state);
  9419. for (int32 i = 0; i < group.size(); i++) {
  9420. lua_interface->SetSpawnValue(state, group[i]);
  9421. lua_rawseti(state, newTable, i + 1);
  9422. }
  9423. }
  9424. else
  9425. lua_pushnil(state);
  9426. return 1;
  9427. }
  9428. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9429. if (!lua_interface)
  9430. return 0;
  9431. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9432. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9433. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9434. lua_interface->ResetFunctionStack(state);
  9435. if (!spawn) {
  9436. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9437. return 0;
  9438. }
  9439. if (anim_id == 0) {
  9440. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9441. return 0;
  9442. }
  9443. if (leeway == 0)
  9444. leeway = 5000;
  9445. spawn->SetSpawnAnim(anim_id);
  9446. spawn->SetSpawnAnimLeeway(leeway);
  9447. return 0;
  9448. }
  9449. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9450. if (!lua_interface)
  9451. return 0;
  9452. Spawn* player = lua_interface->GetSpawn(state);
  9453. lua_interface->ResetFunctionStack(state);
  9454. if (!player || !player->IsPlayer()) {
  9455. return 0;
  9456. }
  9457. Client* client = ((Player*)player)->GetClient();
  9458. if (!client) {
  9459. return 0;
  9460. }
  9461. lua_interface->SetInt32Value(state, client->GetVersion());
  9462. return 1;
  9463. }
  9464. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9465. if (!lua_interface)
  9466. return 0;
  9467. Item* item = lua_interface->GetItem(state);
  9468. lua_interface->ResetFunctionStack(state);
  9469. if (!item) {
  9470. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9471. return 0;
  9472. }
  9473. lua_interface->SetInt32Value(state, item->details.item_id);
  9474. return 1;
  9475. }
  9476. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9477. if (!lua_interface)
  9478. return 0;
  9479. Spawn* spawn = lua_interface->GetSpawn(state);
  9480. lua_interface->ResetFunctionStack(state);
  9481. if (!spawn) {
  9482. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9483. return 0;
  9484. }
  9485. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9486. return 1;
  9487. }
  9488. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9489. if (!lua_interface)
  9490. return 0;
  9491. Spawn* spawn = lua_interface->GetSpawn(state);
  9492. lua_interface->ResetFunctionStack(state);
  9493. if (!spawn) {
  9494. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9495. return 0;
  9496. }
  9497. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9498. return 1;
  9499. }
  9500. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9501. if (!lua_interface)
  9502. return 0;
  9503. Spawn* spawn = lua_interface->GetSpawn(state);
  9504. lua_interface->ResetFunctionStack(state);
  9505. if (!spawn) {
  9506. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9507. return 0;
  9508. }
  9509. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9510. return 1;
  9511. }
  9512. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9513. if (!lua_interface)
  9514. return 0;
  9515. Spawn* spawn = lua_interface->GetSpawn(state);
  9516. lua_interface->ResetFunctionStack(state);
  9517. if (!spawn) {
  9518. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9519. return 0;
  9520. }
  9521. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9522. return 1;
  9523. }
  9524. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9525. if (!lua_interface)
  9526. return 0;
  9527. Spawn* spawn = lua_interface->GetSpawn(state);
  9528. float pct = lua_interface->GetFloatValue(state, 2);
  9529. lua_interface->ResetFunctionStack(state);
  9530. if (!spawn) {
  9531. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9532. return 0;
  9533. }
  9534. if (pct == 0) {
  9535. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9536. return 0;
  9537. }
  9538. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9539. lua_interface->SetInt32Value(state, amount);
  9540. return 1;
  9541. }
  9542. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9543. if (!lua_interface)
  9544. return 0;
  9545. Spawn* spawn = lua_interface->GetSpawn(state);
  9546. float pct = lua_interface->GetFloatValue(state, 2);
  9547. lua_interface->ResetFunctionStack(state);
  9548. if (!spawn) {
  9549. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9550. return 0;
  9551. }
  9552. if (pct == 0) {
  9553. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9554. return 0;
  9555. }
  9556. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9557. lua_interface->SetInt32Value(state, amount);
  9558. return 1;
  9559. }
  9560. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9561. if (!lua_interface)
  9562. return 0;
  9563. Spawn* spawn = lua_interface->GetSpawn(state);
  9564. lua_interface->ResetFunctionStack(state);
  9565. if (!spawn) {
  9566. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9567. return 0;
  9568. }
  9569. if (!spawn->IsPlayer()) {
  9570. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9571. return 0;
  9572. }
  9573. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9574. return 1;
  9575. }
  9576. int EQ2Emu_lua_Evac(lua_State* state) {
  9577. if (!lua_interface)
  9578. return 0;
  9579. Spawn* target = lua_interface->GetSpawn(state);
  9580. if (target) {
  9581. float x = target->GetZone()->GetSafeX();
  9582. float y = target->GetZone()->GetSafeY();
  9583. float z = target->GetZone()->GetSafeZ();
  9584. float h = target->GetZone()->GetSafeHeading();
  9585. target->SetX(x);
  9586. target->SetY(y);
  9587. target->SetZ(z);
  9588. target->SetHeading(h);
  9589. target->SetSpawnOrigX(x);
  9590. target->SetSpawnOrigY(y);
  9591. target->SetSpawnOrigZ(z);
  9592. target->SetSpawnOrigHeading(h);
  9593. if (target->IsPlayer()) {
  9594. Client* client = ((Player*)target)->GetClient();
  9595. if (client) {
  9596. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9597. int numargs = lua_interface->GetNumberOfArgs(state);
  9598. if(numargs == 4) {
  9599. x = lua_interface->GetFloatValue(state,1);
  9600. y = lua_interface->GetFloatValue(state,2);
  9601. z = lua_interface->GetFloatValue(state,3);
  9602. h = lua_interface->GetFloatValue(state,4);
  9603. }
  9604. client->SetReloadingZone(true);
  9605. target->SetX(x);
  9606. target->SetY(y);
  9607. target->SetZ(z);
  9608. target->SetHeading(h);
  9609. target->SetSpawnOrigX(x);
  9610. target->SetSpawnOrigY(y);
  9611. target->SetSpawnOrigZ(z);
  9612. target->SetSpawnOrigHeading(h);
  9613. target->SetAppearancePosition(x,y,z);
  9614. client->SetZoningCoords(x,y,z,h);
  9615. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9616. if (packet)
  9617. {
  9618. packet->setDataByName("x", x);
  9619. packet->setDataByName("y", y);
  9620. packet->setDataByName("z", z);
  9621. client->QueuePacket(packet->serialize());
  9622. safe_delete(packet);
  9623. }
  9624. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9625. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9626. }
  9627. }
  9628. lua_interface->ResetFunctionStack(state);
  9629. }
  9630. else {
  9631. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9632. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9633. lua_interface->ResetFunctionStack(state);
  9634. return 0;
  9635. }
  9636. ZoneServer* zone = spell->caster->GetZone();
  9637. float x = spell->caster->GetZone()->GetSafeX();
  9638. float y = spell->caster->GetZone()->GetSafeY();
  9639. float z = spell->caster->GetZone()->GetSafeZ();
  9640. float h = spell->caster->GetZone()->GetSafeHeading();
  9641. int numargs = lua_interface->GetNumberOfArgs(state);
  9642. if(numargs == 4) {
  9643. x = lua_interface->GetFloatValue(state,1);
  9644. y = lua_interface->GetFloatValue(state,2);
  9645. z = lua_interface->GetFloatValue(state,3);
  9646. h = lua_interface->GetFloatValue(state,4);
  9647. }
  9648. lua_interface->ResetFunctionStack(state);
  9649. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9650. for (int32 i = 0; i < spell->targets.size(); i++) {
  9651. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9652. if (!target2)
  9653. continue;
  9654. if (target2->IsPlayer()) {
  9655. Client* client = ((Player*)target2)->GetClient();
  9656. if (client) {
  9657. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9658. client->SetReloadingZone(true);
  9659. target2->SetX(x);
  9660. target2->SetY(y);
  9661. target2->SetZ(z);
  9662. target2->SetHeading(h);
  9663. target2->SetSpawnOrigX(x);
  9664. target2->SetSpawnOrigY(y);
  9665. target2->SetSpawnOrigZ(z);
  9666. target2->SetSpawnOrigHeading(h);
  9667. target2->SetAppearancePosition(x,y,z);
  9668. client->SetZoningCoords(x,y,z,h);
  9669. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9670. if (packet)
  9671. {
  9672. packet->setDataByName("x", x);
  9673. packet->setDataByName("y", y);
  9674. packet->setDataByName("z", z);
  9675. client->QueuePacket(packet->serialize());
  9676. safe_delete(packet);
  9677. }
  9678. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9679. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9680. }
  9681. }
  9682. }
  9683. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9684. }
  9685. return 0;
  9686. }
  9687. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9688. if (!lua_interface)
  9689. return 0;
  9690. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9691. lua_interface->ResetFunctionStack(state);
  9692. if (!luaspell) {
  9693. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9694. return 0;
  9695. }
  9696. int8 tier = luaspell->spell->GetSpellTier();
  9697. lua_interface->SetInt32Value(state, tier);
  9698. return 1;
  9699. }
  9700. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9701. if (!lua_interface)
  9702. return 0;
  9703. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9704. lua_interface->ResetFunctionStack(state);
  9705. if (!luaspell) {
  9706. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9707. return 0;
  9708. }
  9709. int32 spell_id = luaspell->spell->GetSpellID();
  9710. lua_interface->SetInt32Value(state, spell_id);
  9711. return 1;
  9712. }
  9713. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9714. if (!lua_interface)
  9715. return 0;
  9716. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9717. lua_interface->ResetFunctionStack(state);
  9718. if (!spawn) {
  9719. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9720. return 0;
  9721. }
  9722. if (!spawn->IsPlayer()) {
  9723. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9724. return 0;
  9725. }
  9726. ZoneServer* zone = spawn->GetZone();
  9727. if (!zone) {
  9728. return 0;
  9729. }
  9730. Client* client = ((Player*)spawn)->GetClient();
  9731. if (!client) {
  9732. return 0;
  9733. }
  9734. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9735. return 0;
  9736. }
  9737. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9738. if (!lua_interface)
  9739. return 0;
  9740. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9741. lua_interface->ResetFunctionStack(state);
  9742. if (!spawn) {
  9743. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9744. return 0;
  9745. }
  9746. if (!spawn->IsPlayer()) {
  9747. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9748. return 0;
  9749. }
  9750. ZoneServer* zone = spawn->GetZone();
  9751. if (!zone) {
  9752. return 0;
  9753. }
  9754. Client* client = ((Player*)spawn)->GetClient();
  9755. if (!client) {
  9756. return 0;
  9757. }
  9758. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9759. return 0;
  9760. }
  9761. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9762. if (!lua_interface)
  9763. return 0;
  9764. Spawn* caster = lua_interface->GetSpawn(state);
  9765. Spawn* target = lua_interface->GetSpawn(state, 2);
  9766. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9767. string spell_name = lua_interface->GetStringValue(state, 4);
  9768. lua_interface->ResetFunctionStack(state);
  9769. if (!caster) {
  9770. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9771. return 0;
  9772. }
  9773. if (!caster->IsEntity()) {
  9774. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9775. return 0;
  9776. }
  9777. if (!target) {
  9778. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9779. return 0;
  9780. }
  9781. if (!target->IsEntity()) {
  9782. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9783. return 0;
  9784. }
  9785. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9786. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9787. return 0;
  9788. }
  9789. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9790. if (!lua_interface)
  9791. return 0;
  9792. Spawn* player = lua_interface->GetSpawn(state);
  9793. int32 amount = lua_interface->GetInt32Value(state, 2);
  9794. lua_interface->ResetFunctionStack(state);
  9795. if (player && player->IsPlayer() && amount > 0) {
  9796. ((Player*)player)->AddXP(amount);
  9797. }
  9798. return 0;
  9799. }
  9800. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9801. if (!lua_interface)
  9802. return 0;
  9803. Spawn* player = lua_interface->GetSpawn(state);
  9804. int8 type = lua_interface->GetInt8Value(state, 2);
  9805. string text = lua_interface->GetStringValue(state, 3);
  9806. lua_interface->ResetFunctionStack(state);
  9807. Client* client = 0;
  9808. if (player && player->IsPlayer())
  9809. client = ((Player*)player)->GetClient();
  9810. if (!client || text.length() == 0) {
  9811. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9812. return 0;
  9813. }
  9814. client->SimpleMessage(type, text.c_str());
  9815. return 0;
  9816. }
  9817. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9818. if (!lua_interface)
  9819. return 0;
  9820. Spawn* player = lua_interface->GetSpawn(state);
  9821. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9822. lua_interface->ResetFunctionStack(state);
  9823. Client* client = 0;
  9824. if (player && player->IsPlayer())
  9825. client = ((Player*)player)->GetClient();
  9826. if (!client || !spawn) {
  9827. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9828. return 0;
  9829. }
  9830. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9831. if (!items) {
  9832. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9833. return 0;
  9834. }
  9835. client->Loot(spawn->GetLootCoins(), items, spawn);
  9836. return 0;
  9837. }
  9838. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9839. if (!lua_interface)
  9840. return 0;
  9841. Spawn* spawnref = lua_interface->GetSpawn(state);
  9842. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9843. lua_interface->ResetFunctionStack(state);
  9844. if (spawn_id > 0 && spawnref) {
  9845. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9846. if (spawns.size() == 0) {
  9847. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9848. return 0;
  9849. }
  9850. Spawn* spawn = 0;
  9851. int16 index = MakeRandomInt(0, spawns.size());
  9852. if (index >= spawns.size() || index < 0)
  9853. index = 0;
  9854. spawn = spawns[index];
  9855. lua_interface->SetSpawnValue(state, spawn);
  9856. return 1;
  9857. }
  9858. else {
  9859. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9860. }
  9861. return 0;
  9862. }
  9863. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9864. Spawn* player = lua_interface->GetSpawn(state);
  9865. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9866. string name = lua_interface->GetStringValue(state, 3);
  9867. float distance = lua_interface->GetFloatValue(state, 4);
  9868. string command = lua_interface->GetStringValue(state, 5);
  9869. string error_text = lua_interface->GetStringValue(state, 6);
  9870. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9871. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9872. lua_interface->ResetFunctionStack(state);
  9873. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9874. if (distance == 0)
  9875. distance = 10.0f;
  9876. if (command.length() == 0)
  9877. command = name;
  9878. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9879. if (spawns.size() == 0) {
  9880. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9881. return 0;
  9882. }
  9883. Spawn* spawn = 0;
  9884. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9885. spawn = *itr;
  9886. if (spawn) {
  9887. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9888. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9889. }
  9890. }
  9891. }
  9892. return 0;
  9893. }
  9894. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9895. if (!lua_interface)
  9896. return 0;
  9897. Client* client = 0;
  9898. Spawn* player = lua_interface->GetSpawn(state);
  9899. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9900. lua_interface->ResetFunctionStack(state);
  9901. if (player && player->IsPlayer() && player->GetZone())
  9902. client = ((Player*)player)->GetClient();
  9903. else{
  9904. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9905. return 0;
  9906. }
  9907. if (client) {
  9908. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9909. if (packet) {
  9910. packet->setDataByName("goal_num", goal_num);
  9911. client->QueuePacket(packet->serialize());
  9912. safe_delete(packet);
  9913. }
  9914. }
  9915. return 0;
  9916. }
  9917. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9918. if (!lua_interface)
  9919. return 0;
  9920. Client* client = 0;
  9921. Spawn* player = lua_interface->GetSpawn(state);
  9922. lua_interface->ResetFunctionStack(state);
  9923. if (player && player->IsPlayer() && player->GetZone())
  9924. client = ((Player*)player)->GetClient();
  9925. else {
  9926. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9927. return 0;
  9928. }
  9929. if (client) {
  9930. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9931. }
  9932. return 0;
  9933. }
  9934. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9935. if (!lua_interface)
  9936. return 0;
  9937. Client* client = 0;
  9938. Spawn* player = lua_interface->GetSpawn(state);
  9939. float duration = lua_interface->GetFloatValue(state, 2);
  9940. string text = lua_interface->GetStringValue(state, 3);
  9941. string voice = lua_interface->GetStringValue(state, 4);
  9942. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9943. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9944. string signal = lua_interface->GetStringValue(state, 7);
  9945. string goal1 = lua_interface->GetStringValue(state, 8);
  9946. string task1 = lua_interface->GetStringValue(state, 9);
  9947. string goal2 = lua_interface->GetStringValue(state, 10);
  9948. string task2 = lua_interface->GetStringValue(state, 11);
  9949. string goal3 = lua_interface->GetStringValue(state, 12);
  9950. string task3 = lua_interface->GetStringValue(state, 13);
  9951. string goal4 = lua_interface->GetStringValue(state, 14);
  9952. string task4 = lua_interface->GetStringValue(state, 15);
  9953. lua_interface->ResetFunctionStack(state);
  9954. if (!player) {
  9955. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9956. return 0;
  9957. }
  9958. if (!player->IsPlayer()) {
  9959. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9960. return 0;
  9961. }
  9962. else
  9963. client = ((Player*)player)->GetClient();
  9964. if (!client) {
  9965. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9966. return 0;
  9967. }
  9968. if (text.length() == 0) {
  9969. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9970. return 0;
  9971. }
  9972. if (duration >= 0 && duration < 2)
  9973. duration = 2;
  9974. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9975. if (packet) {
  9976. packet->setDataByName("open_seconds_max", duration);
  9977. packet->setDataByName("text", text.c_str());
  9978. packet->setDataByName("voice", voice.c_str());
  9979. int8 num_goals = 1;
  9980. if (task2.length() > 0)
  9981. num_goals++;
  9982. if (task3.length() > 0)
  9983. num_goals++;
  9984. if (task4.length() > 0)
  9985. num_goals++;
  9986. packet->setArrayLengthByName("num_goals", num_goals);
  9987. for (int8 i = 0; i < num_goals; i++) {
  9988. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9989. }
  9990. if (goal1.length() > 0)
  9991. packet->setArrayDataByName("goal_text", goal1.c_str());
  9992. if (goal2.length() > 0)
  9993. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9994. if (goal3.length() > 0)
  9995. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9996. if (goal4.length() > 0)
  9997. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9998. packet->setSubArrayDataByName("task_text", task1.c_str());
  9999. if (task2.length() > 0)
  10000. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10001. if (task3.length() > 0)
  10002. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10003. if (task4.length() > 0)
  10004. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10005. packet->setDataByName("complete_sound", "click");
  10006. packet->setDataByName("signal", signal.c_str());
  10007. packet->setDataByName("voice_key1", voice_key1);
  10008. packet->setDataByName("voice_key2", voice_key2);
  10009. client->QueuePacket(packet->serialize());
  10010. safe_delete(packet);
  10011. }
  10012. return 0;
  10013. }
  10014. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10015. if (!lua_interface)
  10016. return 0;
  10017. Client* client = 0;
  10018. Spawn* player = lua_interface->GetSpawn(state);
  10019. string window = lua_interface->GetStringValue(state, 2);
  10020. int8 show = lua_interface->GetInt8Value(state, 3);
  10021. lua_interface->ResetFunctionStack(state);
  10022. if (!player) {
  10023. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10024. return 0;
  10025. }
  10026. if (!player->IsPlayer()) {
  10027. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10028. return 0;
  10029. }
  10030. else
  10031. client = ((Player*)player)->GetClient();
  10032. if (!client) {
  10033. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10034. return 0;
  10035. }
  10036. if (window.length() == 0) {
  10037. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10038. return 0;
  10039. }
  10040. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10041. if (packet) {
  10042. packet->setDataByName("window", window.c_str());
  10043. packet->setDataByName("show", show);
  10044. client->QueuePacket(packet->serialize());
  10045. safe_delete(packet);
  10046. }
  10047. return 0;
  10048. }
  10049. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10050. //See GameEvents.txt for options that can be used for this function
  10051. if (!lua_interface)
  10052. return 0;
  10053. Client* client = 0;
  10054. Spawn* player = lua_interface->GetSpawn(state);
  10055. string event_name = lua_interface->GetStringValue(state, 2);
  10056. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10057. lua_interface->ResetFunctionStack(state);
  10058. if (!player || !player->IsPlayer()) {
  10059. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10060. return 0;
  10061. }
  10062. client = ((Player*)player)->GetClient();
  10063. if (!client) {
  10064. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10065. return 0;
  10066. }
  10067. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10068. if (packet) {
  10069. packet->setDataByName("event_name", event_name.c_str());
  10070. packet->setDataByName("enabled", enabled);
  10071. client->QueuePacket(packet->serialize());
  10072. safe_delete(packet);
  10073. }
  10074. return 0;
  10075. }
  10076. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10077. if (!lua_interface)
  10078. return 0;
  10079. Spawn* player = lua_interface->GetSpawn(state);
  10080. lua_interface->ResetFunctionStack(state);
  10081. if (player && player->IsPlayer()) {
  10082. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10083. return 1;
  10084. }
  10085. return 0;
  10086. }
  10087. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10088. if (!lua_interface)
  10089. return 0;
  10090. Spawn* player = lua_interface->GetSpawn(state);
  10091. int8 step = lua_interface->GetInt8Value(state, 2);
  10092. lua_interface->ResetFunctionStack(state);
  10093. if (player && player->IsPlayer() && step > 0) {
  10094. ((Player*)player)->SetTutorialStep(step);
  10095. }
  10096. return 0;
  10097. }
  10098. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10099. if (!lua_interface)
  10100. return 0;
  10101. Client* client = 0;
  10102. Spawn* player = lua_interface->GetSpawn(state);
  10103. string window = lua_interface->GetStringValue(state, 2);
  10104. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10105. lua_interface->ResetFunctionStack(state);
  10106. if (!player) {
  10107. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10108. return 0;
  10109. }
  10110. if (!player->IsPlayer()) {
  10111. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10112. return 0;
  10113. }
  10114. else
  10115. client = ((Player*)player)->GetClient();
  10116. if (!client) {
  10117. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10118. return 0;
  10119. }
  10120. if (window.length() == 0) {
  10121. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10122. return 0;
  10123. }
  10124. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10125. if (packet) {
  10126. packet->setDataByName("window", window.c_str());
  10127. packet->setDataByName("flash_seconds", flash_seconds);
  10128. client->QueuePacket(packet->serialize());
  10129. safe_delete(packet);
  10130. }
  10131. return 0;
  10132. }
  10133. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10134. if (!lua_interface)
  10135. return 0;
  10136. Spawn* spawn = lua_interface->GetSpawn(state);
  10137. Spawn* target = lua_interface->GetSpawn(state, 2);
  10138. lua_interface->ResetFunctionStack(state);
  10139. if (spawn && target)
  10140. return spawn->CheckLoS(target);
  10141. return 0;
  10142. }
  10143. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10144. if (!lua_interface)
  10145. return 0;
  10146. Spawn* spawn = lua_interface->GetSpawn(state);
  10147. float x = lua_interface->GetFloatValue(state, 2);
  10148. float y = lua_interface->GetFloatValue(state, 3);
  10149. float z = lua_interface->GetFloatValue(state, 4);
  10150. lua_interface->ResetFunctionStack(state);
  10151. if (spawn)
  10152. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10153. return 0;
  10154. }
  10155. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10156. if (!lua_interface)
  10157. return 0;
  10158. ZoneServer* zone = lua_interface->GetZone(state);
  10159. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10160. lua_interface->ResetFunctionStack(state);
  10161. if (zone)
  10162. zone->SetExpansionFlag(xpackFlag);
  10163. return 0;
  10164. }
  10165. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10166. if (!lua_interface)
  10167. return 0;
  10168. ZoneServer* zone = lua_interface->GetZone(state);
  10169. lua_interface->ResetFunctionStack(state);
  10170. if (zone) {
  10171. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10172. return 1;
  10173. }
  10174. return 0;
  10175. }
  10176. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10177. if (!lua_interface)
  10178. return 0;
  10179. ZoneServer* zone = lua_interface->GetZone(state);
  10180. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10181. lua_interface->ResetFunctionStack(state);
  10182. if (zone)
  10183. zone->SetHolidayFlag(holidayFlag);
  10184. return 0;
  10185. }
  10186. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10187. if (!lua_interface)
  10188. return 0;
  10189. ZoneServer* zone = lua_interface->GetZone(state);
  10190. lua_interface->ResetFunctionStack(state);
  10191. if (zone) {
  10192. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10193. return 1;
  10194. }
  10195. return 0;
  10196. }
  10197. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10198. if (!lua_interface)
  10199. return 0;
  10200. Spawn* spawn = lua_interface->GetSpawn(state);
  10201. bool canbind = lua_interface->GetInt32Value(state, 2);
  10202. lua_interface->ResetFunctionStack(state);
  10203. if(!spawn) {
  10204. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10205. return 0;
  10206. }
  10207. ZoneServer* zone = spawn->GetZone();
  10208. if (zone)
  10209. zone->SetCanBind(canbind);
  10210. return 0;
  10211. }
  10212. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10213. if (!lua_interface)
  10214. return 0;
  10215. Spawn* spawn = lua_interface->GetSpawn(state);
  10216. lua_interface->ResetFunctionStack(state);
  10217. if(!spawn) {
  10218. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10219. return 0;
  10220. }
  10221. ZoneServer* zone = spawn->GetZone();
  10222. if (zone) {
  10223. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10224. return 1;
  10225. }
  10226. return 0;
  10227. }
  10228. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10229. if (!lua_interface)
  10230. return 0;
  10231. Spawn* spawn = lua_interface->GetSpawn(state);
  10232. bool cangate = lua_interface->GetInt32Value(state, 2);
  10233. lua_interface->ResetFunctionStack(state);
  10234. if(!spawn) {
  10235. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10236. return 0;
  10237. }
  10238. ZoneServer* zone = spawn->GetZone();
  10239. if (zone)
  10240. zone->SetCanGate(cangate);
  10241. return 0;
  10242. }
  10243. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10244. if (!lua_interface)
  10245. return 0;
  10246. Spawn* spawn = lua_interface->GetSpawn(state);
  10247. lua_interface->ResetFunctionStack(state);
  10248. if(!spawn) {
  10249. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10250. return 0;
  10251. }
  10252. ZoneServer* zone = spawn->GetZone();
  10253. if (zone) {
  10254. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10255. return 1;
  10256. }
  10257. return 0;
  10258. }
  10259. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10260. if (!lua_interface)
  10261. return 0;
  10262. Spawn* spawn = lua_interface->GetSpawn(state);
  10263. bool canevac = lua_interface->GetInt32Value(state, 2);
  10264. lua_interface->ResetFunctionStack(state);
  10265. if(!spawn) {
  10266. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10267. return 0;
  10268. }
  10269. ZoneServer* zone = spawn->GetZone();
  10270. if (zone)
  10271. zone->SetCanEvac(canevac);
  10272. return 0;
  10273. }
  10274. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10275. if (!lua_interface)
  10276. return 0;
  10277. Spawn* spawn = lua_interface->GetSpawn(state);
  10278. lua_interface->ResetFunctionStack(state);
  10279. if(!spawn) {
  10280. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10281. return 0;
  10282. }
  10283. ZoneServer* zone = spawn->GetZone();
  10284. if (zone) {
  10285. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10286. return 1;
  10287. }
  10288. return 0;
  10289. }
  10290. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10291. if (!lua_interface)
  10292. return 0;
  10293. Spawn* spawn = lua_interface->GetSpawn(state);
  10294. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10295. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10296. float distance = lua_interface->GetFloatValue(state, 4);
  10297. string in_range_function = lua_interface->GetStringValue(state, 5);
  10298. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10299. lua_interface->ResetFunctionStack(state);
  10300. if (spawn && distance > 0 && in_range_function.length() > 0)
  10301. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10302. return 0;
  10303. }
  10304. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10305. if (!lua_interface)
  10306. return 0;
  10307. Spawn* spawn = lua_interface->GetSpawn(state);
  10308. Spawn* target = lua_interface->GetSpawn(state, 2);
  10309. lua_interface->ResetFunctionStack(state);
  10310. if (spawn && target)
  10311. {
  10312. if (spawn->IsPlayer() && target->IsEntity())
  10313. {
  10314. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10315. return 1;
  10316. }
  10317. else if (spawn->IsEntity() && target->IsEntity())
  10318. {
  10319. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10320. return 1;
  10321. }
  10322. }
  10323. return 0;
  10324. }
  10325. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10326. if (!lua_interface)
  10327. return 0;
  10328. Spawn* spawn = lua_interface->GetSpawn(state);
  10329. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10330. lua_interface->ResetFunctionStack(state);
  10331. if (spawn && spawn->IsEntity())
  10332. {
  10333. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10334. if (spawn->IsPlayer())
  10335. {
  10336. Client* client = ((Player*)spawn)->GetClient();
  10337. if (client)
  10338. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10339. }
  10340. }
  10341. return 0;
  10342. }
  10343. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10344. if (!lua_interface)
  10345. return 0;
  10346. Spawn* spawn = lua_interface->GetSpawn(state);
  10347. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10348. lua_interface->ResetFunctionStack(state);
  10349. if (spawn && spawn->IsEntity())
  10350. {
  10351. ((Entity*)spawn)->SetSeeHideSpell(val);
  10352. if (spawn->IsPlayer())
  10353. {
  10354. Client* client = ((Player*)spawn)->GetClient();
  10355. if (client)
  10356. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10357. }
  10358. }
  10359. return 0;
  10360. }
  10361. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10362. {
  10363. if (!lua_interface)
  10364. return 0;
  10365. Spawn* player = lua_interface->GetSpawn(state);
  10366. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10367. string command = lua_interface->GetStringValue(state, 3);
  10368. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10369. lua_interface->ResetFunctionStack(state);
  10370. if (spawn && player && player->IsPlayer())
  10371. {
  10372. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10373. bool res = false;
  10374. if (cmd)
  10375. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10376. lua_interface->SetBooleanValue(state, res);
  10377. return 1;
  10378. }
  10379. return 0;
  10380. }
  10381. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10382. {
  10383. if (!lua_interface)
  10384. return 0;
  10385. Spawn* spawn = lua_interface->GetSpawn(state);
  10386. int32 charID = lua_interface->GetInt32Value(state, 2);
  10387. string command = lua_interface->GetStringValue(state, 3);
  10388. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10389. lua_interface->ResetFunctionStack(state);
  10390. if (spawn && charID)
  10391. {
  10392. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10393. bool res = false;
  10394. if (cmd)
  10395. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10396. lua_interface->SetBooleanValue(state, res);
  10397. return 1;
  10398. }
  10399. return 0;
  10400. }
  10401. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10402. {
  10403. if (!lua_interface)
  10404. return 0;
  10405. Spawn* spawn = lua_interface->GetSpawn(state);
  10406. string command = lua_interface->GetStringValue(state, 2);
  10407. lua_interface->ResetFunctionStack(state);
  10408. if (spawn && command.length() > 0)
  10409. spawn->RemovePrimaryEntityCommand(command.c_str());
  10410. return 0;
  10411. }
  10412. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10413. if (!lua_interface)
  10414. return 0;
  10415. Spawn* spawn = lua_interface->GetSpawn(state);
  10416. float distance = lua_interface->GetFloatValue(state, 2);
  10417. string command = lua_interface->GetStringValue(state, 3);
  10418. Spawn* player = lua_interface->GetSpawn(state, 4);
  10419. lua_interface->ResetFunctionStack(state);
  10420. if (spawn) {
  10421. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10422. }
  10423. return 0;
  10424. }
  10425. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10426. if (!lua_interface)
  10427. return 0;
  10428. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10429. Spawn* spawn = lua_interface->GetSpawn(state);
  10430. Spawn* player = lua_interface->GetSpawn(state, 2);
  10431. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10432. lua_interface->ResetFunctionStack(state);
  10433. if (spawn && player && transport_id && player->IsPlayer()) {
  10434. Client* client = 0;
  10435. if (player && player->IsPlayer())
  10436. client = ((Player*)player)->GetClient();
  10437. if (!client)
  10438. return 0;
  10439. vector<TransportDestination*> destinations;
  10440. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10441. if (destinations.size())
  10442. {
  10443. client->SetTemporaryTransportID(transport_id);
  10444. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10445. }
  10446. else
  10447. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10448. }
  10449. return 0;
  10450. }
  10451. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10452. if (!lua_interface)
  10453. return 0;
  10454. Spawn* player = lua_interface->GetSpawn(state);
  10455. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10456. lua_interface->ResetFunctionStack(state);
  10457. if (player && player->IsPlayer()) {
  10458. Client* client = 0;
  10459. if (player && player->IsPlayer())
  10460. client = ((Player*)player)->GetClient();
  10461. if (!client)
  10462. return 0;
  10463. client->SetTemporaryTransportID(transport_id);
  10464. }
  10465. return 0;
  10466. }
  10467. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10468. if (!lua_interface)
  10469. return 0;
  10470. Spawn* player = lua_interface->GetSpawn(state);
  10471. lua_interface->ResetFunctionStack(state);
  10472. if (player && player->IsPlayer()) {
  10473. Client* client = 0;
  10474. if (player && player->IsPlayer())
  10475. client = ((Player*)player)->GetClient();
  10476. if (!client)
  10477. return 0;
  10478. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10479. return 1;
  10480. }
  10481. return 0;
  10482. }
  10483. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10484. if (!lua_interface)
  10485. return 0;
  10486. Spawn* spawn = lua_interface->GetSpawn(state);
  10487. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10488. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10489. if (!spawn) {
  10490. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10491. return 0;
  10492. }
  10493. if (!spawn->IsEntity()) {
  10494. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10495. return 0;
  10496. }
  10497. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10498. {
  10499. 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);
  10500. return 0;
  10501. }
  10502. lua_interface->ResetFunctionStack(state);
  10503. if (spell && spell->targets.size() > 0) {
  10504. ZoneServer* zone = spell->caster->GetZone();
  10505. for (int8 i = 0; i < spell->targets.size(); i++) {
  10506. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10507. if (target && target->IsEntity()) {
  10508. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10509. if (target->IsPlayer())
  10510. ((Player*)target)->SetCharSheetChanged(true);
  10511. }
  10512. }
  10513. }
  10514. else {
  10515. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10516. if (spawn->IsPlayer())
  10517. ((Player*)spawn)->SetCharSheetChanged(true);
  10518. }
  10519. return 0;
  10520. }
  10521. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10522. if (!lua_interface)
  10523. return 0;
  10524. Spawn* spawn = lua_interface->GetSpawn(state);
  10525. lua_interface->ResetFunctionStack(state);
  10526. if (!spawn) {
  10527. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10528. return 0;
  10529. }
  10530. if (!spawn->IsEntity()) {
  10531. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10532. return 0;
  10533. }
  10534. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10535. return 1;
  10536. }
  10537. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10538. if (!lua_interface)
  10539. return 0;
  10540. int32 spell_id = lua_interface->GetInt32Value(state);
  10541. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10542. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10543. if (spell_id > 0) {
  10544. if (spell_tier == 0)
  10545. spell_tier = 1;
  10546. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10547. if(!spell) {
  10548. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10549. lua_interface->ResetFunctionStack(state);
  10550. return 0;
  10551. }
  10552. LuaSpell* lua_spell = 0;
  10553. if(custom_lua_script.size() > 0)
  10554. {
  10555. // attempt to load the custom script since it isn't already loaded
  10556. // we will re-obtain the lua_spell further below
  10557. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10558. {
  10559. 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());
  10560. lua_interface->LoadLuaSpell(custom_lua_script);
  10561. }
  10562. }
  10563. else
  10564. custom_lua_script = spell->GetSpellData()->lua_script;
  10565. if (!lua_spell && lua_interface)
  10566. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10567. lua_interface->ResetFunctionStack(state);
  10568. if (!lua_spell)
  10569. {
  10570. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10571. return 0;
  10572. }
  10573. lua_spell->spell = new Spell(spell);
  10574. lua_interface->AddCustomSpell(lua_spell);
  10575. lua_interface->SetSpellValue(state, lua_spell);
  10576. return 1;
  10577. }
  10578. return 0;
  10579. }
  10580. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10581. if (!lua_interface)
  10582. return 0;
  10583. LuaSpell* spell = lua_interface->GetSpell(state);
  10584. string field = lua_interface->GetStringValue(state, 2);
  10585. lua_interface->ResetFunctionStack(state);
  10586. if (!spell) {
  10587. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10588. return 0;
  10589. }
  10590. if (!spell->spell || !spell->spell->GetSpellData()) {
  10591. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10592. return 0;
  10593. }
  10594. boost::to_lower(field);
  10595. return spell->spell->GetSpellData(state, field);
  10596. }
  10597. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10598. if (!lua_interface)
  10599. return 0;
  10600. LuaSpell* spell = lua_interface->GetSpell(state);
  10601. string field = lua_interface->GetStringValue(state, 2);
  10602. int8 fieldArg = 3; // field value after the initial set
  10603. if (!spell) {
  10604. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10605. lua_interface->ResetFunctionStack(state);
  10606. return 0;
  10607. }
  10608. if (!spell->spell || !spell->spell->GetSpellData()) {
  10609. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10610. lua_interface->ResetFunctionStack(state);
  10611. return 0;
  10612. }
  10613. boost::to_lower(field);
  10614. bool valSet = false;
  10615. spell->spell->SetSpellData(state, field, fieldArg);
  10616. lua_interface->ResetFunctionStack(state);
  10617. return valSet;
  10618. }
  10619. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10620. if (!lua_interface)
  10621. return 0;
  10622. LuaSpell* spell = lua_interface->GetSpell(state);
  10623. int8 idx = lua_interface->GetInt32Value(state, 2);
  10624. if (!spell) {
  10625. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10626. lua_interface->ResetFunctionStack(state);
  10627. return 0;
  10628. }
  10629. if (!spell->spell || !spell->spell->GetSpellData()) {
  10630. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10631. lua_interface->ResetFunctionStack(state);
  10632. return 0;
  10633. }
  10634. if (spell->spell->lua_data.size() <= idx)
  10635. {
  10636. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10637. lua_interface->ResetFunctionStack(state);
  10638. return 0;
  10639. }
  10640. bool setVal = true;
  10641. LUAData* data = spell->spell->lua_data[idx];
  10642. switch (data->type)
  10643. {
  10644. case 0:
  10645. {
  10646. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10647. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10648. data->int_value = value;
  10649. data->int_value2 = value2;
  10650. break;
  10651. }
  10652. case 1:
  10653. {
  10654. float value = lua_interface->GetFloatValue(state, 3);
  10655. float value2 = lua_interface->GetFloatValue(state, 4);
  10656. data->float_value = value;
  10657. data->float_value2 = value2;
  10658. break;
  10659. }
  10660. case 2:
  10661. {
  10662. bool value = lua_interface->GetBooleanValue(state, 3);
  10663. data->bool_value = value;
  10664. break;
  10665. }
  10666. case 3:
  10667. {
  10668. string value = lua_interface->GetStringValue(state, 3);
  10669. string value2 = lua_interface->GetStringValue(state, 4);
  10670. data->string_value = value;
  10671. data->string_value2 = value2;
  10672. break;
  10673. }
  10674. default:
  10675. setVal = false;
  10676. }
  10677. lua_interface->ResetFunctionStack(state);
  10678. return setVal;
  10679. }
  10680. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10681. if (!lua_interface)
  10682. return 0;
  10683. LuaSpell* spell = lua_interface->GetSpell(state);
  10684. int8 idx = lua_interface->GetInt32Value(state, 2);
  10685. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10686. lua_interface->ResetFunctionStack(state);
  10687. if (!spell) {
  10688. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10689. return 0;
  10690. }
  10691. if (!spell->spell || !spell->spell->GetSpellData()) {
  10692. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10693. return 0;
  10694. }
  10695. if (spell->spell->lua_data.size() <= idx)
  10696. {
  10697. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10698. return 0;
  10699. }
  10700. bool setVal = true;
  10701. LUAData* data = spell->spell->lua_data[idx];
  10702. switch (data->type)
  10703. {
  10704. case 0:
  10705. {
  10706. if(!secondfield)
  10707. lua_interface->SetSInt32Value(state, data->int_value);
  10708. else
  10709. lua_interface->SetSInt32Value(state, data->int_value2);
  10710. break;
  10711. }
  10712. case 1:
  10713. {
  10714. if (!secondfield)
  10715. lua_interface->SetFloatValue(state, data->float_value);
  10716. else
  10717. lua_interface->SetFloatValue(state, data->float_value2);
  10718. break;
  10719. }
  10720. case 2:
  10721. {
  10722. lua_interface->SetBooleanValue(state, data->bool_value);
  10723. break;
  10724. }
  10725. case 3:
  10726. {
  10727. if (!secondfield)
  10728. lua_interface->SetStringValue(state, data->string_value.c_str());
  10729. else
  10730. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10731. break;
  10732. }
  10733. default:
  10734. setVal = false;
  10735. }
  10736. return setVal;
  10737. }
  10738. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10739. if (!lua_interface)
  10740. return 0;
  10741. LuaSpell* spell = lua_interface->GetSpell(state);
  10742. int8 idx = lua_interface->GetInt32Value(state, 2);
  10743. string field = lua_interface->GetStringValue(state, 3);
  10744. boost::to_lower(field);
  10745. if (!spell) {
  10746. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10747. lua_interface->ResetFunctionStack(state);
  10748. return 0;
  10749. }
  10750. if (!spell->spell || !spell->spell->GetSpellData()) {
  10751. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10752. lua_interface->ResetFunctionStack(state);
  10753. return 0;
  10754. }
  10755. if (spell->spell->effects.size() <= idx)
  10756. {
  10757. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10758. lua_interface->ResetFunctionStack(state);
  10759. return 0;
  10760. }
  10761. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10762. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10763. if (field == "description")
  10764. effect->description = string(lua_interface->GetStringValue(state, 4));
  10765. else if (field == "bullet")
  10766. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10767. else if (field == "percentage")
  10768. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10769. else { // no match
  10770. lua_interface->ResetFunctionStack(state);
  10771. return 0;
  10772. }
  10773. lua_interface->ResetFunctionStack(state);
  10774. return 1;
  10775. }
  10776. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10777. if (!lua_interface)
  10778. return 0;
  10779. LuaSpell* spell = lua_interface->GetSpell(state);
  10780. int8 idx = lua_interface->GetInt32Value(state, 2);
  10781. string field = lua_interface->GetStringValue(state, 3);
  10782. lua_interface->ResetFunctionStack(state);
  10783. boost::to_lower(field);
  10784. if (!spell) {
  10785. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10786. return 0;
  10787. }
  10788. if (!spell->spell || !spell->spell->GetSpellData()) {
  10789. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10790. return 0;
  10791. }
  10792. if (spell->spell->effects.size() <= idx)
  10793. {
  10794. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10795. return 0;
  10796. }
  10797. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10798. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10799. if (field == "description")
  10800. lua_interface->SetStringValue(state, effect->description.c_str());
  10801. else if (field == "bullet")
  10802. lua_interface->SetInt32Value(state, effect->subbullet);
  10803. else if (field == "percentage")
  10804. lua_interface->SetInt32Value(state, effect->percentage);
  10805. else // no match
  10806. return 0;
  10807. return 1;
  10808. }
  10809. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10810. if (!lua_interface)
  10811. return 0;
  10812. LuaSpell* spell = lua_interface->GetSpell(state);
  10813. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10814. Spawn* target = lua_interface->GetSpawn(state, 3);
  10815. lua_interface->ResetFunctionStack(state);
  10816. if (!target) {
  10817. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10818. return 0;
  10819. }
  10820. if (!target->IsEntity()) {
  10821. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10822. return 0;
  10823. }
  10824. if (!spell) {
  10825. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10826. return 0;
  10827. }
  10828. if (caster && !caster->IsEntity()) {
  10829. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10830. return 0;
  10831. }
  10832. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10833. return 0;
  10834. }
  10835. int EQ2Emu_lua_InWater(lua_State* state) {
  10836. if (!lua_interface)
  10837. return 0;
  10838. Spawn* spawn = lua_interface->GetSpawn(state);
  10839. lua_interface->ResetFunctionStack(state);
  10840. if (spawn) {
  10841. lua_interface->SetBooleanValue(state, spawn->InWater());
  10842. return 1;
  10843. }
  10844. return 0;
  10845. }
  10846. int EQ2Emu_lua_InLava(lua_State* state) {
  10847. if (!lua_interface)
  10848. return 0;
  10849. Spawn* spawn = lua_interface->GetSpawn(state);
  10850. lua_interface->ResetFunctionStack(state);
  10851. if (spawn) {
  10852. lua_interface->SetBooleanValue(state, spawn->InLava());
  10853. return 1;
  10854. }
  10855. return 0;
  10856. }
  10857. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10858. if (!lua_interface)
  10859. return 0;
  10860. Spawn* attacker = lua_interface->GetSpawn(state);
  10861. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10862. int8 type = lua_interface->GetInt8Value(state, 3);
  10863. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10864. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10865. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10866. string spell_name = lua_interface->GetStringValue(state, 7);
  10867. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10868. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10869. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10870. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10871. lua_interface->ResetFunctionStack(state);
  10872. if (!attacker) {
  10873. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10874. return 0;
  10875. }
  10876. if (!attacker->IsEntity()) {
  10877. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10878. return 0;
  10879. }
  10880. if (!victim) {
  10881. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10882. return 0;
  10883. }
  10884. if (!victim->IsEntity()) {
  10885. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10886. return 0;
  10887. }
  10888. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10889. return 0;
  10890. }
  10891. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10892. if (!lua_interface)
  10893. return 0;
  10894. Spawn* spawn = lua_interface->GetSpawn(state);
  10895. lua_interface->ResetFunctionStack(state);
  10896. if (spawn) {
  10897. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10898. return 1;
  10899. }
  10900. return 0;
  10901. }
  10902. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10903. if (!lua_interface)
  10904. return 0;
  10905. Spawn* spawn = lua_interface->GetSpawn(state);
  10906. bool invul = lua_interface->GetBooleanValue(state, 2);
  10907. lua_interface->ResetFunctionStack(state);
  10908. if (spawn) {
  10909. spawn->SetInvulnerable(invul);
  10910. }
  10911. return 0;
  10912. }
  10913. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10914. if (!lua_interface)
  10915. return 0;
  10916. string category = lua_interface->GetStringValue(state);
  10917. string name = lua_interface->GetStringValue(state, 2);
  10918. lua_interface->ResetFunctionStack(state);
  10919. Rule *ret = 0;
  10920. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10921. lua_interface->SetBooleanValue(state, ret->GetBool());
  10922. return 1;
  10923. }
  10924. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10925. return 0;
  10926. }
  10927. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10928. if (!lua_interface)
  10929. return 0;
  10930. string category = lua_interface->GetStringValue(state);
  10931. string name = lua_interface->GetStringValue(state, 2);
  10932. lua_interface->ResetFunctionStack(state);
  10933. Rule *ret = 0;
  10934. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10935. lua_interface->SetInt32Value(state, ret->GetInt32());
  10936. return 1;
  10937. }
  10938. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10939. return 0;
  10940. }
  10941. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10942. if (!lua_interface)
  10943. return 0;
  10944. string category = lua_interface->GetStringValue(state);
  10945. string name = lua_interface->GetStringValue(state, 2);
  10946. lua_interface->ResetFunctionStack(state);
  10947. Rule *ret = 0;
  10948. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10949. lua_interface->SetFloatValue(state, ret->GetFloat());
  10950. return 1;
  10951. }
  10952. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10953. return 0;
  10954. }
  10955. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10956. if (!lua_interface)
  10957. return 0;
  10958. Spawn* spawn = lua_interface->GetSpawn(state);
  10959. string type = lua_interface->GetStringValue(state, 2);
  10960. lua_interface->ResetFunctionStack(state);
  10961. if (spawn) {
  10962. int res = 1;
  10963. boost::to_lower(type);
  10964. if(type == "assigned_aa")
  10965. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10966. else if ( type == "unassigned_aa")
  10967. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10968. else if ( type == "assigned_tradeskill_aa")
  10969. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10970. else if ( type == "unassigned_tradeskill_aa")
  10971. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10972. else if ( type == "assigned_prestige_aa")
  10973. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10974. else if ( type == "unassigned_prestige_aa")
  10975. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10976. else if ( type == "assigned_tradeskill_prestige_aa")
  10977. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10978. else if ( type == "unassigned_tradeskill_prestige_aa")
  10979. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10980. else
  10981. res = 0;
  10982. return res;
  10983. }
  10984. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10985. return 0;
  10986. }
  10987. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10988. if (!lua_interface)
  10989. return 0;
  10990. Spawn* spawn = lua_interface->GetSpawn(state);
  10991. string type = lua_interface->GetStringValue(state, 2);
  10992. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10993. lua_interface->ResetFunctionStack(state);
  10994. if (spawn) {
  10995. boost::to_lower(type);
  10996. if(type == "assigned_aa")
  10997. spawn->SetAssignedAA((sint16)value);
  10998. else if ( type == "unassigned_aa")
  10999. spawn->SetUnassignedAA((sint16)value);
  11000. else if ( type == "assigned_tradeskill_aa")
  11001. spawn->SetTradeskillAA((sint16)value);
  11002. else if ( type == "unassigned_tradeskill_aa")
  11003. spawn->SetUnassignedTradeskillAA((sint16)value);
  11004. else if ( type == "assigned_prestige_aa")
  11005. spawn->SetPrestigeAA((sint16)value);
  11006. else if ( type == "unassigned_prestige_aa")
  11007. spawn->SetUnassignedPrestigeAA((sint16)value);
  11008. else if ( type == "assigned_tradeskill_prestige_aa")
  11009. spawn->SetTradeskillPrestigeAA((sint16)value);
  11010. else if ( type == "unassigned_tradeskill_prestige_aa")
  11011. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11012. if(spawn->IsPlayer())
  11013. ((Player*)spawn)->SetCharSheetChanged(true);
  11014. }
  11015. return 0;
  11016. }
  11017. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11018. if (!lua_interface)
  11019. return 0;
  11020. string titleName = lua_interface->GetStringValue(state);
  11021. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11022. lua_interface->ResetFunctionStack(state);
  11023. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11024. lua_interface->SetSInt32Value(state, index);
  11025. return 1;
  11026. }
  11027. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11028. if (!lua_interface)
  11029. return 0;
  11030. Spawn* spawn = lua_interface->GetSpawn(state);
  11031. string titleName = lua_interface->GetStringValue(state, 2);
  11032. lua_interface->ResetFunctionStack(state);
  11033. if(!spawn->IsPlayer())
  11034. {
  11035. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11036. lua_interface->SetSInt32Value(state, -1);
  11037. return 1;
  11038. }
  11039. Player* player = (Player*)spawn;
  11040. // check if player already has the title, don't need to add twice
  11041. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11042. if ( playerHasTitle)
  11043. {
  11044. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11045. return 1;
  11046. }
  11047. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11048. if(!title)
  11049. {
  11050. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11051. lua_interface->SetSInt32Value(state, -1);
  11052. return 1;
  11053. }
  11054. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11055. if(returnIdx < 0)
  11056. {
  11057. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11058. }
  11059. lua_interface->SetSInt32Value(state, returnIdx);
  11060. player->GetClient()->SendTitleUpdate();
  11061. return 1;
  11062. }
  11063. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11064. if (!lua_interface)
  11065. return 0;
  11066. Spawn* spawn = lua_interface->GetSpawn(state);
  11067. string titleName = lua_interface->GetStringValue(state, 2);
  11068. lua_interface->ResetFunctionStack(state);
  11069. if(!spawn->IsPlayer())
  11070. {
  11071. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11072. return 0;
  11073. }
  11074. Player* player = (Player*)spawn;
  11075. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11076. if(!title)
  11077. {
  11078. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11079. return 0;
  11080. }
  11081. if(title->GetPrefix())
  11082. {
  11083. 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());
  11084. return 0;
  11085. }
  11086. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11087. player->GetClient()->SendTitleUpdate();
  11088. return 1;
  11089. }
  11090. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11091. if (!lua_interface)
  11092. return 0;
  11093. Spawn* spawn = lua_interface->GetSpawn(state);
  11094. string titleName = lua_interface->GetStringValue(state, 2);
  11095. lua_interface->ResetFunctionStack(state);
  11096. if(!spawn->IsPlayer())
  11097. {
  11098. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11099. return 0;
  11100. }
  11101. Player* player = (Player*)spawn;
  11102. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11103. if(!title)
  11104. {
  11105. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11106. return 0;
  11107. }
  11108. if(!title->GetPrefix())
  11109. {
  11110. 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());
  11111. return 0;
  11112. }
  11113. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11114. player->GetClient()->SendTitleUpdate();
  11115. return 1;
  11116. }
  11117. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11118. if (!lua_interface)
  11119. return 0;
  11120. Spawn* spawn = lua_interface->GetSpawn(state);
  11121. lua_interface->ResetFunctionStack(state);
  11122. if(!spawn->IsPlayer())
  11123. {
  11124. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11125. return 0;
  11126. }
  11127. Player* player = (Player*)spawn;
  11128. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11129. player->GetClient()->SendTitleUpdate();
  11130. return 1;
  11131. }
  11132. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11133. if (!lua_interface)
  11134. return 0;
  11135. Spawn* spawn = lua_interface->GetSpawn(state);
  11136. lua_interface->ResetFunctionStack(state);
  11137. if(!spawn->IsPlayer())
  11138. {
  11139. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11140. return 0;
  11141. }
  11142. Player* player = (Player*)spawn;
  11143. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11144. player->GetClient()->SendTitleUpdate();
  11145. return 1;
  11146. }
  11147. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11148. if (!lua_interface)
  11149. return 0;
  11150. Spawn* spawn = lua_interface->GetSpawn(state);
  11151. string field = lua_interface->GetStringValue(state, 2);
  11152. lua_interface->ResetFunctionStack(state);
  11153. if(!spawn || !spawn->IsEntity())
  11154. {
  11155. 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));
  11156. return 0;
  11157. }
  11158. Entity* ent = (Entity*)spawn;
  11159. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11160. return 1;
  11161. }
  11162. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11163. if (!lua_interface)
  11164. return 0;
  11165. Spawn* spawn = lua_interface->GetSpawn(state);
  11166. string field = lua_interface->GetStringValue(state, 2);
  11167. lua_interface->ResetFunctionStack(state);
  11168. if(!spawn || !spawn->IsEntity())
  11169. {
  11170. 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));
  11171. return 0;
  11172. }
  11173. Entity* ent = (Entity*)spawn;
  11174. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11175. return 1;
  11176. }
  11177. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11178. if (!lua_interface)
  11179. return 0;
  11180. Spawn* spawn = lua_interface->GetSpawn(state);
  11181. string field = lua_interface->GetStringValue(state, 2);
  11182. lua_interface->ResetFunctionStack(state);
  11183. if(!spawn || !spawn->IsEntity())
  11184. {
  11185. 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));
  11186. return 0;
  11187. }
  11188. Entity* ent = (Entity*)spawn;
  11189. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11190. return 1;
  11191. }
  11192. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11193. if (!lua_interface)
  11194. return 0;
  11195. Spawn* spawn = lua_interface->GetSpawn(state);
  11196. string field = lua_interface->GetStringValue(state, 2);
  11197. lua_interface->ResetFunctionStack(state);
  11198. if(!spawn || !spawn->IsEntity())
  11199. {
  11200. 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));
  11201. return 0;
  11202. }
  11203. Entity* ent = (Entity*)spawn;
  11204. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11205. return 1;
  11206. }
  11207. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11208. if (!lua_interface)
  11209. return 0;
  11210. Spawn* spawn = lua_interface->GetSpawn(state);
  11211. string field = lua_interface->GetStringValue(state, 2);
  11212. string value = lua_interface->GetStringValue(state, 3);
  11213. lua_interface->ResetFunctionStack(state);
  11214. if(!spawn || !spawn->IsEntity())
  11215. {
  11216. 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));
  11217. return 0;
  11218. }
  11219. Entity* ent = (Entity*)spawn;
  11220. bool set_ = ent->SetInfoStructString(field, value);
  11221. lua_interface->SetBooleanValue(state, set_);
  11222. return 1;
  11223. }
  11224. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11225. if (!lua_interface)
  11226. return 0;
  11227. Spawn* spawn = lua_interface->GetSpawn(state);
  11228. string field = lua_interface->GetStringValue(state, 2);
  11229. int64 value = lua_interface->GetInt64Value(state, 3);
  11230. lua_interface->ResetFunctionStack(state);
  11231. if(!spawn || !spawn->IsEntity())
  11232. {
  11233. 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));
  11234. return 0;
  11235. }
  11236. Entity* ent = (Entity*)spawn;
  11237. bool set_ = ent->SetInfoStructUInt(field, value);
  11238. lua_interface->SetBooleanValue(state, set_);
  11239. return 1;
  11240. }
  11241. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11242. if (!lua_interface)
  11243. return 0;
  11244. Spawn* spawn = lua_interface->GetSpawn(state);
  11245. string field = lua_interface->GetStringValue(state, 2);
  11246. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11247. lua_interface->ResetFunctionStack(state);
  11248. if(!spawn || !spawn->IsEntity())
  11249. {
  11250. 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));
  11251. return 0;
  11252. }
  11253. Entity* ent = (Entity*)spawn;
  11254. bool set_ = ent->SetInfoStructSInt(field, value);
  11255. lua_interface->SetBooleanValue(state, set_);
  11256. return 1;
  11257. }
  11258. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11259. if (!lua_interface)
  11260. return 0;
  11261. Spawn* spawn = lua_interface->GetSpawn(state);
  11262. string field = lua_interface->GetStringValue(state, 2);
  11263. float value = lua_interface->GetFloatValue(state, 3);
  11264. lua_interface->ResetFunctionStack(state);
  11265. if(!spawn || !spawn->IsEntity())
  11266. {
  11267. 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));
  11268. return 0;
  11269. }
  11270. Entity* ent = (Entity*)spawn;
  11271. bool set_ = ent->SetInfoStructFloat(field, value);
  11272. lua_interface->SetBooleanValue(state, set_);
  11273. return 1;
  11274. }
  11275. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11276. if (!lua_interface)
  11277. return 0;
  11278. Spawn* spawn = lua_interface->GetSpawn(state);
  11279. bool value = lua_interface->GetBooleanValue(state, 2);
  11280. lua_interface->ResetFunctionStack(state);
  11281. if(!spawn || !spawn->IsPlayer())
  11282. {
  11283. 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));
  11284. return 0;
  11285. }
  11286. ((Player*)spawn)->SetCharSheetChanged(value);
  11287. return 0;
  11288. }
  11289. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11290. if (!lua_interface)
  11291. return 0;
  11292. Spawn* spawn = lua_interface->GetSpawn(state);
  11293. std::string fromName = lua_interface->GetStringValue(state, 2);
  11294. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11295. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11296. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11297. int32 copper = lua_interface->GetInt32Value(state, 6);
  11298. int32 silver = lua_interface->GetInt32Value(state, 7);
  11299. int32 gold = lua_interface->GetInt32Value(state, 8);
  11300. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11301. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11302. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11303. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11304. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11305. lua_interface->ResetFunctionStack(state);
  11306. if(!spawn || !spawn->IsPlayer())
  11307. {
  11308. 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));
  11309. lua_interface->SetBooleanValue(state, false);
  11310. return 1;
  11311. }
  11312. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11313. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11314. lua_interface->SetBooleanValue(state, true);
  11315. return 1;
  11316. }
  11317. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11318. if (!lua_interface)
  11319. return 0;
  11320. int32 char_id = lua_interface->GetInt32Value(state);
  11321. std::string fromName = lua_interface->GetStringValue(state, 2);
  11322. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11323. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11324. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11325. int32 copper = lua_interface->GetInt32Value(state, 6);
  11326. int32 silver = lua_interface->GetInt32Value(state, 7);
  11327. int32 gold = lua_interface->GetInt32Value(state, 8);
  11328. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11329. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11330. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11331. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11332. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11333. lua_interface->ResetFunctionStack(state);
  11334. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11335. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11336. lua_interface->SetBooleanValue(state, true);
  11337. return 1;
  11338. }
  11339. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11340. Spawn* widget;
  11341. if (lua_interface) {
  11342. widget = lua_interface->GetSpawn(state);
  11343. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11344. lua_interface->ResetFunctionStack(state);
  11345. if (widget && widget->IsWidget())
  11346. {
  11347. ((Widget*)widget)->OpenDoor();
  11348. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11349. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11350. }
  11351. else
  11352. 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));
  11353. }
  11354. return 0;
  11355. }
  11356. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11357. Spawn* widget;
  11358. if (lua_interface) {
  11359. widget = lua_interface->GetSpawn(state);
  11360. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11361. lua_interface->ResetFunctionStack(state);
  11362. if (widget && widget->IsWidget())
  11363. {
  11364. ((Widget*)widget)->CloseDoor();
  11365. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11366. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11367. }
  11368. else
  11369. 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));
  11370. }
  11371. return 0;
  11372. }
  11373. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11374. if (!lua_interface)
  11375. return 0;
  11376. Spawn* widget = lua_interface->GetSpawn(state);
  11377. lua_interface->ResetFunctionStack(state);
  11378. if (widget && widget->IsWidget())
  11379. {
  11380. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11381. return 1;
  11382. }
  11383. return 0;
  11384. }
  11385. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11386. if (!lua_interface)
  11387. return 0;
  11388. sint32 min = lua_interface->GetSInt32Value(state);
  11389. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11390. lua_interface->ResetFunctionStack(state);
  11391. sint32 result = MakeRandomInt(min, max);
  11392. lua_interface->SetSInt32Value(state, result);
  11393. return 1;
  11394. }
  11395. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11396. if (!lua_interface)
  11397. return 0;
  11398. float min = lua_interface->GetFloatValue(state);
  11399. float max = lua_interface->GetFloatValue(state, 2);
  11400. lua_interface->ResetFunctionStack(state);
  11401. float result = MakeRandomFloat(min, max);
  11402. lua_interface->SetFloatValue(state, result);
  11403. return 1;
  11404. }
  11405. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11406. if (!lua_interface)
  11407. return 0;
  11408. Spawn* spawn = lua_interface->GetSpawn(state);
  11409. int32 value = lua_interface->GetInt32Value(state, 2);
  11410. lua_interface->ResetFunctionStack(state);
  11411. if(!spawn)
  11412. {
  11413. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11414. lua_interface->SetBooleanValue(state, false);
  11415. return 1;
  11416. }
  11417. spawn->AddIconValue(value);
  11418. lua_interface->SetBooleanValue(state, true);
  11419. return 1;
  11420. }
  11421. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11422. if (!lua_interface)
  11423. return 0;
  11424. Spawn* spawn = lua_interface->GetSpawn(state);
  11425. int32 value = lua_interface->GetInt32Value(state, 2);
  11426. lua_interface->ResetFunctionStack(state);
  11427. if(!spawn)
  11428. {
  11429. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11430. lua_interface->SetBooleanValue(state, false);
  11431. return 1;
  11432. }
  11433. spawn->RemoveIconValue(value);
  11434. lua_interface->SetBooleanValue(state, true);
  11435. return 1;
  11436. }
  11437. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11438. Spawn* npc = lua_interface->GetSpawn(state);
  11439. lua_interface->ResetFunctionStack(state);
  11440. if (npc && npc->IsNPC()) {
  11441. NPC* shard = (NPC*)npc;
  11442. int32 shardid = shard->GetShardID();
  11443. lua_interface->SetInt32Value(state, shardid);
  11444. return 1;
  11445. }
  11446. lua_interface->SetInt32Value(state, 0);
  11447. return 1;
  11448. }
  11449. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11450. Spawn* npc = lua_interface->GetSpawn(state);
  11451. lua_interface->ResetFunctionStack(state);
  11452. if (npc && npc->IsNPC()) {
  11453. NPC* shard = (NPC*)npc;
  11454. int32 charid = shard->GetShardCharID();
  11455. lua_interface->SetInt32Value(state, charid);
  11456. return 1;
  11457. }
  11458. lua_interface->SetInt32Value(state, 0);
  11459. return 1;
  11460. }
  11461. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11462. Spawn* npc = lua_interface->GetSpawn(state);
  11463. lua_interface->ResetFunctionStack(state);
  11464. if (npc && npc->IsNPC()) {
  11465. NPC* shard = (NPC*)npc;
  11466. int64 timestamp = shard->GetShardCreatedTimestamp();
  11467. lua_interface->SetSInt64Value(state, timestamp);
  11468. return 1;
  11469. }
  11470. lua_interface->SetSInt64Value(state, 0);
  11471. return 1;
  11472. }
  11473. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11474. if (!lua_interface)
  11475. return 0;
  11476. int32 shardid = lua_interface->GetInt32Value(state);
  11477. lua_interface->ResetFunctionStack(state);
  11478. if(shardid < 1)
  11479. lua_interface->SetBooleanValue(state, false);
  11480. else
  11481. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11482. return 1;
  11483. }
  11484. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11485. if (!lua_interface)
  11486. return 0;
  11487. Spawn* spawn = lua_interface->GetSpawn(state);
  11488. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11489. if (spawn) {
  11490. spawn->PauseMovement(delay_in_ms);
  11491. }
  11492. lua_interface->ResetFunctionStack(state);
  11493. return 0;
  11494. }
  11495. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11496. if (!lua_interface)
  11497. return 0;
  11498. Spawn* spawn = lua_interface->GetSpawn(state);
  11499. if (spawn) {
  11500. spawn->StopMovement();
  11501. }
  11502. lua_interface->ResetFunctionStack(state);
  11503. return 0;
  11504. }
  11505. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11506. Player* player = (Player*)lua_interface->GetSpawn(state);
  11507. int8 level = lua_interface->GetInt8Value(state, 2);
  11508. lua_interface->ResetFunctionStack(state);
  11509. if (player && player->IsPlayer() && level > 0) {
  11510. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11511. return 1;
  11512. }
  11513. return 0;
  11514. }
  11515. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11516. Player* player = (Player*)lua_interface->GetSpawn(state);
  11517. int8 level = lua_interface->GetInt8Value(state, 2);
  11518. lua_interface->ResetFunctionStack(state);
  11519. if (player && player->IsPlayer() && level > 0) {
  11520. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11521. return 1;
  11522. }
  11523. return 0;
  11524. }
  11525. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11526. ZoneServer* zone = lua_interface->GetZone(state);
  11527. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11528. lua_interface->ResetFunctionStack(state);
  11529. if (zone) {
  11530. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11531. if (spawn) {
  11532. lua_interface->SetSpawnValue(state, spawn);
  11533. return 1;
  11534. }
  11535. }
  11536. return 0;
  11537. }
  11538. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11539. if (!lua_interface)
  11540. return 0;
  11541. Spawn* spawn = lua_interface->GetSpawn(state);
  11542. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11543. lua_interface->ResetFunctionStack(state);
  11544. bool res = false;
  11545. if(spawn && spawn->IsTransportSpawn())
  11546. {
  11547. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11548. spawn->SetRailID(rail_id);
  11549. res = true;
  11550. }
  11551. else if (!spawn) {
  11552. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11553. }
  11554. else if(!spawn->IsTransportSpawn()) {
  11555. 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());
  11556. }
  11557. lua_interface->SetBooleanValue(state, res);
  11558. return 1;
  11559. }
  11560. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11561. if (!lua_interface)
  11562. return 0;
  11563. ZoneServer* zone = lua_interface->GetZone(state);
  11564. lua_interface->ResetFunctionStack(state);
  11565. if (zone) {
  11566. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11567. return 1;
  11568. }
  11569. return 0;
  11570. }
  11571. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11572. if (!lua_interface)
  11573. return 0;
  11574. Spawn* spawn = lua_interface->GetSpawn(state);
  11575. lua_interface->ResetFunctionStack(state);
  11576. if (spawn) {
  11577. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11578. return 1;
  11579. }
  11580. return 0;
  11581. }
  11582. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11583. if (!lua_interface)
  11584. return 0;
  11585. Spawn* player = lua_interface->GetSpawn(state);
  11586. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11587. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11588. lua_interface->ResetFunctionStack(state);
  11589. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11590. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11591. }
  11592. else if(!zoneID) {
  11593. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11594. }
  11595. else
  11596. {
  11597. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11598. return 1;
  11599. }
  11600. return 0;
  11601. }
  11602. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11603. if (!lua_interface)
  11604. return 0;
  11605. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11606. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11607. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11608. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11609. lua_interface->ResetFunctionStack(state);
  11610. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11611. world.GetWorldTimeStruct()->year = newYear;
  11612. world.GetWorldTimeStruct()->month = newMonth;
  11613. world.GetWorldTimeStruct()->hour = newHour;
  11614. world.GetWorldTimeStruct()->minute = newMinute;
  11615. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11616. return 0;
  11617. }
  11618. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11619. if (!lua_interface)
  11620. return 0;
  11621. lua_interface->ResetFunctionStack(state);
  11622. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11623. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11624. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11625. return 1;
  11626. }
  11627. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11628. if (!lua_interface)
  11629. return 0;
  11630. lua_interface->ResetFunctionStack(state);
  11631. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11632. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11633. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11634. return 1;
  11635. }
  11636. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11637. if (!lua_interface)
  11638. return 0;
  11639. lua_interface->ResetFunctionStack(state);
  11640. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11641. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11642. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11643. return 1;
  11644. }
  11645. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11646. if (!lua_interface)
  11647. return 0;
  11648. lua_interface->ResetFunctionStack(state);
  11649. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11650. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11651. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11652. return 1;
  11653. }
  11654. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11655. if (!lua_interface)
  11656. return 0;
  11657. lua_interface->ResetFunctionStack(state);
  11658. world.SendTimeUpdate();
  11659. return 0;
  11660. }
  11661. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11662. bool update_result = false;
  11663. Faction* faction = 0;
  11664. Spawn* spawn = lua_interface->GetSpawn(state);
  11665. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11666. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11667. lua_interface->ResetFunctionStack(state);
  11668. if(!spawn || !spawn->IsPlayer()) {
  11669. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11670. return 0;
  11671. }
  11672. Player* player = (Player*)spawn;
  11673. Client* client = player->GetClient();
  11674. if (faction_id > 0) {
  11675. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11676. if(hasfaction == 0) {
  11677. //they do not have the faction. Lets get the default value and feed it in.
  11678. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11679. //add the default faction for the player.
  11680. player->SetFactionValue(faction_id, defaultfaction);
  11681. }
  11682. if(increase >= 0) {
  11683. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11684. faction = master_faction_list.GetFaction(faction_id);
  11685. if(faction && update_result)
  11686. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11687. else if(faction)
  11688. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11689. lua_interface->SetBooleanValue(state, true);
  11690. return 1;
  11691. }
  11692. if(increase < 0){
  11693. //change the negative to a positive, since thats how decreasefaction() likes it.
  11694. increase *= -1;
  11695. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11696. faction = master_faction_list.GetFaction(faction_id);
  11697. if(faction && update_result)
  11698. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11699. else if(faction)
  11700. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11701. lua_interface->SetBooleanValue(state, true);
  11702. return 1;
  11703. }
  11704. }
  11705. lua_interface->SetBooleanValue(state, false);
  11706. return 1;
  11707. }
  11708. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11709. bool hascoin = 0;
  11710. Player* player = (Player*)lua_interface->GetSpawn(state);
  11711. int32 coins = lua_interface->GetInt32Value(state, 2);
  11712. lua_interface->ResetFunctionStack(state);
  11713. if (player && player->IsPlayer()) {
  11714. hascoin = player->HasCoins(coins);
  11715. if(hascoin == 0) {
  11716. lua_interface->SetBooleanValue(state, false);
  11717. return 1;
  11718. }
  11719. if(hascoin == 1) {
  11720. lua_interface->SetBooleanValue(state, true);
  11721. return 1;
  11722. }
  11723. }
  11724. return 0;
  11725. }
  11726. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11727. int32 loot_tier = 0;
  11728. Spawn* spawn = lua_interface->GetSpawn(state);
  11729. lua_interface->ResetFunctionStack(state);
  11730. if (spawn) {
  11731. loot_tier = spawn->GetLootTier();
  11732. lua_interface->SetInt32Value(state, loot_tier);
  11733. return 1;
  11734. }
  11735. return 0;
  11736. }
  11737. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11738. if (!lua_interface)
  11739. return 0;
  11740. Spawn* spawn = lua_interface->GetSpawn(state);
  11741. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11742. lua_interface->ResetFunctionStack(state);
  11743. if (spawn) {
  11744. spawn->SetLootTier(loot_tier);
  11745. lua_interface->SetBooleanValue(state, true);
  11746. return 1;
  11747. }
  11748. lua_interface->SetBooleanValue(state, false);
  11749. return 1;
  11750. }
  11751. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11752. int32 loot_drop_type = 0;
  11753. Spawn* spawn = lua_interface->GetSpawn(state);
  11754. lua_interface->ResetFunctionStack(state);
  11755. if (spawn) {
  11756. loot_drop_type = spawn->GetLootDropType();
  11757. lua_interface->SetInt32Value(state, loot_drop_type);
  11758. return 1;
  11759. }
  11760. return 0;
  11761. }
  11762. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11763. if (!lua_interface)
  11764. return 0;
  11765. Spawn* spawn = lua_interface->GetSpawn(state);
  11766. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11767. lua_interface->ResetFunctionStack(state);
  11768. if (spawn) {
  11769. spawn->SetLootDropType(loot_drop_type);
  11770. lua_interface->SetBooleanValue(state, true);
  11771. return 1;
  11772. }
  11773. lua_interface->SetBooleanValue(state, false);
  11774. return 1;
  11775. }
  11776. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11777. if (!lua_interface)
  11778. return 0;
  11779. Spawn* spawn = lua_interface->GetSpawn(state);
  11780. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11781. if(damage_amount > 100) {
  11782. damage_amount = 100;
  11783. }
  11784. if (!spawn) {
  11785. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11786. lua_interface->ResetFunctionStack(state);
  11787. return 0;
  11788. }
  11789. lua_interface->ResetFunctionStack(state);
  11790. if (spawn->IsPlayer()) {
  11791. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11792. lua_interface->SetBooleanValue(state, true);
  11793. else
  11794. lua_interface->SetBooleanValue(state, false);
  11795. }
  11796. else {
  11797. lua_interface->SetBooleanValue(state, false);
  11798. }
  11799. return 1;
  11800. }
  11801. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11802. ZoneServer* zone = lua_interface->GetZone(state);
  11803. int32 version = lua_interface->GetInt32Value(state, 2);
  11804. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11805. if(region_map == nullptr) {
  11806. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11807. lua_interface->ResetFunctionStack(state);
  11808. return 0;
  11809. }
  11810. string region_name = lua_interface->GetStringValue(state, 3);
  11811. string env_name = lua_interface->GetStringValue(state, 4);
  11812. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11813. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11814. float dist = lua_interface->GetFloatValue(state, 7);
  11815. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11816. lua_interface->ResetFunctionStack(state);
  11817. lua_interface->SetBooleanValue(state, true);
  11818. return 1;
  11819. }
  11820. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11821. ZoneServer* zone = lua_interface->GetZone(state);
  11822. int32 version = lua_interface->GetInt32Value(state, 2);
  11823. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11824. if(region_map == nullptr) {
  11825. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11826. lua_interface->ResetFunctionStack(state);
  11827. return 0;
  11828. }
  11829. string region_name = lua_interface->GetStringValue(state, 3);
  11830. region_map->RemoveRegionNode(region_name);
  11831. lua_interface->ResetFunctionStack(state);
  11832. lua_interface->SetBooleanValue(state, true);
  11833. return 1;
  11834. }
  11835. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11836. Client* client = nullptr;
  11837. Spawn* player = lua_interface->GetSpawn(state);
  11838. if (!player) {
  11839. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11840. lua_interface->SetBooleanValue(state, false);
  11841. lua_interface->ResetFunctionStack(state);
  11842. return 1;
  11843. }
  11844. if (!player->IsPlayer()) {
  11845. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11846. lua_interface->SetBooleanValue(state, false);
  11847. lua_interface->ResetFunctionStack(state);
  11848. return 1;
  11849. }
  11850. client = player->GetClient();
  11851. if (!client) {
  11852. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11853. lua_interface->SetBooleanValue(state, false);
  11854. lua_interface->ResetFunctionStack(state);
  11855. return 1;
  11856. }
  11857. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11858. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11859. lua_interface->ResetFunctionStack(state);
  11860. lua_interface->SetBooleanValue(state, success_sight);
  11861. return 1;
  11862. }
  11863. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11864. if (!lua_interface)
  11865. return 0;
  11866. bool result = false;
  11867. Spawn* spawn = lua_interface->GetSpawn(state);
  11868. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11869. lua_interface->ResetFunctionStack(state);
  11870. if (!spawn)
  11871. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11872. else if (!spawn->IsNPC())
  11873. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11874. else
  11875. {
  11876. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11877. result = true;
  11878. }
  11879. lua_interface->SetBooleanValue(state, result);
  11880. return 1;
  11881. }
  11882. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11883. if (!lua_interface)
  11884. return 0;
  11885. bool result = false;
  11886. Spawn* spawn = lua_interface->GetSpawn(state);
  11887. lua_interface->ResetFunctionStack(state);
  11888. if (!spawn)
  11889. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11890. else if (!spawn->IsNPC())
  11891. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11892. else
  11893. {
  11894. if(((NPC*)spawn)->cast_on_aggro_completed)
  11895. result = true;
  11896. }
  11897. lua_interface->SetBooleanValue(state, result);
  11898. return 1;
  11899. }
  11900. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11901. Client* client = nullptr;
  11902. Spawn* player = lua_interface->GetSpawn(state);
  11903. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11904. lua_interface->ResetFunctionStack(state);
  11905. if (!player) {
  11906. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11907. lua_interface->SetBooleanValue(state, false);
  11908. return 1;
  11909. }
  11910. if (!player->IsPlayer()) {
  11911. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11912. lua_interface->SetBooleanValue(state, false);
  11913. return 1;
  11914. }
  11915. client = player->GetClient();
  11916. if (!client) {
  11917. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11918. lua_interface->SetBooleanValue(state, false);
  11919. return 1;
  11920. }
  11921. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11922. lua_interface->SetBooleanValue(state, result);
  11923. return 1;
  11924. }
  11925. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11926. Client* client = nullptr;
  11927. Spawn* player = lua_interface->GetSpawn(state);
  11928. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11929. lua_interface->ResetFunctionStack(state);
  11930. if (!player) {
  11931. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11932. lua_interface->SetBooleanValue(state, false);
  11933. return 1;
  11934. }
  11935. if (!player->IsPlayer()) {
  11936. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11937. lua_interface->SetBooleanValue(state, false);
  11938. return 1;
  11939. }
  11940. client = player->GetClient();
  11941. if (!client) {
  11942. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11943. lua_interface->SetBooleanValue(state, false);
  11944. return 1;
  11945. }
  11946. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11947. lua_interface->SetBooleanValue(state, result);
  11948. return 1;
  11949. }
  11950. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  11951. Client* client = nullptr;
  11952. Spawn* player = lua_interface->GetSpawn(state);
  11953. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11954. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  11955. // rest are all optional fields
  11956. float x = lua_interface->GetFloatValue(state, 4);
  11957. float y = lua_interface->GetFloatValue(state, 5);
  11958. float z = lua_interface->GetFloatValue(state, 6);
  11959. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  11960. lua_interface->ResetFunctionStack(state);
  11961. if (!player) {
  11962. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  11963. lua_interface->SetBooleanValue(state, false);
  11964. return 1;
  11965. }
  11966. if (!player->IsPlayer()) {
  11967. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  11968. lua_interface->SetBooleanValue(state, false);
  11969. return 1;
  11970. }
  11971. if(!player->GetZone()) {
  11972. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  11973. lua_interface->SetBooleanValue(state, false);
  11974. return 1;
  11975. }
  11976. client = player->GetClient();
  11977. if (!client) {
  11978. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  11979. lua_interface->SetBooleanValue(state, false);
  11980. return 1;
  11981. }
  11982. if(!client->IsReadyForUpdates()) {
  11983. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  11984. lua_interface->SetBooleanValue(state, false);
  11985. return 1;
  11986. }
  11987. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  11988. lua_interface->SetBooleanValue(state, true);
  11989. return 1;
  11990. }
  11991. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  11992. Client* client = nullptr;
  11993. Spawn* spawn = lua_interface->GetSpawn(state);
  11994. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11995. lua_interface->ResetFunctionStack(state);
  11996. if (!spawn) {
  11997. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  11998. lua_interface->SetBooleanValue(state, false);
  11999. return 1;
  12000. }
  12001. if(!spawn->GetZone()) {
  12002. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12003. lua_interface->SetBooleanValue(state, false);
  12004. return 1;
  12005. }
  12006. spawn->AddIgnoredWidget(widget_id);
  12007. lua_interface->SetBooleanValue(state, true);
  12008. return 1;
  12009. }
  12010. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12011. ZoneServer* zone = lua_interface->GetZone(state);
  12012. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12013. lua_interface->ResetFunctionStack(state);
  12014. if(!zone) {
  12015. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12016. lua_interface->SetBooleanValue(state, false);
  12017. return 1;
  12018. }
  12019. if(!zone->IsLoading()) {
  12020. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12021. lua_interface->SetBooleanValue(state, false);
  12022. return 1;
  12023. }
  12024. zone->AddIgnoredWidget(widget_id);
  12025. lua_interface->SetBooleanValue(state, true);
  12026. return 1;
  12027. }