LuaFunctions.cpp 372 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182
  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. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //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
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. }
  327. return 0;
  328. }
  329. //this function is used to force an update packet to be sent.
  330. //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
  331. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  332. if (!lua_interface)
  333. return 0;
  334. Spawn* spawn = lua_interface->GetSpawn(state);
  335. if (spawn) {
  336. spawn->info_changed = true;
  337. }
  338. return 0;
  339. }
  340. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int32 new_state = lua_interface->GetInt32Value(state, 2);
  345. Spawn* player = lua_interface->GetSpawn(state, 3);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. if(player)
  349. {
  350. if(player->IsPlayer())
  351. {
  352. Client* client = ((Player*)player)->GetClient();
  353. if(client)
  354. {
  355. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  356. lua_interface->SetBooleanValue(state, true);
  357. return 1;
  358. }
  359. else
  360. 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());
  361. }
  362. else
  363. 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());
  364. }
  365. else
  366. {
  367. spawn->GetZone()->SendStateCommand(spawn, new_state);
  368. lua_interface->SetBooleanValue(state, true);
  369. return 1;
  370. }
  371. }
  372. lua_interface->SetBooleanValue(state, false);
  373. return 1;
  374. }
  375. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  376. if (!lua_interface)
  377. return 0;
  378. Spawn* spawn = lua_interface->GetSpawn(state);
  379. string variable = lua_interface->GetStringValue(state, 2);
  380. string value = lua_interface->GetStringValue(state, 3);
  381. 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.
  382. bool temporary_flag = true;
  383. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  384. if(num_args >= 5)
  385. 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
  386. int32 type = commands.GetSpawnSetType(variable);
  387. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  388. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  389. return 0;
  390. }
  391. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  392. if (!lua_interface)
  393. return 0;
  394. Spawn* spawn = lua_interface->GetSpawn(state);
  395. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  396. if (spawn && spawn_id > 0) {
  397. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  398. if (closest_spawn) {
  399. lua_interface->SetSpawnValue(state, closest_spawn);
  400. return 1;
  401. }
  402. }
  403. return 0;
  404. }
  405. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  406. if (!lua_interface)
  407. return 0;
  408. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  409. int32 position = lua_interface->GetInt32Value(state, 2);
  410. if (spawnList) {
  411. if (spawnList->size() > position) {
  412. lua_interface->SetSpawnValue(state, spawnList->at(position));
  413. return 1;
  414. }
  415. else {
  416. return 0;
  417. }
  418. return spawnList->size();
  419. }
  420. return 0;
  421. }
  422. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  423. if (!lua_interface)
  424. return 0;
  425. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  426. if (spawnList) {
  427. return spawnList->size();
  428. }
  429. return 0;
  430. }
  431. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  432. if (!lua_interface)
  433. return 0;
  434. vector<Spawn*>* spawnList = new vector<Spawn*>();
  435. lua_interface->SetSpawnListValue(state, spawnList);
  436. return 1;
  437. }
  438. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  439. if (!lua_interface)
  440. return 0;
  441. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  442. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  443. if (spawnList) {
  444. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  445. if (it == spawnList->end())
  446. spawnList->push_back(spawn);
  447. }
  448. return 0;
  449. }
  450. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  451. if (!lua_interface)
  452. return 0;
  453. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  454. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  455. if (spawnList) {
  456. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  457. if(it != spawnList->end())
  458. spawnList->erase(it);
  459. }
  460. return 0;
  461. }
  462. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  463. if (!lua_interface)
  464. return 0;
  465. Spawn* spawn = lua_interface->GetSpawn(state);
  466. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  467. if (spawn) {
  468. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  469. if (spawns.size() > 0) {
  470. vector<Spawn*>* spawnList = new vector<Spawn*>();
  471. vector<Spawn*>::iterator itr;
  472. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  473. spawnList->push_back(*itr);
  474. }
  475. lua_interface->SetSpawnListValue(state, spawnList);
  476. return 1;
  477. }
  478. }
  479. return 0;
  480. }
  481. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  482. if (!lua_interface)
  483. return 0;
  484. string variable_name = lua_interface->GetStringValue(state);
  485. Variable* var = variables.FindVariable(variable_name);
  486. if (var) {
  487. lua_interface->SetStringValue(state, var->GetValue());
  488. return 1;
  489. }
  490. return 0;
  491. }
  492. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  493. if (!lua_interface)
  494. return 0;
  495. int32 total_coins = lua_interface->GetInt32Value(state);
  496. if (total_coins == 0) {
  497. lua_interface->SetStringValue(state, "0 copper");
  498. return 1;
  499. }
  500. char tmp[64] = { 0 };
  501. string message = "";
  502. int32 val = 0;
  503. if (total_coins >= 1000000) {
  504. val = total_coins / 1000000;
  505. total_coins -= 1000000 * val;
  506. sprintf(tmp, " %u Platinum", val);
  507. message.append(tmp);
  508. memset(tmp, 0, 64);
  509. }
  510. if (total_coins >= 10000) {
  511. val = total_coins / 10000;
  512. total_coins -= 10000 * val;
  513. sprintf(tmp, " %u Gold", val);
  514. message.append(tmp);
  515. memset(tmp, 0, 64);
  516. }
  517. if (total_coins >= 100) {
  518. val = total_coins / 100;
  519. total_coins -= 100 * val;
  520. sprintf(tmp, " %u Silver", val);
  521. message.append(tmp);
  522. memset(tmp, 0, 64);
  523. }
  524. if (total_coins > 0) {
  525. sprintf(tmp, " %u Copper", (int32)total_coins);
  526. message.append(tmp);
  527. }
  528. lua_interface->SetStringValue(state, message.c_str());
  529. return 1;
  530. }
  531. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  532. ZoneServer* zone = lua_interface->GetZone(state);
  533. int32 group_id = lua_interface->GetInt32Value(state, 2);
  534. if (zone) {
  535. Spawn* spawn = zone->GetSpawnGroup(group_id);
  536. if (spawn) {
  537. lua_interface->SetSpawnValue(state, spawn);
  538. return 1;
  539. }
  540. }
  541. return 0;
  542. }
  543. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  544. ZoneServer* zone = lua_interface->GetZone(state);
  545. int32 location_id = lua_interface->GetInt32Value(state, 2);
  546. if (zone) {
  547. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  548. if (spawn) {
  549. lua_interface->SetSpawnValue(state, spawn);
  550. return 1;
  551. }
  552. }
  553. return 0;
  554. }
  555. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  556. Spawn* spawn = lua_interface->GetSpawn(state);
  557. if (spawn) {
  558. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  559. return 1;
  560. }
  561. return 0;
  562. }
  563. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  564. Spawn* spawn = lua_interface->GetSpawn(state);
  565. if (spawn) {
  566. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  567. return 1;
  568. }
  569. return 0;
  570. }
  571. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  572. if (!lua_interface)
  573. return 0;
  574. Spawn* spawn = lua_interface->GetSpawn(state);
  575. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  576. lua_interface->ResetFunctionStack(state);
  577. if (spawn) {
  578. spawn->SetSpawnGroupID(new_group_id);
  579. lua_interface->SetBooleanValue(state, true);
  580. return 1;
  581. }
  582. lua_interface->SetBooleanValue(state, false);
  583. return 1;
  584. }
  585. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  586. if (!lua_interface)
  587. return 0;
  588. Spawn* spawn = lua_interface->GetSpawn(state);
  589. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  590. lua_interface->ResetFunctionStack(state);
  591. if (spawn) {
  592. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  593. lua_interface->SetBooleanValue(state, true);
  594. return 1;
  595. }
  596. lua_interface->SetBooleanValue(state, false);
  597. return 1;
  598. }
  599. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  600. Spawn* spawn = lua_interface->GetSpawn(state);
  601. if (spawn) {
  602. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  603. return 1;
  604. }
  605. return 0;
  606. }
  607. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  608. Spawn* spawn = lua_interface->GetSpawn(state);
  609. if (spawn) {
  610. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  611. return 1;
  612. }
  613. return 0;
  614. }
  615. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  616. Player* player = (Player*)lua_interface->GetSpawn(state);
  617. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  618. if (player && player->IsPlayer() && faction_id > 0) {
  619. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  620. return 1;
  621. }
  622. return 0;
  623. }
  624. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  625. if (!lua_interface)
  626. return 0;
  627. Spawn* spawn = lua_interface->GetSpawn(state);
  628. int32 value = lua_interface->GetInt32Value(state, 2);
  629. if (spawn) {
  630. spawn->SetFactionID(value);
  631. }
  632. return 0;
  633. }
  634. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  635. Spawn* spawn = lua_interface->GetSpawn(state);
  636. if (spawn) {
  637. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  638. return 1;
  639. }
  640. return 0;
  641. }
  642. int EQ2Emu_lua_GetGender(lua_State* state) {
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. if (spawn) {
  645. lua_interface->SetInt32Value(state, spawn->GetGender());
  646. return 1;
  647. }
  648. return 0;
  649. }
  650. int EQ2Emu_lua_GetTarget(lua_State* state) {
  651. Spawn* spawn = lua_interface->GetSpawn(state);
  652. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  653. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  654. return 1;
  655. }
  656. return 0;
  657. }
  658. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  659. if (!lua_interface)
  660. return 0;
  661. Spawn* spawn = lua_interface->GetSpawn(state);
  662. string mp3_string = lua_interface->GetStringValue(state, 2);
  663. int32 key1 = lua_interface->GetInt32Value(state, 3);
  664. int32 key2 = lua_interface->GetInt32Value(state, 4);
  665. Spawn* player = lua_interface->GetSpawn(state, 5);
  666. if (spawn && mp3_string.length() > 0) {
  667. Client* client = 0;
  668. if (player && player->IsPlayer())
  669. client = spawn->GetZone()->GetClientBySpawn(player);
  670. if (client) {
  671. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  672. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  673. }
  674. else
  675. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  676. }
  677. return 0;
  678. }
  679. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* spawn = lua_interface->GetSpawn(state);
  683. if (spawn) {
  684. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  685. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  686. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  687. return 3;
  688. }
  689. return 0;
  690. }
  691. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  692. if (!lua_interface)
  693. return 0;
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. if (spawn) {
  696. int32 item_id = lua_interface->GetInt32Value(state, 2);
  697. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  698. return 1;
  699. }
  700. return 0;
  701. }
  702. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  703. if (!lua_interface)
  704. return 0;
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. if (spawn && spawn->IsEntity()) {
  707. int32 item_id = lua_interface->GetInt32Value(state, 2);
  708. int16 charges = lua_interface->GetInt16Value(state, 3);
  709. if (charges == 0)
  710. charges = 1;
  711. ((Entity*)spawn)->AddLootItem(item_id, charges);
  712. }
  713. return 0;
  714. }
  715. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  716. if (!lua_interface)
  717. return 0;
  718. Spawn* spawn = lua_interface->GetSpawn(state);
  719. if (spawn && spawn->IsEntity()) {
  720. int32 item_id = lua_interface->GetInt32Value(state, 2);
  721. spawn->LootItem(item_id);
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  726. if (!lua_interface)
  727. return 0;
  728. Spawn* spawn = lua_interface->GetSpawn(state);
  729. if (spawn) {
  730. int32 val = lua_interface->GetInt32Value(state, 2);
  731. spawn->AddLootCoins(val);
  732. }
  733. return 0;
  734. }
  735. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  736. if (!lua_interface)
  737. return 0;
  738. Spawn* entity = lua_interface->GetSpawn(state);
  739. Spawn* player = lua_interface->GetSpawn(state, 2);
  740. if (entity && player && player->IsPlayer()) {
  741. int32 coins = lua_interface->GetInt32Value(state, 3);
  742. vector<Item*>* items = 0;
  743. int i = 0;
  744. int32 item_id = 0;
  745. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  746. if (items == 0)
  747. items = new vector<Item*>;
  748. if (master_item_list.GetItem(item_id))
  749. items->push_back(master_item_list.GetItem(item_id));
  750. i++;
  751. }
  752. Client* client = 0;
  753. client = player->GetZone()->GetClientBySpawn(player);
  754. if (client)
  755. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  756. if(coins > 0)
  757. entity->AddLootCoins(coins);
  758. safe_delete(items);
  759. }
  760. return 0;
  761. }
  762. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  763. if (!lua_interface)
  764. return 0;
  765. Spawn* entity = lua_interface->GetSpawn(state);
  766. Spawn* player = lua_interface->GetSpawn(state, 2);
  767. int32 item_id = lua_interface->GetInt32Value(state, 3);
  768. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  769. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  770. return 1;
  771. }
  772. return 0;
  773. }
  774. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  775. if (!lua_interface)
  776. return 0;
  777. Spawn* entity = lua_interface->GetSpawn(state);
  778. Spawn* player = lua_interface->GetSpawn(state, 2);
  779. if (entity && player && player->IsPlayer()) {
  780. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  781. return 1;
  782. }
  783. return 0;
  784. }
  785. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  786. if (!lua_interface)
  787. return 0;
  788. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  789. safe_delete(conversation);
  790. conversation = new vector<ConversationOption>();
  791. lua_interface->SetConversationValue(state, conversation);
  792. return 1;
  793. }
  794. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  795. if (!lua_interface)
  796. return 0;
  797. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  798. if (conversation) {
  799. ConversationOption conv_option;
  800. conv_option.option = lua_interface->GetStringValue(state, 2);
  801. conv_option.function = lua_interface->GetStringValue(state, 3);
  802. if (conv_option.option.length() > 0)
  803. conversation->push_back(conv_option);
  804. }
  805. return 0;
  806. }
  807. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  808. if (!lua_interface)
  809. return 0;
  810. Spawn* npc = lua_interface->GetSpawn(state);
  811. Spawn* player = lua_interface->GetSpawn(state, 2);
  812. if (npc && player && player->IsPlayer() && player->GetZone()) {
  813. Client* client = player->GetZone()->GetClientBySpawn(player);
  814. if (client) {
  815. int32 conversation_id = client->GetConversationID(npc, 0);
  816. client->CloseDialog(conversation_id);
  817. }
  818. }
  819. return 0;
  820. }
  821. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  822. if (!lua_interface)
  823. return 0;
  824. Item* item = lua_interface->GetItem(state);
  825. Spawn* player = lua_interface->GetSpawn(state, 2);
  826. if (item && player && player->IsPlayer() && player->GetZone()) {
  827. Client* client = player->GetZone()->GetClientBySpawn(player);
  828. if (client) {
  829. int32 conversation_id = client->GetConversationID(0, item);
  830. client->CloseDialog(conversation_id);
  831. }
  832. }
  833. return 0;
  834. }
  835. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  836. if (!lua_interface)
  837. return 0;
  838. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  839. Spawn* spawn = 0;
  840. Item* item = 0;
  841. int8 type = lua_interface->GetInt8Value(state, 2);
  842. if (type == 1 || type == 3)
  843. spawn = lua_interface->GetSpawn(state, 3);
  844. else if (type == 2 || type == 4)
  845. item = lua_interface->GetItem(state, 3);
  846. Spawn* player = lua_interface->GetSpawn(state, 4);
  847. string text = lua_interface->GetStringValue(state, 5);
  848. string mp3 = lua_interface->GetStringValue(state, 6);
  849. int32 key1 = lua_interface->GetInt32Value(state, 7);
  850. int32 key2 = lua_interface->GetInt32Value(state, 8);
  851. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  852. Client* client = player->GetZone()->GetClientBySpawn(player);
  853. if (client) {
  854. if (spawn) {
  855. // Need to do this so the function works the same as it did before
  856. if (type == 1)
  857. type++;
  858. if (mp3.length() > 0)
  859. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  860. else
  861. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  862. }
  863. else {
  864. if (mp3.length() > 0)
  865. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  866. else
  867. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  868. }
  869. }
  870. }
  871. safe_delete(conversation);
  872. lua_interface->SetConversationValue(state, NULL);
  873. return 0;
  874. }
  875. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  876. if(!lua_interface)
  877. return 0;
  878. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  879. Item* item = lua_interface->GetItem(state, 2);
  880. Spawn* player = lua_interface->GetSpawn(state, 3);
  881. string text = lua_interface->GetStringValue(state, 4);
  882. string mp3 = lua_interface->GetStringValue(state, 5);
  883. int32 key1 = lua_interface->GetInt32Value(state, 6);
  884. int32 key2 = lua_interface->GetInt32Value(state, 7);
  885. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  886. Client* client = player->GetZone()->GetClientBySpawn(player);
  887. if(client){
  888. if(mp3.length() > 0)
  889. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  890. else
  891. client->DisplayConversation(item, conversation, (char*)text.c_str());
  892. }
  893. safe_delete(conversation);
  894. }
  895. return 0;
  896. }*/
  897. int EQ2Emu_lua_StartConversation(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  901. Spawn* source = lua_interface->GetSpawn(state, 2);
  902. Spawn* player = lua_interface->GetSpawn(state, 3);
  903. string text = lua_interface->GetStringValue(state, 4);
  904. string mp3 = lua_interface->GetStringValue(state, 5);
  905. int32 key1 = lua_interface->GetInt32Value(state, 6);
  906. int32 key2 = lua_interface->GetInt32Value(state, 7);
  907. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  908. Client* client = source->GetZone()->GetClientBySpawn(player);
  909. if (mp3.length() > 0)
  910. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  911. else
  912. client->DisplayConversation(source, 1, conversation, text.c_str());
  913. safe_delete(conversation);
  914. lua_interface->SetConversationValue(state, NULL);
  915. }
  916. else
  917. 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);
  918. return 0;
  919. }
  920. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  921. if (!lua_interface)
  922. return 0;
  923. Spawn* spawn = lua_interface->GetSpawn(state);
  924. float distance = lua_interface->GetFloatValue(state, 2);
  925. string in_range_function = lua_interface->GetStringValue(state, 3);
  926. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  927. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  928. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  929. return 0;
  930. }
  931. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  932. ZoneServer* zone = lua_interface->GetZone(state);
  933. float x = lua_interface->GetFloatValue(state, 2);
  934. float y = lua_interface->GetFloatValue(state, 3);
  935. float z = lua_interface->GetFloatValue(state, 4);
  936. float max_variation = lua_interface->GetFloatValue(state, 5);
  937. string in_range_function = lua_interface->GetStringValue(state, 6);
  938. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  939. if (zone && in_range_function.length() > 0)
  940. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  941. return 0;
  942. }
  943. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  944. if (!lua_interface)
  945. return 0;
  946. Spawn* spawn = lua_interface->GetSpawn(state);
  947. if (spawn && spawn->IsEntity()) {
  948. int32 val = lua_interface->GetInt32Value(state, 2);
  949. ((Entity*)spawn)->SetLootCoins(val);
  950. }
  951. return 0;
  952. }
  953. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  954. if (!lua_interface)
  955. return 0;
  956. Spawn* spawn = lua_interface->GetSpawn(state);
  957. if (spawn && spawn->IsEntity()) {
  958. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  959. return 1;
  960. }
  961. return 0;
  962. }
  963. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  964. if (!lua_interface)
  965. return 0;
  966. Spawn* spawn = lua_interface->GetSpawn(state);
  967. float x = lua_interface->GetFloatValue(state, 2);
  968. float y = lua_interface->GetFloatValue(state, 3);
  969. float z = lua_interface->GetFloatValue(state, 4);
  970. float speed = lua_interface->GetFloatValue(state, 5);
  971. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  972. string function = lua_interface->GetStringValue(state, 7);
  973. if (spawn) {
  974. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  975. spawn->GetZone()->AddMovementNPC(spawn);
  976. }
  977. lua_interface->ResetFunctionStack(state);
  978. return 0;
  979. }
  980. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  981. if (!lua_interface)
  982. return 0;
  983. Spawn* spawn = lua_interface->GetSpawn(state);
  984. if (spawn) {
  985. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  986. return 1;
  987. }
  988. return 0;
  989. }
  990. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  991. if (!lua_interface)
  992. return 0;
  993. Spawn* spawn = lua_interface->GetSpawn(state);
  994. if (spawn && spawn->IsPlayer()) {
  995. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  996. return 1;
  997. }
  998. lua_interface->SetInt32Value(state, 0);
  999. return 1;
  1000. }
  1001. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. Spawn* spawn = lua_interface->GetSpawn(state);
  1005. Spawn* target = lua_interface->GetSpawn(state, 2);
  1006. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1007. bool reset_action_state = true;
  1008. if(num_args > 2)
  1009. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1010. if (spawn && target) {
  1011. if (spawn->IsEntity())
  1012. // ((Entity*)spawn)->FaceTarget(target);
  1013. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1014. }
  1015. lua_interface->ResetFunctionStack(state);
  1016. return 0;
  1017. }
  1018. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1019. if (!lua_interface)
  1020. return 0;
  1021. Spawn* spawn = lua_interface->GetSpawn(state);
  1022. float x = lua_interface->GetFloatValue(state, 2);
  1023. float y = lua_interface->GetFloatValue(state, 3);
  1024. float z = lua_interface->GetFloatValue(state, 4);
  1025. float speed = lua_interface->GetFloatValue(state, 5);
  1026. string lua_function = lua_interface->GetStringValue(state, 6);
  1027. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1028. if (spawn) {
  1029. if (speed == 0)
  1030. speed = spawn->GetSpeed();
  1031. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1032. }
  1033. lua_interface->ResetFunctionStack(state);
  1034. return 0;
  1035. }
  1036. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1037. if (!lua_interface)
  1038. return 0;
  1039. Spawn* spawn = lua_interface->GetSpawn(state);
  1040. if (spawn) {
  1041. spawn->ClearRunningLocations();
  1042. }
  1043. return 0;
  1044. }
  1045. int EQ2Emu_lua_Say(lua_State* state) {
  1046. if (!lua_interface)
  1047. return 0;
  1048. Spawn* spawn = lua_interface->GetSpawn(state);
  1049. string message = lua_interface->GetStringValue(state, 2);
  1050. Spawn* player = lua_interface->GetSpawn(state, 3);
  1051. int32 language = lua_interface->GetInt32Value(state, 4);
  1052. if (spawn && message.length() > 0) {
  1053. Client* client = 0;
  1054. if (player && player->IsPlayer())
  1055. client = spawn->GetZone()->GetClientBySpawn(player);
  1056. if (client)
  1057. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1058. else
  1059. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1060. }
  1061. lua_interface->ResetFunctionStack(state);
  1062. return 0;
  1063. }
  1064. int EQ2Emu_lua_Shout(lua_State* state) {
  1065. if (!lua_interface)
  1066. return 0;
  1067. Spawn* spawn = lua_interface->GetSpawn(state);
  1068. string message = lua_interface->GetStringValue(state, 2);
  1069. Spawn* player = lua_interface->GetSpawn(state, 3);
  1070. if (spawn && message.length() > 0) {
  1071. Client* client = 0;
  1072. if (player && player->IsPlayer())
  1073. client = spawn->GetZone()->GetClientBySpawn(player);
  1074. if (client)
  1075. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1076. else
  1077. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1078. }
  1079. lua_interface->ResetFunctionStack(state);
  1080. return 0;
  1081. }
  1082. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1083. if (!lua_interface)
  1084. return 0;
  1085. Spawn* spawn = lua_interface->GetSpawn(state);
  1086. string message = lua_interface->GetStringValue(state, 2);
  1087. Spawn* player = lua_interface->GetSpawn(state, 3);
  1088. if (spawn && message.length() > 0) {
  1089. Client* client = 0;
  1090. if (player && player->IsPlayer())
  1091. client = spawn->GetZone()->GetClientBySpawn(player);
  1092. if (client)
  1093. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1094. else
  1095. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1096. }
  1097. lua_interface->ResetFunctionStack(state);
  1098. return 0;
  1099. }
  1100. int EQ2Emu_lua_Emote(lua_State* state) {
  1101. if (!lua_interface)
  1102. return 0;
  1103. Spawn* spawn = lua_interface->GetSpawn(state);
  1104. string message = lua_interface->GetStringValue(state, 2);
  1105. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1106. Spawn* player = lua_interface->GetSpawn(state, 4);
  1107. char* to = 0;
  1108. if (spawn2)
  1109. to = spawn2->GetName();
  1110. if (spawn && message.length() > 0) {
  1111. Client* client = 0;
  1112. if (player && player->IsPlayer())
  1113. client = spawn->GetZone()->GetClientBySpawn(player);
  1114. if (client)
  1115. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1116. else
  1117. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1118. }
  1119. lua_interface->ResetFunctionStack(state);
  1120. return 0;
  1121. }
  1122. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1123. if (!lua_interface)
  1124. return 0;
  1125. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1126. if (!luaspell)
  1127. return 0;
  1128. Spawn* caster = luaspell->caster;
  1129. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1130. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1131. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1132. Spawn* target = lua_interface->GetSpawn(state, 4);
  1133. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1134. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1135. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1136. lua_interface->ResetFunctionStack(state);
  1137. boost::to_lower(heal_type);
  1138. if (caster && caster->IsEntity()) {
  1139. bool success = false;
  1140. luaspell->resisted = false;
  1141. if (target) {
  1142. float distance = caster->GetDistance(target, true);
  1143. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1144. success = true;
  1145. }
  1146. if (luaspell->targets.size() > 0) {
  1147. Spawn* target = 0;
  1148. ZoneServer* zone = luaspell->caster->GetZone();
  1149. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1150. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1151. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1152. float distance = caster->GetDistance(target, true);
  1153. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1154. }
  1155. }
  1156. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1157. success = true;
  1158. }
  1159. if (success) {
  1160. if (caster->GetZone())
  1161. caster->GetZone()->TriggerCharSheetTimer();
  1162. }
  1163. }
  1164. return 0;
  1165. }
  1166. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1167. if (!lua_interface)
  1168. return 0;
  1169. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1170. if (!luaspell)
  1171. return 0;
  1172. Spawn* caster = luaspell->caster;
  1173. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1174. float percentage = lua_interface->GetFloatValue(state, 2);
  1175. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1176. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1177. Spawn* target = lua_interface->GetSpawn(state, 5);
  1178. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1179. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1180. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1181. lua_interface->ResetFunctionStack(state);
  1182. boost::to_lower(heal_type);
  1183. int32 min_heal = 0, max_heal = 0;
  1184. if (caster && caster->IsEntity() && target) {
  1185. if(percentage <= 0.0f)
  1186. {
  1187. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1188. return 0;
  1189. }
  1190. if(heal_type == "power")
  1191. {
  1192. if(current_value)
  1193. {
  1194. if(caster_value)
  1195. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1196. else
  1197. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1198. }
  1199. else
  1200. {
  1201. if(caster_value)
  1202. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1203. else
  1204. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1205. }
  1206. }
  1207. else
  1208. {
  1209. if(current_value)
  1210. {
  1211. if(caster_value)
  1212. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1213. else
  1214. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1215. }
  1216. else
  1217. {
  1218. if(caster_value)
  1219. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1220. else
  1221. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1222. }
  1223. }
  1224. bool success = false;
  1225. luaspell->resisted = false;
  1226. if (target) {
  1227. float distance = caster->GetDistance(target, true);
  1228. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1229. success = true;
  1230. }
  1231. if (luaspell->targets.size() > 0) {
  1232. Spawn* target = 0;
  1233. ZoneServer* zone = luaspell->caster->GetZone();
  1234. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1235. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1236. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1237. float distance = caster->GetDistance(target, true);
  1238. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1239. }
  1240. }
  1241. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1242. success = true;
  1243. }
  1244. if (success) {
  1245. if (caster->GetZone())
  1246. caster->GetZone()->TriggerCharSheetTimer();
  1247. }
  1248. }
  1249. return 0;
  1250. }
  1251. int EQ2Emu_lua_AddItem(lua_State* state) {
  1252. if (!lua_interface)
  1253. return 0;
  1254. Spawn* spawn = lua_interface->GetSpawn(state);
  1255. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1256. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1257. // default of 1 quantity to add
  1258. if (quantity == 0)
  1259. quantity = 1;
  1260. if (spawn && spawn->IsPlayer()) {
  1261. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1262. if (client && item_id > 0) {
  1263. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1264. return 1;
  1265. }
  1266. }
  1267. lua_interface->SetBooleanValue(state, false);
  1268. return 1;
  1269. }
  1270. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1271. if (!lua_interface)
  1272. return 0;
  1273. Spawn* spawn = lua_interface->GetSpawn(state);
  1274. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1275. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1276. string location = lua_interface->GetStringValue(state, 4);
  1277. if (spawn && spawn->IsPlayer()) {
  1278. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1279. if (client && item_id > 0) {
  1280. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1281. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1282. else
  1283. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1284. if (send_messages) {
  1285. Item* item = master_item_list.GetItem(item_id);
  1286. if (item) {
  1287. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1288. string popup_text = "You receive " + item->name;
  1289. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1290. }
  1291. }
  1292. return 1;
  1293. }
  1294. }
  1295. lua_interface->SetBooleanValue(state, false);
  1296. return 1;
  1297. }
  1298. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1299. Spawn* spawn = lua_interface->GetSpawn(state);
  1300. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1301. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1302. // default of 1 to remove
  1303. if (quantity == 0)
  1304. quantity = 1;
  1305. Client* client;
  1306. Item* item;
  1307. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1308. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1309. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1310. if (client->RemoveItem(item, quantity)) {
  1311. lua_interface->SetBooleanValue(state, true);
  1312. return 1;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. lua_interface->SetBooleanValue(state, false);
  1318. return 1;
  1319. }
  1320. int EQ2Emu_lua_HasItem(lua_State* state) {
  1321. Spawn* player = lua_interface->GetSpawn(state);
  1322. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1323. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1324. if (player && player->IsPlayer()) {
  1325. bool hasItem = false;
  1326. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1327. if (!hasItem)
  1328. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1329. lua_interface->SetBooleanValue(state, hasItem);
  1330. return 1;
  1331. }
  1332. lua_interface->SetBooleanValue(state, false);
  1333. return 1;
  1334. }
  1335. int EQ2Emu_lua_Spawn(lua_State* state) {
  1336. if (!lua_interface)
  1337. return 0;
  1338. ZoneServer* zone = lua_interface->GetZone(state);
  1339. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1340. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1341. float x = lua_interface->GetFloatValue(state, 4);
  1342. float y = lua_interface->GetFloatValue(state, 5);
  1343. float z = lua_interface->GetFloatValue(state, 6);
  1344. float heading = lua_interface->GetFloatValue(state, 7);
  1345. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1346. Spawn* spawn = zone->GetSpawn(spawn_id);
  1347. if (!spawn)
  1348. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1349. else {
  1350. spawn->SetX(x);
  1351. spawn->SetZ(z);
  1352. spawn->SetY(y,true,true);
  1353. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1354. spawn->SetHeading(heading);
  1355. if (restricted_npc)
  1356. spawn->AddAllowAccessSpawn(spawn);
  1357. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1358. bool scriptActive = false;
  1359. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1360. scriptActive = true;
  1361. spawn->SetSpawnScript(string(spawn_script));
  1362. }
  1363. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1364. zone->AddSpawn(spawn);
  1365. if (scriptActive) {
  1366. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1367. }
  1368. lua_interface->SetSpawnValue(state, spawn);
  1369. return 1;
  1370. }
  1371. }
  1372. else {
  1373. string output = "Invalid paramaters to LUA Spawn command: \n";
  1374. if (!zone)
  1375. output = output.append("\t").append("Missing zone reference. \n");
  1376. if (spawn_id == 0)
  1377. output = output.append("\t").append("Missing spawn_id.");
  1378. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1379. }
  1380. return 0;
  1381. }
  1382. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1383. if (!lua_interface)
  1384. return 0;
  1385. ZoneServer* zone = lua_interface->GetZone(state);
  1386. if (zone) {
  1387. lua_interface->SetStringValue(state, zone->GetZoneName());
  1388. return 1;
  1389. }
  1390. return 0;
  1391. }
  1392. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1393. if (!lua_interface)
  1394. return 0;
  1395. ZoneServer* zone = lua_interface->GetZone(state);
  1396. if (zone) {
  1397. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1398. return 1;
  1399. }
  1400. return 0;
  1401. }
  1402. int EQ2Emu_lua_GetZone(lua_State* state) {
  1403. if (!lua_interface)
  1404. return 0;
  1405. int32 zone_id = lua_interface->GetInt32Value(state);
  1406. ZoneServer* zone = 0;
  1407. if (zone_id > 0)
  1408. zone = zone_list.Get(zone_id);
  1409. else {
  1410. string zone_name = lua_interface->GetStringValue(state);
  1411. if (zone_name.length() > 0) {
  1412. zone = zone_list.Get(zone_name.c_str());
  1413. }
  1414. else {
  1415. Spawn* spawn = lua_interface->GetSpawn(state);
  1416. if (spawn)
  1417. zone = spawn->GetZone();
  1418. }
  1419. }
  1420. if (zone) {
  1421. lua_interface->SetZoneValue(state, zone);
  1422. return 1;
  1423. }
  1424. return 0;
  1425. }
  1426. int EQ2Emu_lua_AddHate(lua_State* state) {
  1427. Spawn* entity = lua_interface->GetSpawn(state);
  1428. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1429. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1430. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1431. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1432. if (entity && entity->IsEntity() && amount != 0) {
  1433. if (luaspell) {
  1434. ZoneServer* zone = luaspell->caster->GetZone();
  1435. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1436. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1437. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1438. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1439. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1440. if (send_packet)
  1441. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1442. }
  1443. }
  1444. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1445. }
  1446. else if (npc && npc->IsNPC() && npc->GetZone())
  1447. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1448. }
  1449. return 0;
  1450. }
  1451. int EQ2Emu_lua_Zone(lua_State* state) {
  1452. if (!lua_interface)
  1453. return 0;
  1454. ZoneServer* zone = lua_interface->GetZone(state);
  1455. Spawn* player = lua_interface->GetSpawn(state, 2);
  1456. Client* client = 0;
  1457. if (player && player->IsPlayer())
  1458. client = player->GetZone()->GetClientBySpawn(player);
  1459. float x = lua_interface->GetFloatValue(state, 3);
  1460. float y = lua_interface->GetFloatValue(state, 4);
  1461. float z = lua_interface->GetFloatValue(state, 5);
  1462. float heading = lua_interface->GetFloatValue(state, 6);
  1463. if (zone && client) {
  1464. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1465. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1466. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1467. {
  1468. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1469. return 0;
  1470. }
  1471. if (x != 0 || y != 0 || z != 0) {
  1472. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1473. player->SetX(x);
  1474. player->SetY(y);
  1475. player->SetZ(z);
  1476. player->SetHeading(heading);
  1477. client->Zone(zone->GetZoneName(), false);
  1478. }
  1479. else
  1480. client->Zone(zone->GetZoneName());
  1481. }
  1482. else
  1483. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1484. return 0;
  1485. }
  1486. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1487. if (!lua_interface)
  1488. return 0;
  1489. Spawn* spawn = lua_interface->GetSpawn(state);
  1490. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1491. if (spawn && spawn2)
  1492. spawn->AddAllowAccessSpawn(spawn2);
  1493. return 0;
  1494. }
  1495. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1496. if (!lua_interface)
  1497. return 0;
  1498. Spawn* target = lua_interface->GetSpawn(state);
  1499. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1500. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1501. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1502. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1503. if (!target) {
  1504. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1505. return 0;
  1506. }
  1507. if (!target->IsEntity()) {
  1508. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1509. return 0;
  1510. }
  1511. if (spell_id <= 0) {
  1512. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1513. return 0;
  1514. }
  1515. if (caster && !caster->IsEntity()) {
  1516. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1517. return 0;
  1518. }
  1519. if (spell_tier == 0)
  1520. spell_tier = 1;
  1521. if (!caster)
  1522. caster = target;
  1523. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1524. return 0;
  1525. }
  1526. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1527. if (!lua_interface)
  1528. return 0;
  1529. Spawn* target = lua_interface->GetSpawn(state);
  1530. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1531. if (!luaspell)
  1532. return 0;
  1533. Spawn* caster = luaspell->caster;
  1534. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1535. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1536. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1537. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1538. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1539. //lua_interface->ResetFunctionStack(state);
  1540. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1541. vector<int16> faction_req;
  1542. vector<int16> race_req;
  1543. int32 class_req = 0;
  1544. int32 i = 0;
  1545. int8 f = 0;
  1546. int8 r = 0;
  1547. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1548. if (class_id < 100) {
  1549. class_req += pow(2.0, double(class_id - 1));
  1550. }
  1551. else if (class_id > 100 && class_id < 1000) {
  1552. race_req.push_back(class_id);
  1553. r++;
  1554. }
  1555. else {
  1556. faction_req.push_back(class_id);
  1557. f++;
  1558. }
  1559. i++;
  1560. }
  1561. if (caster && caster->IsEntity()) {
  1562. bool race_match = false;
  1563. bool success = false;
  1564. luaspell->resisted = false;
  1565. if (luaspell->targets.size() > 0) {
  1566. ZoneServer* zone = luaspell->caster->GetZone();
  1567. Spawn* target = 0;
  1568. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1569. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1570. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1571. if (race_req.size() > 0) {
  1572. for (int8 i = 0; i < race_req.size(); i++) {
  1573. if (target->GetLuaRaceId() == race_req[i]) {
  1574. race_match = true;
  1575. }
  1576. }
  1577. }
  1578. else
  1579. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1580. if (race_match == true) {
  1581. float distance = caster->GetDistance(target, true);
  1582. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1583. }
  1584. }
  1585. }
  1586. success = true;
  1587. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1588. }
  1589. else if (target) {
  1590. //check class and race/faction here
  1591. if (race_req.size() > 0) {
  1592. for (int8 i = 0; i < race_req.size(); i++) {
  1593. if (target->GetLuaRaceId() == race_req[i]) {
  1594. race_match = true;
  1595. }
  1596. }
  1597. }
  1598. else
  1599. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1600. if (race_match == true) {
  1601. float distance = caster->GetDistance(target, true);
  1602. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1603. success = true;
  1604. }
  1605. }
  1606. if (success) {
  1607. Spell* spell = luaspell->spell;
  1608. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1609. ((Player*)caster)->InCombat(true);
  1610. if (caster->GetZone())
  1611. caster->GetZone()->TriggerCharSheetTimer();
  1612. }
  1613. }
  1614. }
  1615. return 0;
  1616. }
  1617. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1618. if (!lua_interface)
  1619. return 0;
  1620. Spawn* spawn = lua_interface->GetSpawn(state);
  1621. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1622. lua_interface->ResetFunctionStack(state);
  1623. if (spawn && value != 0) {
  1624. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1625. spawn->SetPower(spawn->GetTotalPower());
  1626. else
  1627. spawn->SetPower(spawn->GetPower() + value);
  1628. }
  1629. return 0;
  1630. }
  1631. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1632. if (!lua_interface)
  1633. return 0;
  1634. Spawn* spawn = lua_interface->GetSpawn(state);
  1635. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1636. lua_interface->ResetFunctionStack(state);
  1637. if (spawn && value != 0) {
  1638. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1639. spawn->SetHP(spawn->GetTotalHP());
  1640. else
  1641. spawn->SetHP(spawn->GetHP() + value);
  1642. }
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1650. lua_interface->ResetFunctionStack(state);
  1651. if (spawn && value != 0) {
  1652. spawn->SetPower(spawn->GetPower() + value);
  1653. if (value > spawn->GetTotalHPBase())
  1654. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1655. }
  1656. return 0;
  1657. }
  1658. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1659. if (!lua_interface)
  1660. return 0;
  1661. Spawn* spawn = lua_interface->GetSpawn(state);
  1662. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (spawn && value != 0) {
  1665. spawn->SetHP(spawn->GetHP() + value);
  1666. if (value > spawn->GetTotalHPBase())
  1667. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1668. }
  1669. return 0;
  1670. }
  1671. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1672. if (!lua_interface)
  1673. return 0;
  1674. Spawn* spawn = lua_interface->GetSpawn(state);
  1675. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1676. lua_interface->ResetFunctionStack(state);
  1677. if (spawn) {
  1678. spawn->SetHP(value);
  1679. if (value > spawn->GetTotalHPBase())
  1680. spawn->SetTotalHP(value);
  1681. }
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* spawn = lua_interface->GetSpawn(state);
  1688. float value = lua_interface->GetFloatValue(state, 2);
  1689. lua_interface->ResetFunctionStack(state);
  1690. if (spawn && spawn->IsEntity() && value > 0)
  1691. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1692. if (spawn->IsPlayer())
  1693. ((Player*)spawn)->SetCharSheetChanged(true);
  1694. return 0;
  1695. }
  1696. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1697. if (!lua_interface)
  1698. return 0;
  1699. Spawn* spawn = lua_interface->GetSpawn(state);
  1700. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1701. lua_interface->ResetFunctionStack(state);
  1702. if (spawn && spawn->IsEntity() && value > 0)
  1703. ((Entity*)spawn)->SetTotalHPBase(value);
  1704. return 0;
  1705. }
  1706. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1707. if (!lua_interface)
  1708. return 0;
  1709. Spawn* spawn = lua_interface->GetSpawn(state);
  1710. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1711. lua_interface->ResetFunctionStack(state);
  1712. if (spawn && value > 0) {
  1713. spawn->SetPower(value);
  1714. if (value > spawn->GetTotalPowerBase())
  1715. spawn->SetTotalPower(value);
  1716. }
  1717. return 0;
  1718. }
  1719. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1720. if (!lua_interface)
  1721. return 0;
  1722. Spawn* spawn = lua_interface->GetSpawn(state);
  1723. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1724. lua_interface->ResetFunctionStack(state);
  1725. if (spawn && spawn->IsEntity() && value > 0)
  1726. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1727. return 0;
  1728. }
  1729. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1730. if (!lua_interface)
  1731. return 0;
  1732. Spawn* spawn = lua_interface->GetSpawn(state);
  1733. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1734. lua_interface->ResetFunctionStack(state);
  1735. if (spawn && spawn->IsEntity() && value > 0)
  1736. ((Entity*)spawn)->SetTotalPowerBase(value);
  1737. return 0;
  1738. }
  1739. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1740. if (!lua_interface)
  1741. return 0;
  1742. Spawn* spawn = lua_interface->GetSpawn(state);
  1743. float x = lua_interface->GetFloatValue(state, 2);
  1744. float y = lua_interface->GetFloatValue(state, 3);
  1745. float z = lua_interface->GetFloatValue(state, 4);
  1746. float heading = lua_interface->GetFloatValue(state, 5);
  1747. lua_interface->ResetFunctionStack(state);
  1748. if (spawn) {
  1749. spawn->SetX(x);
  1750. spawn->SetY(y);
  1751. spawn->SetZ(z);
  1752. if (heading != 0)
  1753. spawn->SetHeading(heading);
  1754. spawn->SetSpawnOrigX(spawn->GetX());
  1755. spawn->SetSpawnOrigY(spawn->GetY());
  1756. spawn->SetSpawnOrigZ(spawn->GetZ());
  1757. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1758. if (spawn->IsPlayer()) {
  1759. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1760. if (client) {
  1761. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1762. client->QueuePacket(packet);
  1763. }
  1764. }
  1765. }
  1766. return 0;
  1767. }
  1768. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1769. if (!lua_interface)
  1770. return 0;
  1771. Spawn* spawn = lua_interface->GetSpawn(state);
  1772. float value = lua_interface->GetFloatValue(state, 2);
  1773. lua_interface->ResetFunctionStack(state);
  1774. if (spawn) {
  1775. spawn->SetHeading(value);
  1776. if (spawn->IsPlayer()) {
  1777. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1778. if (client) {
  1779. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1780. client->QueuePacket(packet);
  1781. }
  1782. }
  1783. }
  1784. return 0;
  1785. }
  1786. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1787. if (!lua_interface)
  1788. return 0;
  1789. Spawn* spawn = lua_interface->GetSpawn(state);
  1790. int16 value = lua_interface->GetInt16Value(state, 2);
  1791. lua_interface->ResetFunctionStack(state);
  1792. if (spawn)
  1793. spawn->SetModelType(value);
  1794. return 0;
  1795. }
  1796. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1797. if (!lua_interface)
  1798. return 0;
  1799. Spawn* spawn = lua_interface->GetSpawn(state);
  1800. int8 value = lua_interface->GetInt8Value(state, 2);
  1801. lua_interface->ResetFunctionStack(state);
  1802. if (spawn) {
  1803. if (spawn->IsPlayer())
  1804. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1805. else
  1806. spawn->SetAdventureClass(value);
  1807. }
  1808. return 0;
  1809. }
  1810. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1811. if (!lua_interface)
  1812. return 0;
  1813. Spawn* spawn = lua_interface->GetSpawn(state);
  1814. int8 value = lua_interface->GetInt8Value(state, 2);
  1815. lua_interface->ResetFunctionStack(state);
  1816. if (spawn) {
  1817. spawn->SetTradeskillClass(value);
  1818. if (spawn->IsEntity()) {
  1819. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1820. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1821. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1822. }
  1823. if (spawn->IsPlayer())
  1824. ((Player*)spawn)->SetCharSheetChanged(true);
  1825. }
  1826. return 0;
  1827. }
  1828. int EQ2Emu_lua_SetMount(lua_State* state) {
  1829. if (!lua_interface)
  1830. return 0;
  1831. Spawn* spawn = lua_interface->GetSpawn(state);
  1832. int16 value = lua_interface->GetInt16Value(state, 2);
  1833. if (spawn && spawn->IsEntity()) {
  1834. ((Entity*)spawn)->SetMount(value);
  1835. EQ2_Color color;
  1836. color.red = 255;
  1837. color.green = 255;
  1838. color.blue = 255;
  1839. ((Entity*)spawn)->SetMountColor(&color);
  1840. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1841. }
  1842. return 0;
  1843. }
  1844. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1845. if (!lua_interface)
  1846. return 0;
  1847. Spawn* spawn = lua_interface->GetSpawn(state);
  1848. EQ2_Color mount_color;
  1849. EQ2_Color saddle_color;
  1850. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1851. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1852. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1853. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1854. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1855. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1856. if (spawn && spawn->IsEntity()) {
  1857. ((Entity*)spawn)->SetMountColor(&mount_color);
  1858. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1859. }
  1860. return 0;
  1861. }
  1862. int EQ2Emu_lua_GetMount(lua_State* state) {
  1863. if (!lua_interface)
  1864. return 0;
  1865. Spawn* spawn = lua_interface->GetSpawn(state);
  1866. if (spawn && spawn->IsEntity()) {
  1867. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1868. return 1;
  1869. }
  1870. return 0;
  1871. }
  1872. int EQ2Emu_lua_GetRace(lua_State* state) {
  1873. if (!lua_interface)
  1874. return 0;
  1875. Spawn* spawn = lua_interface->GetSpawn(state);
  1876. if (spawn)
  1877. {
  1878. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1879. lua_interface->SetInt32Value(state, spawn->GetRace());
  1880. return 1;
  1881. }
  1882. return 0;
  1883. }
  1884. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1885. if (!lua_interface)
  1886. return 0;
  1887. Spawn* spawn = lua_interface->GetSpawn(state);
  1888. if (spawn) {
  1889. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1890. return 1;
  1891. }
  1892. return 0;
  1893. }
  1894. int EQ2Emu_lua_GetClass(lua_State* state) {
  1895. Spawn* spawn = lua_interface->GetSpawn(state);
  1896. if (spawn) {
  1897. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1898. return 1;
  1899. }
  1900. return 0;
  1901. }
  1902. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1903. Spawn* spawn = lua_interface->GetSpawn(state);
  1904. if (spawn) {
  1905. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1906. return 1;
  1907. }
  1908. return 0;
  1909. }
  1910. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1911. if (!lua_interface)
  1912. return 0;
  1913. Spawn* spawn = lua_interface->GetSpawn(state);
  1914. float value = lua_interface->GetFloatValue(state, 2);
  1915. lua_interface->ResetFunctionStack(state);
  1916. if (spawn) {
  1917. spawn->SetSpeed(value);
  1918. ((Entity*)spawn)->SetSpeed(value);
  1919. if (spawn->IsPlayer()) {
  1920. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1921. if (client) {
  1922. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1923. if (packet) {
  1924. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1925. packet->setDataByName("speed", value);
  1926. packet->setDataByName("size", 0.51);
  1927. EQ2Packet* app = packet->serialize();
  1928. client->QueuePacket(app);
  1929. safe_delete(packet);
  1930. }
  1931. }
  1932. }
  1933. }
  1934. return 0;
  1935. }
  1936. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1937. if (!lua_interface)
  1938. return 0;
  1939. Spawn* spawn = lua_interface->GetSpawn(state);
  1940. const int16 type = lua_interface->GetInt16Value(state, 2);
  1941. const float value = lua_interface->GetFloatValue(state, 3);
  1942. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1943. int64 class_req = 0;
  1944. int32 class_id = 0;
  1945. vector<int16> faction_req;
  1946. vector<int16> race_req;
  1947. int32 i = 0;
  1948. int8 f = 0;
  1949. int8 r = 0;
  1950. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1951. if (class_id < 100) {
  1952. class_req += pow(2.0, double(class_id - 1));
  1953. }
  1954. else if (class_id > 100 && class_id < 1000) {
  1955. race_req.push_back(class_id);
  1956. r++;
  1957. }
  1958. else {
  1959. faction_req.push_back(class_id);
  1960. f++;
  1961. }
  1962. i++;
  1963. }
  1964. if (value != 0 && type >= 0) {
  1965. if (luaspell && luaspell->spell && luaspell->caster) {
  1966. ZoneServer* zone = luaspell->caster->GetZone();
  1967. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1968. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1969. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1970. if (target) {
  1971. if (target->IsPlayer()) {
  1972. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1973. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1974. if (((Player*)target)->GetGroupMemberInfo())
  1975. ((Player*)target)->UpdateGroupMemberInfo();
  1976. ((Player*)target)->SetCharSheetChanged(true);
  1977. }
  1978. else if (target->IsNPC())
  1979. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1980. else
  1981. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1982. }
  1983. }
  1984. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1985. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1986. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1987. }
  1988. else if (spawn && spawn->IsEntity()) {
  1989. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1990. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1991. if (spawn->IsPlayer())
  1992. ((Player*)spawn)->SetCharSheetChanged(true);
  1993. }
  1994. else
  1995. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1996. }
  1997. else
  1998. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1999. return 0;
  2000. }
  2001. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2002. if (!lua_interface)
  2003. return 0;
  2004. Spawn* spawn = lua_interface->GetSpawn(state);
  2005. int16 type = lua_interface->GetInt16Value(state, 2);
  2006. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2007. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2008. if (!spawn) {
  2009. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2010. return 0;
  2011. }
  2012. if (!spawn->IsEntity()) {
  2013. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2014. return 0;
  2015. }
  2016. if (value == 0) {
  2017. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2018. return 0;
  2019. }
  2020. if (!luaspell || !luaspell->spell) {
  2021. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2022. return 0;
  2023. }
  2024. int32 class_req = 0;
  2025. vector<int16> faction_req;
  2026. vector<int16> race_req;
  2027. int32 class_id = 0;
  2028. int32 i = 0;
  2029. int8 f = 0;
  2030. int8 r = 0;
  2031. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2032. if (class_id < 100) {
  2033. class_req += pow(2.0, double(class_id - 1));
  2034. }
  2035. else if (class_id > 100 && class_id < 1000) {
  2036. race_req.push_back(class_id);
  2037. r++;
  2038. }
  2039. else {
  2040. faction_req.push_back(class_id);
  2041. f++;
  2042. }
  2043. i++;
  2044. }
  2045. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2046. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2047. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2048. if (spawn->IsPlayer())
  2049. ((Player*)spawn)->SetCharSheetChanged(true);
  2050. return 0;
  2051. }
  2052. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2053. if (!lua_interface)
  2054. return 0;
  2055. Spawn* spawn = lua_interface->GetSpawn(state);
  2056. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2057. if (!spawn) {
  2058. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2059. return 0;
  2060. }
  2061. if (!spawn->IsEntity()) {
  2062. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2063. return 0;
  2064. }
  2065. if (!luaspell || !luaspell->spell) {
  2066. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2067. return 0;
  2068. }
  2069. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2070. if (spawn->IsPlayer())
  2071. ((Player*)spawn)->SetCharSheetChanged(true);
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2079. if (luaspell && luaspell->spell) {
  2080. ZoneServer* zone = luaspell->caster->GetZone();
  2081. Spawn* target = 0;
  2082. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2083. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2084. target = zone->GetSpawnByID(luaspell->targets[i]);
  2085. if (target && target->IsEntity()) {
  2086. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2087. if (target->IsPlayer())
  2088. ((Player*)target)->SetCharSheetChanged(true);
  2089. }
  2090. }
  2091. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2092. }
  2093. else if (spawn && spawn->IsEntity()) {
  2094. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2095. if (spawn->IsPlayer())
  2096. ((Player*)spawn)->SetCharSheetChanged(true);
  2097. }
  2098. return 0;
  2099. }
  2100. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2101. if (!lua_interface)
  2102. return 0;
  2103. Spawn* spawn = lua_interface->GetSpawn(state);
  2104. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2105. float value = lua_interface->GetFloatValue(state, 3);
  2106. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2107. if (value != 0) {
  2108. int32 spell_id = 0;
  2109. if (luaspell && luaspell->spell && luaspell->caster) {
  2110. spell_id = luaspell->spell->GetSpellID();
  2111. ZoneServer* zone = luaspell->caster->GetZone();
  2112. Spawn* target = 0;
  2113. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2114. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2115. target = zone->GetSpawnByID(luaspell->targets[i]);
  2116. if (target && target->Alive()) {
  2117. if (target->IsPlayer()) {
  2118. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2119. Client* client = target->GetZone()->GetClientBySpawn(target);
  2120. if (client) {
  2121. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2122. if (packet)
  2123. client->QueuePacket(packet);
  2124. }
  2125. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2126. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2127. }
  2128. else if (target->IsNPC()) {
  2129. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2130. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2131. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2132. }
  2133. else
  2134. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2135. }
  2136. }
  2137. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2138. }
  2139. else if (spawn) {
  2140. if (spawn->IsPlayer()) {
  2141. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2142. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2143. if (client) {
  2144. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2145. if (packet)
  2146. client->QueuePacket(packet);
  2147. }
  2148. }
  2149. else if (spawn->IsNPC())
  2150. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2151. else
  2152. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2153. }
  2154. }
  2155. else
  2156. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2157. return 0;
  2158. }
  2159. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2160. if (!lua_interface)
  2161. return 0;
  2162. Spawn* spawn = lua_interface->GetSpawn(state);
  2163. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2164. if (spawn && spawn->IsPlayer()) {
  2165. int32 spell_id = 0;
  2166. if (luaspell && luaspell->spell) {
  2167. spell_id = luaspell->spell->GetSpellID();
  2168. ZoneServer* zone = luaspell->caster->GetZone();
  2169. Spawn* target = 0;
  2170. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2171. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2172. target = zone->GetSpawnByID(luaspell->targets[i]);
  2173. if (target) {
  2174. if (target->IsPlayer()) {
  2175. ((Player*)target)->RemoveSkillBonus(spell_id);
  2176. Client* client = target->GetZone()->GetClientBySpawn(target);
  2177. if (client) {
  2178. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2179. if (packet)
  2180. client->QueuePacket(packet);
  2181. }
  2182. }
  2183. else if (target->IsNPC())
  2184. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2185. else
  2186. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2187. }
  2188. }
  2189. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2190. }
  2191. else if (spawn) {
  2192. if (spawn->IsPlayer()) {
  2193. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2194. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2195. if (client) {
  2196. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2197. if (packet)
  2198. client->QueuePacket(packet);
  2199. }
  2200. }
  2201. else if (spawn->IsNPC())
  2202. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2203. else
  2204. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2205. }
  2206. }
  2207. return 0;
  2208. }
  2209. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2210. if (!lua_interface)
  2211. return 0;
  2212. Spawn* spawn = lua_interface->GetSpawn(state);
  2213. int8 type = lua_interface->GetInt32Value(state, 2);
  2214. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2215. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2216. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2217. ZoneServer* zone = luaspell->caster->GetZone();
  2218. Spawn* target = 0;
  2219. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2220. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2221. target = zone->GetSpawnByID(luaspell->targets[i]);
  2222. if (target && target->IsEntity()) {
  2223. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2224. ((Entity*)target)->AddMezSpell(luaspell);
  2225. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2226. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2227. if (target->IsNPC())
  2228. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2229. }
  2230. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2231. ((Entity*)target)->AddStifleSpell(luaspell);
  2232. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2233. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2234. if (target->IsNPC())
  2235. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2236. }
  2237. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2238. ((Entity*)target)->AddDazeSpell(luaspell);
  2239. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2240. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2241. if (target->IsNPC())
  2242. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2243. }
  2244. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2245. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2246. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2247. ((Entity*)target)->AddStunSpell(luaspell);
  2248. if (target->IsNPC())
  2249. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2250. }
  2251. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2252. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2253. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2254. ((Entity*)target)->AddRootSpell(luaspell);
  2255. if (target->IsNPC())
  2256. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2257. }
  2258. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2259. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2260. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2261. ((Entity*)target)->AddFearSpell(luaspell);
  2262. if (target->IsNPC())
  2263. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2264. }
  2265. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2266. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2267. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2268. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2269. }
  2270. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2271. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2272. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2273. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2274. }
  2275. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2276. ((Entity*)target)->AddSnareSpell(luaspell);
  2277. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2278. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2279. if (target->IsNPC())
  2280. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2281. }
  2282. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2283. ((Entity*)target)->AddFlightSpell(luaspell);
  2284. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2285. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2286. }
  2287. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2288. ((Entity*)target)->AddGlideSpell(luaspell);
  2289. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2290. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2291. }
  2292. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2293. ((Entity*)target)->AddSafefallSpell(luaspell);
  2294. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2295. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2296. }
  2297. else
  2298. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2299. }
  2300. else
  2301. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2302. }
  2303. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2304. }
  2305. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2306. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2307. ((Entity*)spawn)->AddMezSpell(luaspell);
  2308. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2309. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2310. }
  2311. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2312. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2313. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2314. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2315. }
  2316. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2317. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2318. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2319. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2320. }
  2321. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2322. ((Entity*)spawn)->AddStunSpell(luaspell);
  2323. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2324. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2325. }
  2326. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2327. ((Entity*)spawn)->AddRootSpell(luaspell);
  2328. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2329. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2330. }
  2331. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2332. ((Entity*)spawn)->AddFearSpell(luaspell);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2335. }
  2336. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2337. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2338. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2339. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2340. }
  2341. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2342. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2343. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2344. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2345. }
  2346. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2347. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2348. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2349. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2350. }
  2351. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2352. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2353. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2354. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2355. }
  2356. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2357. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2358. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2359. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2360. }
  2361. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2362. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2363. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2364. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2365. }
  2366. else
  2367. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2368. }
  2369. else
  2370. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2371. return 0;
  2372. }
  2373. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2374. if (!lua_interface)
  2375. return 0;
  2376. Spawn* spawn = lua_interface->GetSpawn(state);
  2377. int8 type = lua_interface->GetInt8Value(state, 2);
  2378. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2379. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2380. if (spawn && spawn->IsEntity()) {
  2381. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2382. ZoneServer* zone = luaspell->caster->GetZone();
  2383. Spawn* target = 0;
  2384. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2385. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2386. target = zone->GetSpawnByID(luaspell->targets[i]);
  2387. if (target) {
  2388. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2389. ((Entity*)target)->RemoveMezSpell(luaspell);
  2390. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2391. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2392. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2393. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2394. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2395. ((Entity*)target)->RemoveStunSpell(luaspell);
  2396. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2397. ((Entity*)target)->RemoveRootSpell(luaspell);
  2398. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2399. ((Entity*)target)->RemoveFearSpell(luaspell);
  2400. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2401. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2402. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2403. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2404. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2405. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2406. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2407. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2408. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2409. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2410. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2411. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2412. else
  2413. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2414. }
  2415. }
  2416. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2417. }
  2418. else if (only_remove_spawn) {
  2419. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2420. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2421. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2422. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2423. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2424. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2425. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2426. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2427. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2428. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2429. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2430. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2431. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2432. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2433. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2434. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2435. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2436. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2437. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2438. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2440. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2442. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2443. else
  2444. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2445. }
  2446. }
  2447. return 0;
  2448. }
  2449. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2450. if (!lua_interface)
  2451. return 0;
  2452. Spawn* spawn = lua_interface->GetSpawn(state);
  2453. int8 type = lua_interface->GetInt8Value(state, 2);
  2454. bool hasEffect = false;
  2455. if (!spawn)
  2456. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2457. else if (!spawn->IsEntity())
  2458. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2459. else if (type < CONTROL_MAX_EFFECTS)
  2460. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2461. else
  2462. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2463. lua_interface->SetBooleanValue(state, hasEffect);
  2464. return 1;
  2465. }
  2466. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2467. if (!lua_interface)
  2468. return 0;
  2469. Spawn* spawn = lua_interface->GetSpawn(state);
  2470. float distance = 0.0f;
  2471. if (!spawn)
  2472. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2473. else if (!spawn->IsNPC())
  2474. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2475. else
  2476. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2477. lua_interface->SetFloatValue(state, distance);
  2478. return 1;
  2479. }
  2480. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2481. if (!lua_interface)
  2482. return 0;
  2483. Spawn* spawn = lua_interface->GetSpawn(state);
  2484. float distance = 0.0f;
  2485. if (!spawn)
  2486. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2487. else if (!spawn->IsNPC())
  2488. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2489. else
  2490. distance = ((NPC*)spawn)->GetAggroRadius();
  2491. lua_interface->SetFloatValue(state, distance);
  2492. return 1;
  2493. }
  2494. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2495. if (!lua_interface)
  2496. return 0;
  2497. Spawn* spawn = lua_interface->GetSpawn(state);
  2498. float distance = lua_interface->GetFloatValue(state, 2);
  2499. bool override = lua_interface->GetBooleanValue(state, 3);
  2500. bool result = false;
  2501. lua_interface->ResetFunctionStack(state);
  2502. if (!spawn)
  2503. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2504. else if (!spawn->IsNPC())
  2505. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2506. else
  2507. {
  2508. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2509. result = true;
  2510. }
  2511. lua_interface->SetBooleanValue(state, result);
  2512. return 1;
  2513. }
  2514. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int16 value = lua_interface->GetInt16Value(state, 2);
  2519. if (spawn && spawn->IsEntity()) {
  2520. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2521. if (spawn->IsPlayer())
  2522. ((Player*)spawn)->SetCharSheetChanged(true);
  2523. }
  2524. return 0;
  2525. }
  2526. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2527. if (!lua_interface)
  2528. return 0;
  2529. Spawn* spawn = lua_interface->GetSpawn(state);
  2530. int16 value = lua_interface->GetInt16Value(state, 2);
  2531. if (spawn && spawn->IsEntity()) {
  2532. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2533. if (spawn->IsPlayer())
  2534. ((Player*)spawn)->SetCharSheetChanged(true);
  2535. }
  2536. return 0;
  2537. }
  2538. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2539. if (!lua_interface)
  2540. return 0;
  2541. Spawn* spawn = lua_interface->GetSpawn(state);
  2542. int16 value = lua_interface->GetInt16Value(state, 2);
  2543. if (spawn && spawn->IsEntity()) {
  2544. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2545. if (spawn->IsPlayer())
  2546. ((Player*)spawn)->SetCharSheetChanged(true);
  2547. }
  2548. return 0;
  2549. }
  2550. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2551. if (!lua_interface)
  2552. return 0;
  2553. Spawn* spawn = lua_interface->GetSpawn(state);
  2554. int16 value = lua_interface->GetInt16Value(state, 2);
  2555. if (spawn && spawn->IsEntity()) {
  2556. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2557. if (spawn->IsPlayer())
  2558. ((Player*)spawn)->SetCharSheetChanged(true);
  2559. }
  2560. return 0;
  2561. }
  2562. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2563. if (!lua_interface)
  2564. return 0;
  2565. Spawn* spawn = lua_interface->GetSpawn(state);
  2566. int16 value = lua_interface->GetInt16Value(state, 2);
  2567. if (spawn && spawn->IsEntity()) {
  2568. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2569. if (spawn->IsPlayer())
  2570. ((Player*)spawn)->SetCharSheetChanged(true);
  2571. }
  2572. return 0;
  2573. }
  2574. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2575. if (!lua_interface)
  2576. return 0;
  2577. Spawn* spawn = lua_interface->GetSpawn(state);
  2578. int8 value = lua_interface->GetInt8Value(state, 2);
  2579. if (spawn && spawn->IsEntity()) {
  2580. ((Entity*)spawn)->SetDeity(value);
  2581. if (spawn->IsPlayer())
  2582. ((Player*)spawn)->SetCharSheetChanged(true);
  2583. }
  2584. lua_interface->ResetFunctionStack(state);
  2585. return 0;
  2586. }
  2587. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2588. if (!lua_interface)
  2589. return 0;
  2590. Spawn* spawn = lua_interface->GetSpawn(state);
  2591. if (spawn && spawn->IsEntity()) {
  2592. int8 deity = ((Entity*)spawn)->GetDeity();
  2593. lua_interface->SetInt32Value(state, deity);
  2594. return 1;
  2595. }
  2596. return 0;
  2597. }
  2598. int EQ2Emu_lua_SetInt(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2603. if (spawn && spawn->IsEntity()) {
  2604. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2605. if (spawn->IsPlayer())
  2606. ((Player*)spawn)->SetCharSheetChanged(true);
  2607. }
  2608. return 0;
  2609. }
  2610. int EQ2Emu_lua_SetWis(lua_State* state) {
  2611. if (!lua_interface)
  2612. return 0;
  2613. Spawn* spawn = lua_interface->GetSpawn(state);
  2614. float value = lua_interface->GetFloatValue(state, 2);
  2615. if (spawn && spawn->IsEntity()) {
  2616. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2617. if (spawn->IsPlayer())
  2618. ((Player*)spawn)->SetCharSheetChanged(true);
  2619. }
  2620. return 0;
  2621. }
  2622. int EQ2Emu_lua_SetSta(lua_State* state) {
  2623. if (!lua_interface)
  2624. return 0;
  2625. Spawn* spawn = lua_interface->GetSpawn(state);
  2626. float value = lua_interface->GetFloatValue(state, 2);
  2627. if (spawn && spawn->IsEntity()) {
  2628. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2629. if (spawn->IsPlayer())
  2630. ((Player*)spawn)->SetCharSheetChanged(true);
  2631. }
  2632. return 0;
  2633. }
  2634. int EQ2Emu_lua_SetStr(lua_State* state) {
  2635. if (!lua_interface)
  2636. return 0;
  2637. Spawn* spawn = lua_interface->GetSpawn(state);
  2638. float value = lua_interface->GetFloatValue(state, 2);
  2639. if (spawn && spawn->IsEntity()) {
  2640. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2641. if (spawn->IsPlayer())
  2642. ((Player*)spawn)->SetCharSheetChanged(true);
  2643. }
  2644. return 0;
  2645. }
  2646. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2647. if (!lua_interface)
  2648. return 0;
  2649. Spawn* spawn = lua_interface->GetSpawn(state);
  2650. float value = lua_interface->GetFloatValue(state, 2);
  2651. if (spawn && spawn->IsEntity()) {
  2652. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2653. if (spawn->IsPlayer())
  2654. ((Player*)spawn)->SetCharSheetChanged(true);
  2655. }
  2656. return 0;
  2657. }
  2658. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2659. if (!lua_interface)
  2660. return 0;
  2661. Spawn* spawn = lua_interface->GetSpawn(state);
  2662. if (spawn) {
  2663. lua_interface->SetInt32Value(state, spawn->GetHP());
  2664. return 1;
  2665. }
  2666. return 0;
  2667. }
  2668. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. if (spawn) {
  2673. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2674. return 1;
  2675. }
  2676. return 0;
  2677. }
  2678. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2679. if (!lua_interface)
  2680. return 0;
  2681. Spawn* spawn = lua_interface->GetSpawn(state);
  2682. if (spawn) {
  2683. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2684. return 1;
  2685. }
  2686. return 0;
  2687. }
  2688. int EQ2Emu_lua_GetName(lua_State* state) {
  2689. if (!lua_interface)
  2690. return 0;
  2691. Spawn* spawn = lua_interface->GetSpawn(state);
  2692. if (spawn) {
  2693. lua_interface->SetStringValue(state, spawn->GetName());
  2694. return 1;
  2695. }
  2696. return 0;
  2697. }
  2698. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2699. Spawn* spawn = lua_interface->GetSpawn(state);
  2700. if (spawn) {
  2701. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2702. return 1;
  2703. }
  2704. return 0;
  2705. }
  2706. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2707. if (!lua_interface)
  2708. return 0;
  2709. Spawn* spawn = lua_interface->GetSpawn(state);
  2710. if (spawn) {
  2711. lua_interface->SetInt32Value(state, spawn->GetPower());
  2712. return 1;
  2713. }
  2714. return 0;
  2715. }
  2716. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2717. if (!lua_interface)
  2718. return 0;
  2719. Spawn* spawn = lua_interface->GetSpawn(state);
  2720. if (spawn) {
  2721. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2722. return 1;
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. if (spawn) {
  2731. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2732. return 1;
  2733. }
  2734. return 0;
  2735. }
  2736. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2737. if (!lua_interface)
  2738. return 0;
  2739. Spawn* spawn = lua_interface->GetSpawn(state);
  2740. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2741. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2742. if (spawn && spawn2) {
  2743. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2744. lua_interface->SetFloatValue(state, distance);
  2745. return 1;
  2746. }
  2747. return 0;
  2748. }
  2749. int EQ2Emu_lua_GetX(lua_State* state) {
  2750. if (!lua_interface)
  2751. return 0;
  2752. Spawn* spawn = lua_interface->GetSpawn(state);
  2753. if (spawn) {
  2754. lua_interface->SetFloatValue(state, spawn->GetX());
  2755. return 1;
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_GetY(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* spawn = lua_interface->GetSpawn(state);
  2763. if (spawn) {
  2764. lua_interface->SetFloatValue(state, spawn->GetY());
  2765. return 1;
  2766. }
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_GetZ(lua_State* state) {
  2770. if (!lua_interface)
  2771. return 0;
  2772. Spawn* spawn = lua_interface->GetSpawn(state);
  2773. if (spawn) {
  2774. lua_interface->SetFloatValue(state, spawn->GetZ());
  2775. return 1;
  2776. }
  2777. return 0;
  2778. }
  2779. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2780. if (!lua_interface)
  2781. return 0;
  2782. Spawn* spawn = lua_interface->GetSpawn(state);
  2783. if (spawn) {
  2784. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2785. return 1;
  2786. }
  2787. return 0;
  2788. }
  2789. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Spawn* spawn = lua_interface->GetSpawn(state);
  2793. if (spawn) {
  2794. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2795. return 1;
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. if (spawn) {
  2804. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2805. return 1;
  2806. }
  2807. return 0;
  2808. }
  2809. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2810. if (!lua_interface)
  2811. return 0;
  2812. Spawn* spawn = lua_interface->GetSpawn(state);
  2813. if (spawn && spawn->IsEntity()) {
  2814. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2815. return 1;
  2816. }
  2817. return 0;
  2818. }
  2819. int EQ2Emu_lua_GetInt(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Spawn* spawn = lua_interface->GetSpawn(state);
  2823. if (spawn && spawn->IsEntity()) {
  2824. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2825. return 1;
  2826. }
  2827. return 0;
  2828. }
  2829. int EQ2Emu_lua_GetWis(lua_State* state) {
  2830. if (!lua_interface)
  2831. return 0;
  2832. Spawn* spawn = lua_interface->GetSpawn(state);
  2833. if (spawn && spawn->IsEntity()) {
  2834. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2835. return 1;
  2836. }
  2837. return 0;
  2838. }
  2839. int EQ2Emu_lua_GetSta(lua_State* state) {
  2840. if (!lua_interface)
  2841. return 0;
  2842. Spawn* spawn = lua_interface->GetSpawn(state);
  2843. if (spawn && spawn->IsEntity()) {
  2844. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_GetStr(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn && spawn->IsEntity()) {
  2854. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn && spawn->IsEntity()) {
  2864. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn && spawn->IsEntity()) {
  2874. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2880. if (!lua_interface)
  2881. return 0;
  2882. Spawn* spawn = lua_interface->GetSpawn(state);
  2883. if (spawn && spawn->IsEntity()) {
  2884. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2885. return 1;
  2886. }
  2887. return 0;
  2888. }
  2889. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2890. if (!lua_interface)
  2891. return 0;
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. if (spawn && spawn->IsEntity()) {
  2894. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2895. return 1;
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2900. if (!lua_interface)
  2901. return 0;
  2902. Spawn* spawn = lua_interface->GetSpawn(state);
  2903. if (spawn && spawn->IsEntity()) {
  2904. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2905. return 1;
  2906. }
  2907. return 0;
  2908. }
  2909. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2910. if (!lua_interface)
  2911. return 0;
  2912. Spawn* spawn = lua_interface->GetSpawn(state);
  2913. if (spawn && spawn->IsEntity()) {
  2914. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2915. return 1;
  2916. }
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. Spawn* player = lua_interface->GetSpawn(state);
  2923. if (!player || !player->IsPlayer()) {
  2924. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2925. return 0;
  2926. }
  2927. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2928. if (quest_id <= 0) {
  2929. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2930. return 0;
  2931. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2932. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2933. return 0;
  2934. }
  2935. int32 step = lua_interface->GetInt32Value(state, 3);
  2936. if (step > 0) {
  2937. Client* client = player->GetZone()->GetClientBySpawn(player);
  2938. if (client)
  2939. client->AddPendingQuestUpdate(quest_id, step);
  2940. } else {
  2941. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2942. }
  2943. return 0;
  2944. }
  2945. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2946. Spawn* player = lua_interface->GetSpawn(state);
  2947. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2948. int32 step = lua_interface->GetInt32Value(state, 3);
  2949. int32 progress = lua_interface->GetInt32Value(state, 4);
  2950. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2951. Client* client = player->GetZone()->GetClientBySpawn(player);
  2952. if (client)
  2953. client->AddPendingQuestUpdate(quest_id, step, progress);
  2954. }
  2955. return 0;
  2956. }
  2957. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2958. if (!lua_interface)
  2959. return 0;
  2960. Spawn* player = lua_interface->GetSpawn(state);
  2961. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2962. if (player && player->IsPlayer() && quest_id > 0) {
  2963. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2964. return 1;
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Spawn* player = lua_interface->GetSpawn(state);
  2972. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2973. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2974. if (player && player->IsPlayer() && quest_id > 0) {
  2975. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2976. return 1;
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* player = lua_interface->GetSpawn(state);
  2984. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2985. if (player && player->IsPlayer() && quest_id > 0) {
  2986. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2987. return 1;
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Quest* quest = lua_interface->GetQuest(state);
  2995. string name = lua_interface->GetStringValue(state, 2);
  2996. string type = lua_interface->GetStringValue(state, 3);
  2997. string zone = lua_interface->GetStringValue(state, 4);
  2998. int16 level = lua_interface->GetInt16Value(state, 5);
  2999. string description = lua_interface->GetStringValue(state, 6);
  3000. bool load = true;
  3001. if (!quest) {
  3002. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3003. load = false;
  3004. }
  3005. if (load && name.length() == 0) {
  3006. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3007. load = false;
  3008. }
  3009. if (load && type.length() == 0) {
  3010. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3011. load = false;
  3012. }
  3013. if (load && zone.length() == 0) {
  3014. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3015. load = false;
  3016. }
  3017. if (load && description.length() == 0) {
  3018. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3019. load = false;
  3020. }
  3021. if (load && level == 0) {
  3022. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3023. load = false;
  3024. }
  3025. if (load)
  3026. quest->RegisterQuest(name, type, zone, level, description);
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Quest* quest = lua_interface->GetQuest(state);
  3033. if (quest) {
  3034. int8 level = lua_interface->GetInt16Value(state, 2);
  3035. quest->SetPrereqLevel(level);
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3040. if (!lua_interface)
  3041. return 0;
  3042. Quest* quest = lua_interface->GetQuest(state);
  3043. if (quest) {
  3044. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3045. quest->AddPrereqQuest(quest_id);
  3046. }
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3050. if (!lua_interface)
  3051. return 0;
  3052. Quest* quest = lua_interface->GetQuest(state);
  3053. if (quest) {
  3054. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3055. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3056. if (quantity == 0)
  3057. quantity = 1;
  3058. Item* master_item = master_item_list.GetItem(item_id);
  3059. if (master_item) {
  3060. Item* item = new Item(master_item);
  3061. item->details.count = quantity;
  3062. quest->AddPrereqItem(item);
  3063. }
  3064. }
  3065. return 0;
  3066. }
  3067. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3068. if (!lua_interface)
  3069. return 0;
  3070. Spawn* player = lua_interface->GetSpawn(state);
  3071. if(!player || !player->IsPlayer()) {
  3072. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3073. return 0;
  3074. }
  3075. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3076. if (quest_id > 0) {
  3077. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3078. return 1;
  3079. } else {
  3080. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3081. }
  3082. return 0;
  3083. }
  3084. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3085. if (!lua_interface)
  3086. return 0;
  3087. Quest* quest = lua_interface->GetQuest(state);
  3088. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3089. if (quest && spawn_id > 0)
  3090. quest->SetQuestReturnNPC(spawn_id);
  3091. return 0;
  3092. }
  3093. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3094. if (!lua_interface)
  3095. return 0;
  3096. Spawn* spawn = lua_interface->GetSpawn(state);
  3097. if (!spawn) {
  3098. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3099. return 0;
  3100. }
  3101. int32 time = lua_interface->GetInt32Value(state, 2);
  3102. if (time <= 0) {
  3103. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3104. return 0;
  3105. }
  3106. string function = lua_interface->GetStringValue(state, 3);
  3107. if (function.length() == 0) {
  3108. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3109. return 0;
  3110. }
  3111. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3112. Spawn* player = lua_interface->GetSpawn(state, 5);
  3113. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3114. timer->timer = Timer::GetCurrentTime2() + time;
  3115. timer->function = function;
  3116. timer->spawn = spawn->GetID();
  3117. timer->player = player ? player->GetID() : 0;
  3118. if (max_count == 0)
  3119. max_count = 1;
  3120. timer->max_count = max_count;
  3121. timer->current_count = 0;
  3122. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3123. return 0;
  3124. }
  3125. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3126. if (!lua_interface)
  3127. return 0;
  3128. Spawn* player = lua_interface->GetSpawn(state);
  3129. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3130. if (player && player->IsPlayer() && quest_id > 0) {
  3131. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3132. return 1;
  3133. }
  3134. return 0;
  3135. }
  3136. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3137. if (!lua_interface)
  3138. return 0;
  3139. Spawn* player = lua_interface->GetSpawn(state);
  3140. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3141. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3142. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3143. if (quest)
  3144. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3145. return 1;
  3146. }
  3147. return 0;
  3148. }
  3149. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3150. if (!lua_interface)
  3151. return 0;
  3152. Spawn* player = lua_interface->GetSpawn(state);
  3153. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3154. if (player && player->IsPlayer() && quest_id > 0) {
  3155. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3156. return 1;
  3157. }
  3158. return 0;
  3159. }
  3160. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3161. if (!lua_interface)
  3162. return 0;
  3163. Spawn* npc = lua_interface->GetSpawn(state);
  3164. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3165. if (npc && !npc->IsPlayer() && quest_id > 0)
  3166. npc->AddProvidedQuest(quest_id);
  3167. return 0;
  3168. }
  3169. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3170. if (!lua_interface)
  3171. return 0;
  3172. Spawn* npc = lua_interface->GetSpawn(state);
  3173. Spawn* player = lua_interface->GetSpawn(state, 2);
  3174. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3175. bool forced = lua_interface->GetBooleanValue(state, 4);
  3176. /* NPC is allowed to be null */
  3177. if (player && player->IsPlayer() && quest_id > 0) {
  3178. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3179. if (master_quest) {
  3180. Client* client = player->GetZone()->GetClientBySpawn(player);
  3181. if (!client) {
  3182. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3183. }
  3184. Quest* quest = new Quest(master_quest);
  3185. if (!quest) {
  3186. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3187. }
  3188. if (client && quest) {
  3189. if (npc)
  3190. quest->SetQuestGiver(npc->GetDatabaseID());
  3191. else
  3192. quest->SetQuestGiver(0);
  3193. client->AddPendingQuest(quest, forced);
  3194. }
  3195. }
  3196. else {
  3197. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3198. }
  3199. }
  3200. else {
  3201. 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);
  3202. }
  3203. return 0;
  3204. }
  3205. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3206. if (!lua_interface)
  3207. return 0;
  3208. Quest* quest = lua_interface->GetQuest(state);
  3209. if (quest) {
  3210. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3211. quest->AddPrereqClass(class_id);
  3212. }
  3213. return 0;
  3214. }
  3215. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3216. if (!lua_interface)
  3217. return 0;
  3218. Quest* quest = lua_interface->GetQuest(state);
  3219. if (quest) {
  3220. int8 race = lua_interface->GetInt8Value(state, 2);
  3221. quest->AddPrereqRace(race);
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Quest* quest = lua_interface->GetQuest(state);
  3229. if (quest) {
  3230. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3231. quest->AddPrereqModelType(model_type);
  3232. }
  3233. return 0;
  3234. }
  3235. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3236. if (!lua_interface)
  3237. return 0;
  3238. Quest* quest = lua_interface->GetQuest(state);
  3239. if (!quest) {
  3240. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3241. return 0;
  3242. }
  3243. int8 level = lua_interface->GetInt8Value(state, 2);
  3244. quest->SetPrereqTSLevel(level);
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Quest* quest = lua_interface->GetQuest(state);
  3251. if (!quest) {
  3252. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3253. return 0;
  3254. }
  3255. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3256. quest->AddPrereqTradeskillClass(class_id);
  3257. return 0;
  3258. }
  3259. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3260. if (!lua_interface)
  3261. return 0;
  3262. Quest* quest = lua_interface->GetQuest(state);
  3263. if (quest) {
  3264. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3265. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3266. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3267. quest->AddPrereqFaction(faction_id, min, max);
  3268. }
  3269. return 0;
  3270. }
  3271. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3272. if (!lua_interface)
  3273. return 0;
  3274. Quest* quest = lua_interface->GetQuest(state);
  3275. if (quest) {
  3276. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3277. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3278. if (quantity == 0)
  3279. quantity = 1;
  3280. Item* master_item = master_item_list.GetItem(item_id);
  3281. if (master_item) {
  3282. Item* item = new Item(master_item);
  3283. item->details.count = quantity;
  3284. quest->AddSelectableRewardItem(item);
  3285. }
  3286. }
  3287. return 0;
  3288. }
  3289. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3290. if (!lua_interface)
  3291. return 0;
  3292. Quest* quest = lua_interface->GetQuest(state);
  3293. if (quest) {
  3294. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3295. vector<Item*>* items = quest->GetRewardItems();
  3296. if (items) {
  3297. vector<Item*>::iterator itr;
  3298. for (itr = items->begin(); itr != items->end(); itr++) {
  3299. if (*itr && (*itr)->details.item_id == item_id) {
  3300. lua_interface->SetBooleanValue(state, true);
  3301. return 1;
  3302. }
  3303. }
  3304. }
  3305. }
  3306. lua_interface->SetBooleanValue(state, false);
  3307. return 1;
  3308. }
  3309. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3310. if (!lua_interface)
  3311. return 0;
  3312. Quest* quest = lua_interface->GetQuest(state);
  3313. if (quest) {
  3314. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3315. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3316. if (quantity == 0)
  3317. quantity = 1;
  3318. Item* master_item = master_item_list.GetItem(item_id);
  3319. if (master_item) {
  3320. Item* item = new Item(master_item);
  3321. item->details.count = quantity;
  3322. quest->AddRewardItem(item);
  3323. }
  3324. }
  3325. return 0;
  3326. }
  3327. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3328. if (!lua_interface)
  3329. return 0;
  3330. Quest* quest = lua_interface->GetQuest(state);
  3331. if (quest) {
  3332. int32 copper = lua_interface->GetInt32Value(state, 2);
  3333. int32 silver = lua_interface->GetInt32Value(state, 3);
  3334. int32 gold = lua_interface->GetInt32Value(state, 4);
  3335. int32 plat = lua_interface->GetInt32Value(state, 5);
  3336. quest->AddRewardCoins(copper, silver, gold, plat);
  3337. }
  3338. return 0;
  3339. }
  3340. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3341. if (!lua_interface)
  3342. return 0;
  3343. Quest* quest = lua_interface->GetQuest(state);
  3344. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3345. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3346. if (quest && faction_id > 0 && amount != 0)
  3347. quest->AddRewardFaction(faction_id, amount);
  3348. return 0;
  3349. }
  3350. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3351. if (!lua_interface)
  3352. return 0;
  3353. Quest* quest = lua_interface->GetQuest(state);
  3354. if (quest) {
  3355. int32 status = lua_interface->GetInt32Value(state, 2);
  3356. quest->SetRewardStatus(status);
  3357. }
  3358. return 0;
  3359. }
  3360. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Quest* quest = lua_interface->GetQuest(state);
  3364. if (quest) {
  3365. int32 status = lua_interface->GetInt32Value(state, 2);
  3366. quest->SetStatusTmpReward(status);
  3367. }
  3368. return 0;
  3369. }
  3370. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3371. if (!lua_interface)
  3372. return 0;
  3373. Quest* quest = lua_interface->GetQuest(state);
  3374. if (quest) {
  3375. int64 coins = lua_interface->GetInt64Value(state, 2);
  3376. quest->SetCoinTmpReward(coins);
  3377. }
  3378. return 0;
  3379. }
  3380. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3381. if (!lua_interface)
  3382. return 0;
  3383. Quest* quest = lua_interface->GetQuest(state);
  3384. if (quest) {
  3385. string comment = lua_interface->GetStringValue(state, 2);
  3386. quest->SetRewardComment(comment);
  3387. }
  3388. return 0;
  3389. }
  3390. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3391. if (!lua_interface)
  3392. return 0;
  3393. Quest* quest = lua_interface->GetQuest(state);
  3394. if (quest) {
  3395. int32 exp = lua_interface->GetInt32Value(state, 2);
  3396. quest->SetRewardXP(exp);
  3397. }
  3398. return 0;
  3399. }
  3400. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3401. Quest* quest = lua_interface->GetQuest(state);
  3402. if (quest) {
  3403. int32 step = lua_interface->GetInt32Value(state, 2);
  3404. string description = lua_interface->GetStringValue(state, 3);
  3405. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3406. float percentage = lua_interface->GetFloatValue(state, 5);
  3407. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3408. int16 icon = lua_interface->GetInt16Value(state, 7);
  3409. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3410. const char* taskgroup = 0;
  3411. if (str_taskgroup.length() > 0)
  3412. taskgroup = str_taskgroup.c_str();
  3413. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3414. if (quest_step && icon && quantity > 0)
  3415. quest_step->SetIcon(icon);
  3416. }
  3417. return 0;
  3418. }
  3419. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3420. if (!lua_interface)
  3421. return 0;
  3422. Quest* quest = lua_interface->GetQuest(state);
  3423. if (quest) {
  3424. int32 step = lua_interface->GetInt32Value(state, 2);
  3425. string description = lua_interface->GetStringValue(state, 3);
  3426. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3427. float percentage = lua_interface->GetFloatValue(state, 5);
  3428. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3429. int16 icon = lua_interface->GetInt16Value(state, 7);
  3430. const char* taskgroup = 0;
  3431. if (str_taskgroup.length() > 0)
  3432. taskgroup = str_taskgroup.c_str();
  3433. int32 npc_id = 0;
  3434. vector<int32>* ids = 0;
  3435. int i = 0;
  3436. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3437. if (ids == 0)
  3438. ids = new vector<int32>;
  3439. ids->push_back(npc_id);
  3440. i++;
  3441. }
  3442. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3443. if (quest_step && icon > 0 && quantity > 0)
  3444. quest_step->SetIcon(icon);
  3445. if (quest->GetPlayer()) {
  3446. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3447. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3448. }
  3449. }
  3450. return 0;
  3451. }
  3452. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3453. if (!lua_interface)
  3454. return 0;
  3455. Quest* quest = lua_interface->GetQuest(state);
  3456. if (quest) {
  3457. int32 step = lua_interface->GetInt32Value(state, 2);
  3458. string description = lua_interface->GetStringValue(state, 3);
  3459. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3460. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3461. int16 icon = lua_interface->GetInt16Value(state, 6);
  3462. const char* taskgroup = 0;
  3463. if (str_taskgroup.length() > 0)
  3464. taskgroup = str_taskgroup.c_str();
  3465. int32 npc_id = 0;
  3466. vector<int32>* ids = 0;
  3467. int i = 0;
  3468. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3469. if (ids == 0)
  3470. ids = new vector<int32>;
  3471. ids->push_back(npc_id);
  3472. i++;
  3473. }
  3474. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3475. if (quest_step && icon > 0)
  3476. quest_step->SetIcon(icon);
  3477. if (quest->GetPlayer()) {
  3478. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3479. if(client)
  3480. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3481. }
  3482. }
  3483. return 0;
  3484. }
  3485. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3486. if (!lua_interface)
  3487. return 0;
  3488. Quest* quest = lua_interface->GetQuest(state);
  3489. if (quest) {
  3490. int32 step = lua_interface->GetInt32Value(state, 2);
  3491. string description = lua_interface->GetStringValue(state, 3);
  3492. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3493. float percentage = lua_interface->GetFloatValue(state, 5);
  3494. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3495. int16 icon = lua_interface->GetInt16Value(state, 7);
  3496. const char* taskgroup = 0;
  3497. if (str_taskgroup.length() > 0)
  3498. taskgroup = str_taskgroup.c_str();
  3499. int32 item_id = 0;
  3500. vector<int32>* ids = 0;
  3501. int i = 0;
  3502. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3503. if (ids == 0)
  3504. ids = new vector<int32>;
  3505. ids->push_back(item_id);
  3506. i++;
  3507. }
  3508. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3509. if (quest_step && icon > 0 && quantity > 0)
  3510. quest_step->SetIcon(icon);
  3511. if (quest->GetPlayer()) {
  3512. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3513. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3514. }
  3515. }
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. if (quest) {
  3523. int32 step = lua_interface->GetInt32Value(state, 2);
  3524. string description = lua_interface->GetStringValue(state, 3);
  3525. float max_variation = lua_interface->GetFloatValue(state, 4);
  3526. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3527. int16 icon = lua_interface->GetInt16Value(state, 6);
  3528. const char* taskgroup = 0;
  3529. if (str_taskgroup.length() > 0)
  3530. taskgroup = str_taskgroup.c_str();
  3531. vector<Location>* locations = 0;
  3532. int i = 7;
  3533. while (true) {
  3534. Location loc;
  3535. loc.x = lua_interface->GetFloatValue(state, i);
  3536. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3537. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3538. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3539. break;
  3540. if (locations == 0)
  3541. locations = new vector<Location>;
  3542. locations->push_back(loc);
  3543. i += 3;
  3544. }
  3545. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3546. if (quest_step && icon > 0)
  3547. quest_step->SetIcon(icon);
  3548. if (quest->GetPlayer()) {
  3549. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3550. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3551. }
  3552. }
  3553. return 0;
  3554. }
  3555. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3556. if (!lua_interface)
  3557. return 0;
  3558. Quest* quest = lua_interface->GetQuest(state);
  3559. if (quest) {
  3560. int32 step = lua_interface->GetInt32Value(state, 2);
  3561. string description = lua_interface->GetStringValue(state, 3);
  3562. float max_variation = lua_interface->GetFloatValue(state, 4);
  3563. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3564. int16 icon = lua_interface->GetInt16Value(state, 6);
  3565. const char* taskgroup = 0;
  3566. if (str_taskgroup.length() > 0)
  3567. taskgroup = str_taskgroup.c_str();
  3568. vector<Location>* locations = 0;
  3569. int i = 7;
  3570. while (true) {
  3571. Location loc;
  3572. loc.x = lua_interface->GetFloatValue(state, i);
  3573. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3574. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3575. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3576. break;
  3577. if (locations == 0)
  3578. locations = new vector<Location>;
  3579. locations->push_back(loc);
  3580. i += 3;
  3581. }
  3582. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3583. if (quest_step && icon > 0)
  3584. quest_step->SetIcon(icon);
  3585. if (quest->GetPlayer()) {
  3586. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3587. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3588. }
  3589. }
  3590. return 0;
  3591. }
  3592. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3593. Quest* quest = lua_interface->GetQuest(state);
  3594. if (quest) {
  3595. int32 step = lua_interface->GetInt32Value(state, 2);
  3596. string description = lua_interface->GetStringValue(state, 3);
  3597. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3598. float percentage = lua_interface->GetFloatValue(state, 5);
  3599. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3600. int16 icon = lua_interface->GetInt16Value(state, 7);
  3601. const char* taskgroup = 0;
  3602. if (str_taskgroup.length() > 0)
  3603. taskgroup = str_taskgroup.c_str();
  3604. int32 spell_id = 0;
  3605. vector<int32>* ids = 0;
  3606. int i = 0;
  3607. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3608. if (ids == 0)
  3609. ids = new vector<int32>;
  3610. ids->push_back(spell_id);
  3611. i++;
  3612. }
  3613. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3614. if (quest_step && icon > 0 && quantity > 0)
  3615. quest_step->SetIcon(icon);
  3616. if (quest->GetPlayer()) {
  3617. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3618. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3619. }
  3620. }
  3621. return 0;
  3622. }
  3623. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3624. if (!lua_interface)
  3625. return 0;
  3626. Quest* quest = lua_interface->GetQuest(state);
  3627. if (quest) {
  3628. int32 step = lua_interface->GetInt32Value(state, 2);
  3629. string description = lua_interface->GetStringValue(state, 3);
  3630. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3631. float percentage = lua_interface->GetFloatValue(state, 5);
  3632. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3633. int16 icon = lua_interface->GetInt16Value(state, 7);
  3634. const char* taskgroup = 0;
  3635. if (str_taskgroup.length() > 0)
  3636. taskgroup = str_taskgroup.c_str();
  3637. int32 item_id = 0;
  3638. vector<int32>* ids = 0;
  3639. int i = 0;
  3640. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3641. if (ids == 0)
  3642. ids = new vector<int32>;
  3643. ids->push_back(item_id);
  3644. i++;
  3645. }
  3646. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3647. if (quest_step && icon > 0 && quantity > 0)
  3648. quest_step->SetIcon(icon);
  3649. if (quest->GetPlayer()) {
  3650. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3651. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3652. }
  3653. }
  3654. return 0;
  3655. }
  3656. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3657. if (!lua_interface)
  3658. return 0;
  3659. Quest* quest = lua_interface->GetQuest(state);
  3660. if (quest) {
  3661. int32 step = lua_interface->GetInt32Value(state, 2);
  3662. string description = lua_interface->GetStringValue(state, 3);
  3663. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3664. float percentage = lua_interface->GetFloatValue(state, 5);
  3665. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3666. int16 icon = lua_interface->GetInt16Value(state, 7);
  3667. const char* taskgroup = 0;
  3668. if (str_taskgroup.length() > 0)
  3669. taskgroup = str_taskgroup.c_str();
  3670. int32 item_id = 0;
  3671. vector<int32>* ids = 0;
  3672. int i = 0;
  3673. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3674. if (ids == 0)
  3675. ids = new vector<int32>;
  3676. ids->push_back(item_id);
  3677. i++;
  3678. }
  3679. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3680. if (quest_step && icon > 0 && quantity > 0)
  3681. quest_step->SetIcon(icon);
  3682. if (quest->GetPlayer()) {
  3683. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3684. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3685. }
  3686. }
  3687. return 0;
  3688. }
  3689. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3690. if (!lua_interface)
  3691. return 0;
  3692. Quest* quest = lua_interface->GetQuest(state);
  3693. if (quest) {
  3694. string action = lua_interface->GetStringValue(state, 2);
  3695. if (action.length() > 0)
  3696. quest->SetCompleteAction(action);
  3697. }
  3698. return 0;
  3699. }
  3700. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3701. if (!lua_interface)
  3702. return 0;
  3703. Quest* quest = lua_interface->GetQuest(state);
  3704. if (quest) {
  3705. int32 step = lua_interface->GetInt32Value(state, 2);
  3706. string action = lua_interface->GetStringValue(state, 3);
  3707. if (step > 0 && action.length() > 0)
  3708. quest->AddCompleteAction(step, action);
  3709. }
  3710. return 0;
  3711. }
  3712. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3713. if (!lua_interface)
  3714. return 0;
  3715. Quest* quest = lua_interface->GetQuest(state);
  3716. if (quest) {
  3717. int32 step = lua_interface->GetInt32Value(state, 2);
  3718. string action = lua_interface->GetStringValue(state, 3);
  3719. if (step > 0 && action.length() > 0)
  3720. quest->AddProgressAction(step, action);
  3721. }
  3722. return 0;
  3723. }
  3724. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3725. if (!lua_interface)
  3726. return 0;
  3727. Quest* quest = lua_interface->GetQuest(state);
  3728. string description = lua_interface->GetStringValue(state, 2);
  3729. if (quest && description.length() > 0)
  3730. quest->SetDescription(description);
  3731. return 0;
  3732. }
  3733. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3734. if (!lua_interface)
  3735. return 0;
  3736. Quest* quest = lua_interface->GetQuest(state);
  3737. string description = lua_interface->GetStringValue(state, 2);
  3738. if (quest && description.length() > 0)
  3739. quest->SetCompletedDescription(description);
  3740. return 0;
  3741. }
  3742. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3743. if (!lua_interface)
  3744. return 0;
  3745. Quest* quest = lua_interface->GetQuest(state);
  3746. int32 step = lua_interface->GetInt32Value(state, 2);
  3747. string description = lua_interface->GetStringValue(state, 3);
  3748. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3749. if (quest && step > 0 && description.length() > 0) {
  3750. quest->SetTaskGroupDescription(step, description, display_bullets);
  3751. /* if (quest->GetPlayer()) {
  3752. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3753. if (client)
  3754. client->SendQuestUpdateStep(quest, step, false);
  3755. }*/
  3756. }
  3757. return 0;
  3758. }
  3759. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3760. if (!lua_interface)
  3761. return 0;
  3762. Quest* quest = lua_interface->GetQuest(state);
  3763. int32 step = lua_interface->GetInt32Value(state, 2);
  3764. string description = lua_interface->GetStringValue(state, 3);
  3765. if (quest && step > 0 && description.length() > 0) {
  3766. quest->SetStepDescription(step, description);
  3767. /*if (quest->GetPlayer()) {
  3768. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3769. if (client)
  3770. client->SendQuestUpdateStepImmediately(quest, step);
  3771. }*/
  3772. }
  3773. return 0;
  3774. }
  3775. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3776. Quest* quest = lua_interface->GetQuest(state);
  3777. string zone = lua_interface->GetStringValue(state, 2);
  3778. if (quest && zone.length() > 0)
  3779. quest->SetZone(zone);
  3780. return 0;
  3781. }
  3782. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3783. if (!lua_interface)
  3784. return 0;
  3785. Quest* quest = lua_interface->GetQuest(state);
  3786. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3787. int32 coin = lua_interface->GetInt32Value(state, 3);
  3788. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3789. string rewards_str = lua_interface->GetStringValue(state, 5);
  3790. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3791. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3792. string text = lua_interface->GetStringValue(state, 8);
  3793. if (playerSpawn && playerSpawn->IsPlayer()) {
  3794. Player* player = (Player*)playerSpawn;
  3795. Client* client = player->GetZone()->GetClientBySpawn(player);
  3796. if (client) {
  3797. vector<Item*> reward_items;
  3798. vector<Item*> selectable_reward_items;
  3799. if (rewards_str.length() > 0) {
  3800. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3801. map<unsigned int, unsigned short>::iterator itr;
  3802. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3803. if (itr->first > 0) {
  3804. Item* item = new Item(master_item_list.GetItem(itr->first));
  3805. if (item) {
  3806. if (itr->second > 0)
  3807. item->details.count = itr->second;
  3808. reward_items.push_back(item);
  3809. }
  3810. }
  3811. }
  3812. }
  3813. if (select_rewards_str.length() > 0) {
  3814. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3815. map<unsigned int, unsigned short>::iterator itr;
  3816. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3817. if (itr->first > 0) {
  3818. Item* item = new Item(master_item_list.GetItem(itr->first));
  3819. if (item) {
  3820. if (itr->second > 0)
  3821. item->stack_count = itr->second;
  3822. selectable_reward_items.push_back(item);
  3823. }
  3824. }
  3825. }
  3826. }
  3827. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3828. const char* reward_type = "Quest Reward!";
  3829. if (!quest)
  3830. reward_type = "Reward!";
  3831. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3832. }
  3833. }
  3834. return 0;
  3835. }
  3836. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3837. if (!lua_interface)
  3838. return 0;
  3839. Quest* quest = lua_interface->GetQuest(state);
  3840. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3841. lua_interface->ResetFunctionStack(state);
  3842. if (quest && spawn) {
  3843. if (spawn->IsPlayer()) {
  3844. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3845. if (client)
  3846. {
  3847. client->AddPendingQuestAcceptReward(quest);
  3848. client->AddPendingQuestReward(quest);
  3849. }
  3850. }
  3851. }
  3852. return 0;
  3853. }
  3854. int EQ2Emu_lua_Harvest(lua_State* state) {
  3855. if (!lua_interface)
  3856. return 0;
  3857. Spawn* player = lua_interface->GetSpawn(state);
  3858. Spawn* node = lua_interface->GetSpawn(state, 2);
  3859. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3860. Client* client = player->GetZone()->GetClientBySpawn(player);
  3861. if (client) {
  3862. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3863. ((GroundSpawn*)node)->ProcessHarvest(client);
  3864. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3865. player->GetZone()->RemoveSpawn(node, true);
  3866. }
  3867. }
  3868. else if (player && player->IsPlayer()) {
  3869. Client* client = player->GetZone()->GetClientBySpawn(player);
  3870. if (client)
  3871. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3872. }
  3873. return 0;
  3874. }
  3875. int EQ2Emu_lua_Bind(lua_State* state) {
  3876. if (!lua_interface)
  3877. return 0;
  3878. Spawn* spawn = lua_interface->GetSpawn(state);
  3879. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3880. float x = lua_interface->GetFloatValue(state, 3);
  3881. float y = lua_interface->GetFloatValue(state, 4);
  3882. float z = lua_interface->GetFloatValue(state, 5);
  3883. float h = lua_interface->GetFloatValue(state, 6);
  3884. if (!spawn) {
  3885. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3886. return 0;
  3887. }
  3888. if (!spawn->IsPlayer()) {
  3889. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3890. return 0;
  3891. }
  3892. if (zone_id == 0) {
  3893. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3894. if (!client) {
  3895. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3896. return 0;
  3897. }
  3898. if (!client->Bind())
  3899. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3900. }
  3901. else {
  3902. Player* player = (Player*)spawn;
  3903. player->GetPlayerInfo()->SetBindZone(zone_id);
  3904. player->GetPlayerInfo()->SetBindX(x);
  3905. player->GetPlayerInfo()->SetBindY(y);
  3906. player->GetPlayerInfo()->SetBindZ(z);
  3907. player->GetPlayerInfo()->SetBindHeading(h);
  3908. }
  3909. return 0;
  3910. }
  3911. int EQ2Emu_lua_Gate(lua_State* state) {
  3912. if (!lua_interface)
  3913. return 0;
  3914. Spawn* spawn = lua_interface->GetSpawn(state);
  3915. if (spawn) {
  3916. if (spawn->IsPlayer()) {
  3917. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3918. if (client) {
  3919. if (!client->Gate())
  3920. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3921. }
  3922. }
  3923. }
  3924. return 0;
  3925. }
  3926. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3927. if (!lua_interface)
  3928. return 0;
  3929. bool ret = false;
  3930. Spawn* spawn = lua_interface->GetSpawn(state);
  3931. if (spawn) {
  3932. if (spawn->IsPlayer()) {
  3933. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3934. if (client)
  3935. ret = client->BindAllowed();
  3936. }
  3937. }
  3938. lua_interface->SetBooleanValue(state, ret);
  3939. return 1;
  3940. }
  3941. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3942. if (!lua_interface)
  3943. return 0;
  3944. bool ret = false;
  3945. Spawn* spawn = lua_interface->GetSpawn(state);
  3946. if (spawn) {
  3947. if (spawn->IsPlayer()) {
  3948. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3949. if (client)
  3950. ret = client->GateAllowed();
  3951. }
  3952. }
  3953. lua_interface->SetBooleanValue(state, ret);
  3954. return 1;
  3955. }
  3956. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3957. Spawn* spawn = lua_interface->GetSpawn(state);
  3958. if (spawn) {
  3959. lua_interface->SetBooleanValue(state, spawn->Alive());
  3960. return 1;
  3961. }
  3962. return 0;
  3963. }
  3964. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3965. if (!lua_interface)
  3966. return 0;
  3967. Spawn* spawn = lua_interface->GetSpawn(state);
  3968. if (spawn && spawn->IsEntity()) {
  3969. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3970. return 1;
  3971. }
  3972. return 0;
  3973. }
  3974. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3975. Spawn* spawn = lua_interface->GetSpawn(state);
  3976. string message = lua_interface->GetStringValue(state, 2);
  3977. string color_str = lua_interface->GetStringValue(state, 3);
  3978. int8 color = CHANNEL_NARRATIVE;
  3979. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3980. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3981. if (client) {
  3982. if (color_str.length() > 0) {
  3983. // leave for backwards compat, but all future should just use the number
  3984. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3985. color = CHANNEL_COLOR_RED;
  3986. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3987. color = CHANNEL_COLOR_YELLOW;
  3988. else
  3989. {
  3990. // use a number to specify the channel as per Commands/Commands.h defines
  3991. color = (int8)atoul(color_str.c_str());
  3992. }
  3993. }
  3994. client->SimpleMessage(color, message.c_str());
  3995. }
  3996. }
  3997. return 0;
  3998. }
  3999. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4000. Spawn* spawn = lua_interface->GetSpawn(state);
  4001. string message = lua_interface->GetStringValue(state, 2);
  4002. int8 red = lua_interface->GetInt8Value(state, 3);
  4003. int8 green = lua_interface->GetInt8Value(state, 4);
  4004. int8 blue = lua_interface->GetInt8Value(state, 5);
  4005. if (!spawn) {
  4006. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4007. return 0;
  4008. }
  4009. int32 words = ::CountWordsInString(message.c_str());
  4010. if (words < 5)
  4011. words = 5;
  4012. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4013. if (client)
  4014. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4015. return 0;
  4016. }
  4017. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4018. Spawn* spawn = lua_interface->GetSpawn(state);
  4019. int8 param = lua_interface->GetInt8Value(state, 2);
  4020. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4021. int8 value = lua_interface->GetInt8Value(state, 4);
  4022. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4023. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4024. if (client) {
  4025. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4026. switch (param) {
  4027. case 1: {
  4028. packet->setDataByName("parameter1", param_value);
  4029. break;
  4030. }
  4031. case 2: {
  4032. packet->setDataByName("parameter2", param_value);
  4033. break;
  4034. }
  4035. case 3: {
  4036. packet->setDataByName("parameter3", param_value);
  4037. break;
  4038. }
  4039. case 4: {
  4040. packet->setDataByName("parameter4", param_value);
  4041. break;
  4042. }
  4043. case 5: {
  4044. packet->setDataByName("parameter5", param_value);
  4045. break;
  4046. }
  4047. }
  4048. packet->setDataByName("value", value);
  4049. client->QueuePacket(packet->serialize());
  4050. safe_delete(packet);
  4051. }
  4052. }
  4053. return 0;
  4054. }
  4055. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4056. Spawn* spawn = lua_interface->GetSpawn(state);
  4057. if (spawn && spawn->IsPlayer()) {
  4058. if (((Player*)spawn)->GetIsTracking())
  4059. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4060. else
  4061. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4062. }
  4063. return 0;
  4064. }
  4065. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4066. Spawn* player = lua_interface->GetSpawn(state);
  4067. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4068. string name = lua_interface->GetStringValue(state, 3);
  4069. float distance = lua_interface->GetFloatValue(state, 4);
  4070. string command = lua_interface->GetStringValue(state, 5);
  4071. string error_text = lua_interface->GetStringValue(state, 6);
  4072. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4073. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4074. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4075. if (spawn) {
  4076. if (distance == 0)
  4077. distance = 10.0f;
  4078. if (command.length() == 0)
  4079. command = name;
  4080. if (command.length() < 1 && name.length() < 1)
  4081. {
  4082. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4083. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4084. spawn->RemovePrimaryCommands();
  4085. }
  4086. else
  4087. {
  4088. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4089. }
  4090. }
  4091. return 0;
  4092. }
  4093. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4094. if (!lua_interface)
  4095. return 0;
  4096. Spawn* player = lua_interface->GetSpawn(state);
  4097. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4098. int16 tier = lua_interface->GetInt16Value(state, 3);
  4099. if (player && player->IsPlayer()) {
  4100. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4101. return 1;
  4102. }
  4103. return 0;
  4104. }
  4105. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4106. if (!lua_interface)
  4107. return 0;
  4108. Spawn* player = lua_interface->GetSpawn(state);
  4109. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4110. int16 tier = lua_interface->GetInt16Value(state, 3);
  4111. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4112. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4113. bool add_to_hotbar = true;
  4114. if (num_args > 4) {
  4115. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4116. }
  4117. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4118. if (player && spell && player->IsPlayer()) {
  4119. Client* client = player->GetClient();
  4120. if (client) {
  4121. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4122. {
  4123. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4124. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4125. client->GetPlayer()->UnlockSpell(spell);
  4126. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4127. }
  4128. else
  4129. {
  4130. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4131. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4132. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4133. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4134. client->GetPlayer()->UnlockSpell(spell);
  4135. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4136. }
  4137. //if (client ) {
  4138. // ((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);
  4139. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4140. if (outapp)
  4141. client->QueuePacket(outapp);
  4142. }
  4143. }
  4144. return 0;
  4145. }
  4146. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4147. if (!lua_interface)
  4148. return 0;
  4149. Spawn* player = lua_interface->GetSpawn(state);
  4150. if (player && player->IsPlayer()) {
  4151. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4152. return 1;
  4153. }
  4154. return 0;
  4155. }
  4156. int EQ2Emu_lua_Attack(lua_State* state) {
  4157. if (lua_interface) {
  4158. Spawn* npc = lua_interface->GetSpawn(state);
  4159. Spawn* player = lua_interface->GetSpawn(state, 2);
  4160. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4161. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4162. }
  4163. return 0;
  4164. }
  4165. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4166. if (lua_interface) {
  4167. Spawn* target = lua_interface->GetSpawn(state);
  4168. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4169. if (target && target->GetZone())
  4170. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4171. }
  4172. return 0;
  4173. }
  4174. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4175. Spawn* player;
  4176. if (lua_interface) {
  4177. player = lua_interface->GetSpawn(state);
  4178. if (player && player->IsPlayer()) {
  4179. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4180. return 1;
  4181. }
  4182. }
  4183. return 0;
  4184. }
  4185. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4186. Spawn* player;
  4187. Client* client;
  4188. if (lua_interface) {
  4189. player = lua_interface->GetSpawn(state);
  4190. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4191. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4192. client->HandInCollections();
  4193. }
  4194. return 0;
  4195. }
  4196. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4197. Spawn* widget;
  4198. if (lua_interface) {
  4199. widget = lua_interface->GetSpawn(state);
  4200. if (widget && widget->IsWidget())
  4201. ((Widget*)widget)->HandleUse(nullptr, "");
  4202. }
  4203. return 0;
  4204. }
  4205. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4206. Spawn* spawn = 0;
  4207. int32 primary_list = 0;
  4208. int32 secondary_list = 0;
  4209. if (lua_interface) {
  4210. spawn = lua_interface->GetSpawn(state);
  4211. primary_list = lua_interface->GetInt32Value(state, 2);
  4212. secondary_list = lua_interface->GetInt32Value(state, 3);
  4213. if (!spawn->IsNPC()) {
  4214. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4215. return 0;
  4216. }
  4217. NPC* npc = (NPC*)spawn;
  4218. npc->SetPrimarySpellList(primary_list);
  4219. npc->SetSecondarySpellList(secondary_list);
  4220. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4221. }
  4222. return 0;
  4223. }
  4224. int EQ2Emu_lua_GetPet(lua_State* state) {
  4225. if (!lua_interface)
  4226. return 0;
  4227. Spawn* spawn = lua_interface->GetSpawn(state);
  4228. if (spawn) {
  4229. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4230. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4231. return 1;
  4232. }
  4233. }
  4234. return 0;
  4235. }
  4236. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4237. if (!lua_interface)
  4238. return 0;
  4239. Spawn* spawn = lua_interface->GetSpawn(state);
  4240. if (spawn) {
  4241. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4242. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4243. return 1;
  4244. }
  4245. }
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4249. if (!lua_interface)
  4250. return 0;
  4251. Spawn* spawn = lua_interface->GetSpawn(state);
  4252. if (spawn) {
  4253. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4254. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4255. return 1;
  4256. }
  4257. }
  4258. return 0;
  4259. }
  4260. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4261. if (!lua_interface)
  4262. return 0;
  4263. Spawn* spawn = lua_interface->GetSpawn(state);
  4264. if (spawn) {
  4265. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4266. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4267. return 1;
  4268. }
  4269. }
  4270. return 0;
  4271. }
  4272. int EQ2Emu_lua_Charm(lua_State* state) {
  4273. if (!lua_interface)
  4274. return 0;
  4275. Spawn* owner = lua_interface->GetSpawn(state);
  4276. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4277. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4278. if (!luaspell) {
  4279. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4280. return 0;
  4281. }
  4282. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4283. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4284. pet->SetPet(true);
  4285. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4286. ((NPC*)pet)->SetOwner((Entity*)owner);
  4287. // If owner is player and player does not have a summoned pet set the players charsheet
  4288. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4289. Player* player = (Player*)owner;
  4290. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4291. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4292. player->GetInfoStruct()->set_pet_movement(2);
  4293. player->GetInfoStruct()->set_pet_behavior(3);
  4294. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4295. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4296. // Make sure the values get sent to the client
  4297. player->SetCharSheetChanged(true);
  4298. }
  4299. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4300. pet->SetSpawnScript("");
  4301. // Set faction to the same as the owner
  4302. pet->SetFactionID(owner->GetFactionID());
  4303. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4304. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4305. // Clear hate list
  4306. ((NPC*)pet)->Brain()->ClearHate();
  4307. // Set the brain to a pet brain
  4308. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4309. }
  4310. return 0;
  4311. }
  4312. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4313. if (!lua_interface)
  4314. return 0;
  4315. Spawn* spawn = lua_interface->GetSpawn(state);
  4316. if (!spawn) {
  4317. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4318. return 0;
  4319. }
  4320. vector<Spawn*> groupMembers;
  4321. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4322. groupMembers = *spawn->GetSpawnGroup();
  4323. }
  4324. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4325. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4326. deque<GroupMemberInfo*>::iterator itr;
  4327. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4328. if (group)
  4329. {
  4330. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4331. deque<GroupMemberInfo*>* members = group->GetMembers();
  4332. GroupMemberInfo* info = 0;
  4333. for (itr = members->begin(); itr != members->end(); itr++) {
  4334. info = *itr;
  4335. if (info->client)
  4336. groupMembers.push_back(info->client->GetPlayer());
  4337. }
  4338. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4339. }
  4340. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4341. }
  4342. else
  4343. return 0;
  4344. lua_createtable(state, groupMembers.size(), 0);
  4345. int newTable = lua_gettop(state);
  4346. for (int32 i = 0; i < groupMembers.size(); i++) {
  4347. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4348. lua_rawseti(state, newTable, i + 1);
  4349. }
  4350. return 1;
  4351. }
  4352. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4353. if (!lua_interface)
  4354. return 0;
  4355. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4356. lua_interface->SetOptionWindowValue(state, option_window);
  4357. return 1;
  4358. }
  4359. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4360. if (!lua_interface)
  4361. return 0;
  4362. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4363. if (option_window) {
  4364. OptionWindowOption option_window_option;
  4365. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4366. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4367. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4368. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4369. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4370. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4371. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4372. option_window->push_back(option_window_option);
  4373. }
  4374. return 0;
  4375. }
  4376. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4377. if (!lua_interface)
  4378. return 0;
  4379. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4380. Spawn* player = lua_interface->GetSpawn(state, 2);
  4381. string window_title = lua_interface->GetStringValue(state, 3);
  4382. string cancel_command = lua_interface->GetStringValue(state, 4);
  4383. Client* client = player->GetZone()->GetClientBySpawn(player);
  4384. if (option_window && window_title.length() > 0 && client) {
  4385. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4386. if (!packet)
  4387. return 0;
  4388. packet->setDataByName("title_text", window_title.c_str());
  4389. if (cancel_command.length() > 0)
  4390. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4391. packet->setArrayLengthByName("num_selections", option_window->size());
  4392. vector<OptionWindowOption>::iterator itr;
  4393. int8 i = 0;
  4394. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4395. OptionWindowOption opt = *itr;
  4396. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4397. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4398. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4399. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4400. if (opt.optionCommand.length() > 0)
  4401. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4402. if (opt.optionConfirmTitle.length() > 0)
  4403. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4404. i++;
  4405. }
  4406. client->QueuePacket(packet->serialize());
  4407. safe_delete(option_window);
  4408. safe_delete(packet);
  4409. }
  4410. return 0;
  4411. }
  4412. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4413. if (!lua_interface)
  4414. return 0;
  4415. Spawn* spawn = lua_interface->GetSpawn(state);
  4416. if (spawn) {
  4417. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4418. return 1;
  4419. }
  4420. else
  4421. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4422. return 0;
  4423. }
  4424. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4425. if (!lua_interface)
  4426. return 0;
  4427. Spawn* spawn = lua_interface->GetSpawn(state);
  4428. if (spawn) {
  4429. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4430. return 1;
  4431. }
  4432. else
  4433. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4434. return 0;
  4435. }
  4436. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4437. if (!lua_interface)
  4438. return 0;
  4439. Spawn* spawn = lua_interface->GetSpawn(state);
  4440. if (spawn) {
  4441. int8 class_id = spawn->GetTradeskillClass();
  4442. // Need to add 42 for the offset in the array
  4443. class_id += 44;
  4444. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4445. return 1;
  4446. }
  4447. else
  4448. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4449. return 0;
  4450. }
  4451. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4452. if (!lua_interface)
  4453. return 0;
  4454. Spawn* spawn = lua_interface->GetSpawn(state);
  4455. int16 level = lua_interface->GetInt8Value(state, 2);
  4456. if (spawn) {
  4457. if (spawn->IsPlayer())
  4458. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4459. else
  4460. spawn->SetTSLevel(level);
  4461. }
  4462. else
  4463. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4464. return 0;
  4465. }
  4466. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4467. if (!lua_interface)
  4468. return 0;
  4469. Spawn* spawn = lua_interface->GetSpawn(state);
  4470. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4471. if (spawn) {
  4472. spawn->SetAttackable(attackable);
  4473. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4478. // Check to see if we have a valid lua_interface
  4479. if (!lua_interface)
  4480. return 0;
  4481. // Get the spawn that is getting the pet
  4482. Spawn* spawn = lua_interface->GetSpawn(state);
  4483. // Get the DB ID of the pet
  4484. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4485. // The max level the pet can gain
  4486. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4487. // Get the spell that this command was called from
  4488. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4489. // Check to make sure the spawn pointer is valid
  4490. if (!spawn) {
  4491. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4492. return 0;
  4493. }
  4494. // Check to make sure the spawn is an entity
  4495. if (!spawn->IsEntity()) {
  4496. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4497. return 0;
  4498. }
  4499. // Check to make sure the spawn doesn't already have a pet of this type
  4500. if (((Entity*)spawn)->GetPet()) {
  4501. if (spawn->IsPlayer()) {
  4502. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4503. if (client)
  4504. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4505. }
  4506. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4507. return 0;
  4508. }
  4509. // Check to see if the DB ID for the pet is set
  4510. if (pet_id == 0) {
  4511. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4512. return 0;
  4513. }
  4514. // Check to see if the pointer to the spell is valid
  4515. if (!luaspell) {
  4516. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4517. return 0;
  4518. }
  4519. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4520. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4521. if (!pet) {
  4522. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4523. return 0;
  4524. }
  4525. // Check to make sure the pet is an npc
  4526. if (!pet->IsNPC()) {
  4527. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4528. return 0;
  4529. }
  4530. // Spawn the pet at the same location as the owner
  4531. pet->SetX(spawn->GetX());
  4532. pet->SetY(spawn->GetY());
  4533. pet->SetZ(spawn->GetZ());
  4534. pet->SetLocation(spawn->GetLocation());
  4535. pet->SetHeading(spawn->GetHeading());
  4536. spawn->GetZone()->AddSpawn(pet);
  4537. /*
  4538. const char* spawn_script = world.GetSpawnScript(pet_id);
  4539. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4540. spawn->SetSpawnScript(string(spawn_script));
  4541. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4542. }*/
  4543. // Get a random pet name
  4544. string random_pet_name;
  4545. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4546. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4547. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4548. // If player set various values for the char sheet (pet window)
  4549. if (spawn->IsPlayer()) {
  4550. Player* player = (Player*)spawn;
  4551. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4552. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4553. player->GetInfoStruct()->set_pet_movement(2);
  4554. player->GetInfoStruct()->set_pet_behavior(3);
  4555. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4556. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4557. // Make sure the values get sent to the client
  4558. player->SetCharSheetChanged(true);
  4559. }
  4560. // Set the pets name
  4561. pet->SetName(random_pet_name.c_str());
  4562. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4563. if (max_level > 0)
  4564. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4565. else
  4566. pet->SetLevel(spawn->GetLevel());
  4567. // Set the max level this pet can reach
  4568. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4569. // Set the faction of the pet to the same faction as the owner
  4570. pet->SetFactionID(spawn->GetFactionID());
  4571. // Set the spawn as a pet
  4572. pet->SetPet(true);
  4573. // Give a pointer of the owner to the pet
  4574. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4575. // Give a pointer of the pet to the owner
  4576. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4577. // Set the pet type
  4578. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4579. // Set the spell id used to create this pet
  4580. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4581. // Set the spell tier used to create this pet
  4582. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4583. // Set the pets spawn type to 6
  4584. pet->SetSpawnType(6);
  4585. // Set the pets brain
  4586. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4587. // Check to see if the pet has a subtitle
  4588. if (strlen(pet->GetSubTitle()) > 0) {
  4589. // Add the players name to the front of the sub title
  4590. string pet_subtitle;
  4591. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4592. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4593. // Set the pets subtitle to the new one
  4594. pet->SetSubTitle(pet_subtitle.c_str());
  4595. }
  4596. // Add the "Pet Options" entity command to the pet
  4597. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4598. // Set the pet as the return value for this function
  4599. lua_interface->SetSpawnValue(state, pet);
  4600. return 1;
  4601. }
  4602. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4603. if (!lua_interface)
  4604. return 0;
  4605. Spawn* spawn = lua_interface->GetSpawn(state);
  4606. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4607. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4608. if (!spawn) {
  4609. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4610. return 0;
  4611. }
  4612. if (!spawn->IsEntity()) {
  4613. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4614. return 0;
  4615. }
  4616. if (((Entity*)spawn)->GetDeityPet()) {
  4617. if (spawn->IsPlayer()) {
  4618. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4619. if (client)
  4620. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4621. }
  4622. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4623. return 0;
  4624. }
  4625. if (pet_id == 0) {
  4626. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4627. return 0;
  4628. }
  4629. if (!luaspell) {
  4630. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4631. return 0;
  4632. }
  4633. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4634. if (!pet) {
  4635. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4636. return 0;
  4637. }
  4638. if (!pet->IsNPC()) {
  4639. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4640. return 0;
  4641. }
  4642. pet->SetX(spawn->GetX());
  4643. pet->SetY(spawn->GetY());
  4644. pet->SetZ(spawn->GetZ());
  4645. pet->SetLocation(spawn->GetLocation());
  4646. pet->SetHeading(spawn->GetHeading());
  4647. spawn->GetZone()->AddSpawn(pet);
  4648. string random_pet_name;
  4649. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4650. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4651. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4652. pet->SetName(random_pet_name.c_str());
  4653. pet->SetLevel(spawn->GetLevel());
  4654. pet->SetFactionID(spawn->GetFactionID());
  4655. pet->SetPet(true);
  4656. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4657. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4658. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4659. pet->SetSpawnType(6);
  4660. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4661. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4662. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4663. if (strlen(pet->GetSubTitle()) > 0) {
  4664. string pet_subtitle;
  4665. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4666. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4667. pet->SetSubTitle(pet_subtitle.c_str());
  4668. }
  4669. // deity and cosmetic pets are not attackable
  4670. pet->SetAttackable(false);
  4671. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4672. lua_interface->SetSpawnValue(state, pet);
  4673. return 1;
  4674. }
  4675. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4676. if (!lua_interface)
  4677. return 0;
  4678. Spawn* spawn = lua_interface->GetSpawn(state);
  4679. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4680. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4681. if (!spawn) {
  4682. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. if (!spawn->IsEntity()) {
  4686. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4687. return 0;
  4688. }
  4689. if (((Entity*)spawn)->GetCosmeticPet()) {
  4690. if (spawn->IsPlayer()) {
  4691. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4692. if (client)
  4693. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4694. }
  4695. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4696. return 0;
  4697. }
  4698. if (pet_id == 0) {
  4699. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4700. return 0;
  4701. }
  4702. if (!luaspell) {
  4703. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4704. return 0;
  4705. }
  4706. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4707. if (!pet) {
  4708. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4709. return 0;
  4710. }
  4711. if (!pet->IsNPC()) {
  4712. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4713. return 0;
  4714. }
  4715. pet->SetX(spawn->GetX());
  4716. pet->SetY(spawn->GetY());
  4717. pet->SetZ(spawn->GetZ());
  4718. pet->SetLocation(spawn->GetLocation());
  4719. pet->SetHeading(spawn->GetHeading());
  4720. spawn->GetZone()->AddSpawn(pet);
  4721. string random_pet_name;
  4722. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4723. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4724. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4725. pet->SetName(random_pet_name.c_str());
  4726. pet->SetLevel(spawn->GetLevel());
  4727. pet->SetFactionID(spawn->GetFactionID());
  4728. pet->SetPet(true);
  4729. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4730. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4731. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4732. pet->SetSpawnType(6);
  4733. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4734. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4735. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4736. if (strlen(pet->GetSubTitle()) > 0) {
  4737. string pet_subtitle;
  4738. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4739. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4740. pet->SetSubTitle(pet_subtitle.c_str());
  4741. }
  4742. pet->SetAttackable(false);
  4743. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4744. lua_interface->SetSpawnValue(state, pet);
  4745. return 1;
  4746. }
  4747. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4748. if (!lua_interface)
  4749. return 0;
  4750. Spawn* spawn = lua_interface->GetSpawn(state);
  4751. if (!spawn) {
  4752. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. if (!spawn->IsPet()) {
  4756. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. if (!((NPC*)spawn)->IsDismissing())
  4760. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4761. return 0;
  4762. }
  4763. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4764. if (!lua_interface)
  4765. return 0;
  4766. Quest* quest = lua_interface->GetQuest(state);
  4767. if (!quest) {
  4768. 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));
  4769. return 0;
  4770. }
  4771. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4772. if (feather_color > 0)
  4773. quest->SetFeatherColor(feather_color);
  4774. return 0;
  4775. }
  4776. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4777. if (!lua_interface)
  4778. return 0;
  4779. Spawn* spawn = lua_interface->GetSpawn(state);
  4780. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4781. if (!spawn) {
  4782. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4783. return 0;
  4784. }
  4785. if (!spawn2) {
  4786. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4787. return 0;
  4788. }
  4789. spawn->RemoveSpawnAccess(spawn2);
  4790. return 0;
  4791. }
  4792. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4793. if (!lua_interface)
  4794. return 0;
  4795. ZoneServer* zone = lua_interface->GetZone(state);
  4796. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4797. if (!zone) {
  4798. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4799. return 0;
  4800. }
  4801. if (location_id == 0) {
  4802. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4803. return 0;
  4804. }
  4805. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4806. if (!location) {
  4807. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4808. return 0;
  4809. }
  4810. Spawn* spawn = 0;
  4811. if (location->entities[0]) {
  4812. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4813. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4814. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4815. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4816. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4817. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4818. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4819. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4820. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4821. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4822. if (spawn) {
  4823. const char* script = 0;
  4824. for (int x = 0; x < 3; x++) {
  4825. switch (x) {
  4826. case 0:
  4827. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4828. break;
  4829. case 1:
  4830. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4831. break;
  4832. case 2:
  4833. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4834. break;
  4835. }
  4836. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4837. spawn->SetSpawnScript(string(script));
  4838. break;
  4839. }
  4840. }
  4841. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4842. lua_interface->SetSpawnValue(state, spawn);
  4843. return 1;
  4844. }
  4845. else {
  4846. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4847. safe_delete(spawn);
  4848. }
  4849. }
  4850. return 0;
  4851. }
  4852. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4853. if (!lua_interface)
  4854. return 0;
  4855. Spawn* caster = lua_interface->GetSpawn(state);
  4856. Spawn* target = lua_interface->GetSpawn(state, 2);
  4857. int32 id = lua_interface->GetInt32Value(state, 3);
  4858. string command = lua_interface->GetStringValue(state, 4);
  4859. if (!caster) {
  4860. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4861. return 0;
  4862. }
  4863. if (!target) {
  4864. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. if (!caster->IsPlayer()) {
  4868. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4872. if (!entity_command) {
  4873. 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());
  4874. return 0;
  4875. }
  4876. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4877. if (!client) {
  4878. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4879. return 0;
  4880. }
  4881. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4882. return 0;
  4883. }
  4884. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4885. if (!lua_interface)
  4886. return 0;
  4887. Spawn* spawn = lua_interface->GetSpawn(state);
  4888. if (!spawn) {
  4889. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4890. return 0;
  4891. }
  4892. if (!spawn->IsNPC()) {
  4893. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4894. return 0;
  4895. }
  4896. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4897. return 0;
  4898. }
  4899. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4900. if (!lua_interface)
  4901. return 0;
  4902. Spawn* spawn = lua_interface->GetSpawn(state);
  4903. int16 tick = lua_interface->GetInt16Value(state, 2);
  4904. if (!spawn) {
  4905. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4906. return 0;
  4907. }
  4908. if (!spawn->IsNPC()) {
  4909. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4910. return 0;
  4911. }
  4912. if (tick < 20) {
  4913. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4914. return 0;
  4915. }
  4916. ((NPC*)spawn)->Brain()->SetTick(tick);
  4917. return 0;
  4918. }
  4919. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4920. if (!lua_interface)
  4921. return 0;
  4922. Spawn* spawn = lua_interface->GetSpawn(state);
  4923. Spawn* target = lua_interface->GetSpawn(state, 2);
  4924. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4925. if (!spawn) {
  4926. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4927. return 0;
  4928. }
  4929. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4930. spawn->SetFollowTarget(target, follow_distance);
  4931. return 0;
  4932. }
  4933. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4934. if (!lua_interface)
  4935. return 0;
  4936. Spawn* spawn = lua_interface->GetSpawn(state);
  4937. if (!spawn) {
  4938. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4939. return 0;
  4940. }
  4941. Spawn* target = spawn->GetFollowTarget();
  4942. if (target) {
  4943. lua_interface->SetSpawnValue(state, target);
  4944. return 1;
  4945. }
  4946. return 0;
  4947. }
  4948. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4949. if (!lua_interface)
  4950. return 0;
  4951. Spawn* spawn = lua_interface->GetSpawn(state);
  4952. if (!spawn) {
  4953. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. if (spawn->following)
  4957. spawn->following = false;
  4958. else
  4959. spawn->following = true;
  4960. return 0;
  4961. }
  4962. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4963. if (!lua_interface)
  4964. return 0;
  4965. Spawn* spawn = lua_interface->GetSpawn(state);
  4966. if (!spawn) {
  4967. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4968. return 0;
  4969. }
  4970. lua_interface->SetBooleanValue(state, spawn->following);
  4971. return 1;
  4972. }
  4973. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4974. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4975. // I will attempt to explain how this function works for future refrence
  4976. // Fist lets make sure lua_interface is valid, if not return out
  4977. if (!lua_interface)
  4978. return 0;
  4979. // Next we grab the first 2 params same as we usually would
  4980. Spawn* spawn = lua_interface->GetSpawn(state);
  4981. string var = lua_interface->GetStringValue(state, 2);
  4982. // 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
  4983. // 1 = Spawn
  4984. // 2 = Zone
  4985. // 3 = Item
  4986. // 4 = Quest
  4987. // 5 = String
  4988. // 6 = nil (null)
  4989. int8 dataType = 0;
  4990. // Define pointers for each potential type
  4991. Spawn* spawnVal = 0;
  4992. ZoneServer* zone = 0;
  4993. Item* item = 0;
  4994. Quest* quest = 0;
  4995. string val;
  4996. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4997. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4998. // options window are also light user data be we do not handle those.
  4999. // We check with lua_islightuserdata(lua_State*, index)
  5000. if (lua_islightuserdata(state, 3)) {
  5001. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5002. // and convert it to LUAUserData*
  5003. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5004. // Check to make sure the data we got is valid, if not give an error
  5005. if (!data || !data->IsCorrectlyInitialized()) {
  5006. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5007. }
  5008. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5009. else if (data->IsSpawn()) {
  5010. spawnVal = data->spawn;
  5011. dataType = 1;
  5012. }
  5013. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5014. else if (data->IsZone()) {
  5015. zone = data->zone;
  5016. dataType = 2;
  5017. }
  5018. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5019. else if (data->IsItem()) {
  5020. item = data->item;
  5021. dataType = 3;
  5022. }
  5023. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5024. else if (data->IsQuest()) {
  5025. quest = data->quest;
  5026. dataType = 4;
  5027. }
  5028. }
  5029. // Wasn't light user data, check if it is nil(null)
  5030. else if (lua_isnil(state, 3)) {
  5031. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5032. dataType = 6;
  5033. }
  5034. // Wasn't light user data or nil (null), must be a string
  5035. else {
  5036. // Set the string and dataType variable
  5037. val = lua_interface->GetStringValue(state, 3);
  5038. dataType = 5;
  5039. }
  5040. // We now have all the params, lets check to make sure they are valid
  5041. if (!spawn) {
  5042. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5043. return 0;
  5044. }
  5045. if (var.length() == 0) {
  5046. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5047. return 0;
  5048. }
  5049. if (dataType == 0) {
  5050. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5051. return 0;
  5052. }
  5053. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5054. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5055. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5056. switch (dataType) {
  5057. case 1:
  5058. // 1 = Spawn
  5059. spawn->AddTempVariable(var, spawnVal);
  5060. break;
  5061. case 2:
  5062. // 2 = Zone
  5063. spawn->AddTempVariable(var, zone);
  5064. break;
  5065. case 3:
  5066. // 3 = Item
  5067. spawn->AddTempVariable(var, item);
  5068. break;
  5069. case 4:
  5070. // 4 = Quest
  5071. spawn->AddTempVariable(var, quest);
  5072. break;
  5073. case 5:
  5074. // 5 = String
  5075. spawn->AddTempVariable(var, val);
  5076. break;
  5077. case 6:
  5078. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5079. spawn->DeleteTempVariable(var);
  5080. break;
  5081. }
  5082. // And we are done so return out
  5083. return 0;
  5084. }
  5085. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5086. if (!lua_interface)
  5087. return 0;
  5088. Spawn* spawn = lua_interface->GetSpawn(state);
  5089. string var = lua_interface->GetStringValue(state, 2);
  5090. if (!spawn) {
  5091. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (var.length() == 0) {
  5095. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5099. int8 type = spawn->GetTempVariableType(var);
  5100. Spawn* spawn2 = 0;
  5101. ZoneServer* zone = 0;
  5102. Item* item = 0;
  5103. Quest* quest = 0;
  5104. // Set the lua function return value based on the type of data the variable contains
  5105. switch (type) {
  5106. case 1:
  5107. spawn2 = spawn->GetTempVariableSpawn(var);
  5108. if (!spawn2)
  5109. return 0;
  5110. lua_interface->SetSpawnValue(state, spawn2);
  5111. break;
  5112. case 2:
  5113. zone = spawn->GetTempVariableZone(var);
  5114. if (!zone)
  5115. return 0;
  5116. lua_interface->SetZoneValue(state, zone);
  5117. break;
  5118. case 3:
  5119. item = spawn->GetTempVariableItem(var);
  5120. if (!item)
  5121. return 0;
  5122. lua_interface->SetItemValue(state, item);
  5123. break;
  5124. case 4:
  5125. quest = spawn->GetTempVariableQuest(var);
  5126. if (!quest)
  5127. return 0;
  5128. lua_interface->SetQuestValue(state, quest);
  5129. break;
  5130. case 5:
  5131. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5132. break;
  5133. default:
  5134. // Not a valid type then the variable was not set so return out
  5135. return 0;
  5136. }
  5137. // Return value was set so return out
  5138. return 1;
  5139. }
  5140. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5141. {
  5142. if (!lua_interface)
  5143. return 0;
  5144. Quest* quest = lua_interface->GetQuest(state);
  5145. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5146. string description = lua_interface->GetStringValue(state, 3);
  5147. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5148. if (!quest) {
  5149. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5150. lua_interface->SetBooleanValue(state, false);
  5151. return 1;
  5152. }
  5153. if (!spawn) {
  5154. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5155. lua_interface->SetBooleanValue(state, false);
  5156. return 1;
  5157. }
  5158. if (!spawn->IsPlayer()) {
  5159. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5160. lua_interface->SetBooleanValue(state, false);
  5161. return 1;
  5162. }
  5163. if (item_id == 0) {
  5164. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5165. lua_interface->SetBooleanValue(state, false);
  5166. return 1;
  5167. }
  5168. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5169. if (!client) {
  5170. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5171. lua_interface->SetBooleanValue(state, false);
  5172. return 1;
  5173. }
  5174. Item* item = master_item_list.GetItem(item_id);
  5175. if (!item) {
  5176. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5177. lua_interface->SetBooleanValue(state, false);
  5178. return 1;
  5179. }
  5180. Item* firstItem = new Item(item);
  5181. quest->AddTmpRewardItem(firstItem);
  5182. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5183. bool itemsAddedSuccessfully = true;
  5184. if(num_args > 4)
  5185. {
  5186. for(int8 n=5;n<num_args+1;n++)
  5187. {
  5188. int32 new_item = lua_interface->GetInt32Value(state, n);
  5189. Item* tmpItem = master_item_list.GetItem(new_item);
  5190. if(tmpItem)
  5191. {
  5192. Item* newTmpItem = new Item(tmpItem);
  5193. quest->AddTmpRewardItem(newTmpItem);
  5194. }
  5195. else
  5196. itemsAddedSuccessfully = false;
  5197. }
  5198. }
  5199. client->AddPendingQuestAcceptReward(quest);
  5200. client->DisplayQuestComplete(quest, true, description);
  5201. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5202. return 1;
  5203. }
  5204. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5205. if (!lua_interface)
  5206. return 0;
  5207. Quest* quest = lua_interface->GetQuest(state);
  5208. if (!quest) {
  5209. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. quest->SetRepeatable(true);
  5213. return 0;
  5214. }
  5215. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5216. if (!lua_interface)
  5217. return 0;
  5218. Spawn* spawn = lua_interface->GetSpawn(state);
  5219. if (!spawn) {
  5220. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5221. return 0;
  5222. }
  5223. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5224. string ret = classes.GetClassNameCase(base_class);
  5225. if (ret.length() > 0) {
  5226. lua_interface->SetStringValue(state, ret.c_str());
  5227. return 1;
  5228. }
  5229. return 0;
  5230. }
  5231. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5232. if (!lua_interface)
  5233. return 0;
  5234. Spawn* player = lua_interface->GetSpawn(state);
  5235. if (player && player->IsPlayer()) {
  5236. Client* client = player->GetClient();
  5237. if (client)
  5238. client->SendWaypoints();
  5239. }
  5240. return 0;
  5241. }
  5242. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5243. if (!lua_interface)
  5244. return 0;
  5245. Spawn* player = lua_interface->GetSpawn(state);
  5246. string name = lua_interface->GetStringValue(state, 2);
  5247. int32 type = lua_interface->GetInt32Value(state, 3);
  5248. if (type == 0)
  5249. type = 2;
  5250. if (name.length() > 0) {
  5251. if (player && player->IsPlayer()) {
  5252. Client* client = player->GetClient();
  5253. if (client)
  5254. client->AddWaypoint(name, type);
  5255. }
  5256. }
  5257. return 0;
  5258. }
  5259. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5260. if (!lua_interface)
  5261. return 0;
  5262. Spawn* player = lua_interface->GetSpawn(state);
  5263. string name = lua_interface->GetStringValue(state, 2);
  5264. if (name.length() > 0) {
  5265. if (player && player->IsPlayer()) {
  5266. Client* client = player->GetClient();
  5267. if (client)
  5268. client->RemoveWaypoint(name);
  5269. }
  5270. }
  5271. return 0;
  5272. }
  5273. int EQ2Emu_lua_AddWard(lua_State* state) {
  5274. if (!lua_interface)
  5275. return 0;
  5276. int32 damage = lua_interface->GetInt32Value(state);
  5277. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5278. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5279. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5280. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5281. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5282. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5283. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5284. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5285. bool ward_was_added = false;
  5286. ZoneServer* zone = spell->caster->GetZone();
  5287. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5288. for (int32 i = 0; i < spell->targets.size(); i++) {
  5289. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5290. if (!target)
  5291. continue;
  5292. if (target->IsEntity()) {
  5293. // If the ward is already active remove it
  5294. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5295. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5296. // Create new ward info
  5297. WardInfo* ward = new WardInfo;
  5298. ward->Spell = spell;
  5299. ward->BaseDamage = damage;
  5300. ward->DamageLeft = damage;
  5301. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5302. ward->keepWard = keepWard;
  5303. ward->WardType = wardType;
  5304. if (damageAbsorptionPercent > 100)
  5305. damageAbsorptionPercent = 100;
  5306. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5307. if (damageAbsorptionMaxHealthPercent > 100)
  5308. damageAbsorptionMaxHealthPercent = 100;
  5309. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5310. ward->RedirectDamagePercent = redirectDamagePercent;
  5311. ward->LastRedirectDamage = 0;
  5312. ward->LastAbsorbedDamage = 0;
  5313. ward->HitCount = 0;
  5314. spell->num_triggers = maxHitCount;
  5315. spell->had_triggers = true;
  5316. spell->cancel_after_all_triggers = false;
  5317. ward->MaxHitCount = maxHitCount;
  5318. if (wardType == WARD_TYPE_MAGICAL)
  5319. ward->DamageType = damageTypes;
  5320. // Add the ward to the entity
  5321. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5322. ward_was_added = true;
  5323. }
  5324. }
  5325. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5326. if (ward_was_added && spell->caster->IsPlayer()) {
  5327. spell->had_dmg_remaining = true;
  5328. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5329. }
  5330. return 0;
  5331. }
  5332. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5333. if (!lua_interface)
  5334. return 0;
  5335. int32 amount = lua_interface->GetInt32Value(state);
  5336. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5337. WardInfo* ward = 0;
  5338. ZoneServer* zone = spell->caster->GetZone();
  5339. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5340. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5341. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5342. ward = target->GetWard(spell->spell->GetSpellID());
  5343. if (ward) {
  5344. ward->DamageLeft += amount;
  5345. if (ward->DamageLeft > ward->BaseDamage)
  5346. ward->DamageLeft = ward->BaseDamage;
  5347. for (int32 i = 0; i < spell->targets.size(); i++) {
  5348. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5349. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5350. }
  5351. }
  5352. }
  5353. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5354. if (ward && spell->caster->IsPlayer())
  5355. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5356. return 0;
  5357. }
  5358. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5359. if (!lua_interface)
  5360. return 0;
  5361. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5362. if (!spell) {
  5363. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5364. return 0;
  5365. }
  5366. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5367. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5368. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5369. if (ward) {
  5370. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5371. return 1;
  5372. }
  5373. }
  5374. return 0;
  5375. }
  5376. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5377. if (!lua_interface)
  5378. return 0;
  5379. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5380. if (!spell) {
  5381. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5382. return 0;
  5383. }
  5384. string type = lua_interface->GetStringValue(state, 2);
  5385. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5386. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5387. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5388. if (ward) {
  5389. if (boost::iequals(type, "damageleft"))
  5390. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5391. else if (boost::iequals(type, "basedamage"))
  5392. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5393. else if (boost::iequals(type, "keepward"))
  5394. lua_interface->SetBooleanValue(state, ward->keepWard);
  5395. else if (boost::iequals(type, "wardtype"))
  5396. lua_interface->SetInt32Value(state, ward->WardType);
  5397. else if (boost::iequals(type, "dmgabsorptionpct"))
  5398. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5399. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5400. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5401. else if (boost::iequals(type, "redirectdamagepercent"))
  5402. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5403. else if (boost::iequals(type, "lastredirectdamage"))
  5404. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5405. else if (boost::iequals(type, "lastabsorbeddamage"))
  5406. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5407. else if (boost::iequals(type, "hitcount"))
  5408. lua_interface->SetInt32Value(state, ward->HitCount);
  5409. else if (boost::iequals(type, "maxhitcount"))
  5410. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5411. else
  5412. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5413. return 1;
  5414. }
  5415. }
  5416. return 0;
  5417. }
  5418. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5419. if (!lua_interface)
  5420. return 0;
  5421. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5422. ZoneServer* zone = spell->caster->GetZone();
  5423. Spawn* target = 0;
  5424. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5425. for (int32 i = 0; i < spell->targets.size(); i++) {
  5426. target = zone->GetSpawnByID(spell->targets.at(i));
  5427. if (target && target->IsEntity()) {
  5428. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5429. }
  5430. }
  5431. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5432. return 0;
  5433. }
  5434. int EQ2Emu_lua_Interrupt(lua_State* state)
  5435. {
  5436. if (!lua_interface)
  5437. return 0;
  5438. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5439. Spawn* target = lua_interface->GetSpawn(state, 2);
  5440. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5441. if (!caster)
  5442. {
  5443. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5444. return 0;
  5445. }
  5446. if (!target)
  5447. {
  5448. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5449. return 0;
  5450. }
  5451. if (!spell) {
  5452. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. if (!target->IsEntity() && !spell)
  5456. {
  5457. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5458. return 0;
  5459. }
  5460. if (!target && spell) {
  5461. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5462. for (int8 i = 0; i < spell->targets.size(); i++) {
  5463. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5464. if (!target || !target->IsEntity())
  5465. continue;
  5466. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5467. }
  5468. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5469. }
  5470. else
  5471. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5472. return 0;
  5473. }
  5474. int EQ2Emu_lua_Stealth(lua_State* state) {
  5475. if (!lua_interface)
  5476. return 0;
  5477. int8 type = lua_interface->GetInt8Value(state);
  5478. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5479. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5480. if (!spell) {
  5481. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5482. return 0;
  5483. }
  5484. ZoneServer* zone = spell->caster->GetZone();
  5485. if (spawn) {
  5486. if (spawn->IsEntity()) {
  5487. if (type == 1) {
  5488. ((Entity*)spawn)->AddStealthSpell(spell);
  5489. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5490. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5491. }
  5492. else if (type == 2) {
  5493. ((Entity*)spawn)->AddInvisSpell(spell);
  5494. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5495. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5496. }
  5497. return 0;
  5498. }
  5499. else {
  5500. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5501. return 0;
  5502. }
  5503. }
  5504. else {
  5505. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5506. for (int32 i = 0; i < spell->targets.size(); i++) {
  5507. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5508. if (!spawn || !spawn->IsEntity())
  5509. continue;
  5510. if (type == 1) {
  5511. ((Entity*)spawn)->AddStealthSpell(spell);
  5512. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5513. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5514. }
  5515. else if (type == 2) {
  5516. ((Entity*)spawn)->AddInvisSpell(spell);
  5517. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5518. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5519. }
  5520. else {
  5521. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5522. break;
  5523. }
  5524. }
  5525. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5526. }
  5527. return 0;
  5528. }
  5529. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5530. if (!lua_interface)
  5531. return 0;
  5532. Spawn* spawn = lua_interface->GetSpawn(state);
  5533. if (!spawn) {
  5534. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5535. return 0;
  5536. }
  5537. if (spawn->IsEntity()) {
  5538. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5539. return 1;
  5540. }
  5541. else
  5542. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5546. if (!lua_interface)
  5547. return 0;
  5548. Spawn* spawn = lua_interface->GetSpawn(state);
  5549. if (!spawn) {
  5550. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5551. return 0;
  5552. }
  5553. if (spawn->IsEntity()) {
  5554. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5555. return 1;
  5556. }
  5557. else
  5558. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5562. if (!lua_interface)
  5563. return 0;
  5564. Spawn* player = lua_interface->GetSpawn(state);
  5565. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5566. lua_interface->ResetFunctionStack(state);
  5567. if (!player->IsPlayer()) {
  5568. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5569. return 0;
  5570. }
  5571. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5572. return 1;
  5573. }
  5574. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5575. if (!lua_interface)
  5576. return 0;
  5577. Spawn* player = lua_interface->GetSpawn(state);
  5578. int8 slot = lua_interface->GetInt8Value(state, 2);
  5579. lua_interface->ResetFunctionStack(state);
  5580. if (!player) {
  5581. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5582. return 0;
  5583. }
  5584. if (!player->IsPlayer()) {
  5585. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5586. return 0;
  5587. }
  5588. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5589. if (!item) {
  5590. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. lua_interface->SetItemValue(state, item);
  5594. return 1;
  5595. }
  5596. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5597. if (!lua_interface)
  5598. return 0;
  5599. Spawn* player = lua_interface->GetSpawn(state);
  5600. int32 id = lua_interface->GetInt32Value(state, 2);
  5601. lua_interface->ResetFunctionStack(state);
  5602. if (!player) {
  5603. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5604. return 0;
  5605. }
  5606. if (!player->IsPlayer()) {
  5607. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5608. return 0;
  5609. }
  5610. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5611. if (!item) {
  5612. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5613. return 0;
  5614. }
  5615. lua_interface->SetItemValue(state, item);
  5616. return 1;
  5617. }
  5618. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5619. if (!lua_interface)
  5620. return 0;
  5621. Spawn* spawn = lua_interface->GetSpawn(state);
  5622. int8 slot = lua_interface->GetInt8Value(state, 2);
  5623. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5624. lua_interface->ResetFunctionStack(state);
  5625. if (!spawn) {
  5626. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5627. return 0;
  5628. }
  5629. if (!spawn->IsEntity()) {
  5630. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. Item* item = master_item_list.GetItem(item_id);
  5634. if (!item) {
  5635. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5636. return 0;
  5637. }
  5638. Item* copy = new Item(item);
  5639. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5640. if(result)
  5641. {
  5642. ((Entity*)spawn)->SetEquipment(copy, slot);
  5643. spawn->vis_changed = true;
  5644. if(spawn->IsPlayer())
  5645. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5646. }
  5647. else
  5648. {
  5649. safe_delete(copy);
  5650. }
  5651. lua_interface->SetBooleanValue(state, result);
  5652. return 1;
  5653. }
  5654. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5655. if (!lua_interface)
  5656. return 0;
  5657. Spawn* spawn = lua_interface->GetSpawn(state);
  5658. int8 slot = lua_interface->GetInt8Value(state, 2);
  5659. Item* item = lua_interface->GetItem(state, 3);
  5660. lua_interface->ResetFunctionStack(state);
  5661. if (!spawn) {
  5662. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5663. return 0;
  5664. }
  5665. if (!spawn->IsEntity()) {
  5666. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5667. return 0;
  5668. }
  5669. if (!item) {
  5670. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5671. return 0;
  5672. }
  5673. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5674. if(result)
  5675. {
  5676. ((Entity*)spawn)->SetEquipment(item, slot);
  5677. spawn->vis_changed = true;
  5678. if(spawn->IsPlayer())
  5679. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5680. }
  5681. lua_interface->SetBooleanValue(state, result);
  5682. return 1;
  5683. }
  5684. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5685. if (!lua_interface)
  5686. return 0;
  5687. Spawn* spawn = lua_interface->GetSpawn(state);
  5688. int8 slot = lua_interface->GetInt8Value(state, 2);
  5689. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5690. lua_interface->ResetFunctionStack(state);
  5691. if (!spawn) {
  5692. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5693. return 0;
  5694. }
  5695. if (!spawn->IsEntity()) {
  5696. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5697. return 0;
  5698. }
  5699. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5700. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5701. spawn->vis_changed = true;
  5702. if(spawn->IsPlayer())
  5703. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5704. lua_interface->SetBooleanValue(state, true);
  5705. return 1;
  5706. }
  5707. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5708. if (!lua_interface)
  5709. return 0;
  5710. Spawn* spawn = lua_interface->GetSpawn(state);
  5711. int8 slot = lua_interface->GetInt8Value(state, 2);
  5712. int16 type = lua_interface->GetInt16Value(state, 3);
  5713. int8 r = lua_interface->GetInt8Value(state, 4);
  5714. int8 g = lua_interface->GetInt8Value(state, 5);
  5715. int8 b = lua_interface->GetInt8Value(state, 6);
  5716. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5717. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5718. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5719. lua_interface->ResetFunctionStack(state);
  5720. if (!spawn) {
  5721. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5722. return 0;
  5723. }
  5724. if (!spawn->IsEntity()) {
  5725. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5726. return 0;
  5727. }
  5728. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5729. spawn->vis_changed = true;
  5730. lua_interface->SetBooleanValue(state, true);
  5731. return 1;
  5732. }
  5733. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5734. if (!lua_interface)
  5735. return 0;
  5736. Spawn* player = lua_interface->GetSpawn(state);
  5737. int32 id = lua_interface->GetInt32Value(state, 2);
  5738. int8 count = lua_interface->GetInt8Value(state, 3);
  5739. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5740. lua_interface->ResetFunctionStack(state);
  5741. if (!player) {
  5742. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. if (!player->IsPlayer()) {
  5746. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5747. return 0;
  5748. }
  5749. if (!count)
  5750. count = 1;
  5751. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5752. if (!item) {
  5753. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5754. return 0;
  5755. }
  5756. lua_interface->SetItemValue(state, item);
  5757. return 1;
  5758. }
  5759. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5760. if (!lua_interface)
  5761. return 0;
  5762. Spawn* spawn = lua_interface->GetSpawn(state);
  5763. int32 anim = lua_interface->GetInt32Value(state, 2);
  5764. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5765. int8 type = lua_interface->GetInt8Value(state, 4);
  5766. if (!spawn) {
  5767. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5768. return 0;
  5769. }
  5770. if (spawn2) {
  5771. if (spawn2->IsPlayer()) {
  5772. if (type != 1 && type != 2)
  5773. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5774. else
  5775. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5776. return 0;
  5777. }
  5778. else {
  5779. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5780. return 0;
  5781. }
  5782. }
  5783. else
  5784. spawn->GetZone()->PlayAnimation(spawn, anim);
  5785. return 0;
  5786. }
  5787. int EQ2Emu_lua_IsPet(lua_State* state) {
  5788. if (!lua_interface)
  5789. return 0;
  5790. Spawn* spawn = lua_interface->GetSpawn(state);
  5791. if (!spawn) {
  5792. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5793. return 0;
  5794. }
  5795. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5796. return 1;
  5797. }
  5798. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5799. if (!lua_interface)
  5800. return 0;
  5801. Spawn* spawn = lua_interface->GetSpawn(state);
  5802. if (!spawn) {
  5803. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5804. return 0;
  5805. }
  5806. if (!spawn->IsNPC()) {
  5807. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5808. return 0;
  5809. }
  5810. if (((NPC*)spawn)->GetOwner()) {
  5811. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5812. return 1;
  5813. }
  5814. return 0;
  5815. }
  5816. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5817. if (!lua_interface)
  5818. return 0;
  5819. Spawn* spawn = lua_interface->GetSpawn(state);
  5820. Spawn* target = lua_interface->GetSpawn(state, 2);
  5821. if (!spawn) {
  5822. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5823. return 0;
  5824. }
  5825. if (!spawn) {
  5826. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5827. return 0;
  5828. }
  5829. spawn->SetTarget(target);
  5830. return 0;
  5831. }
  5832. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5833. if (!lua_interface)
  5834. return 0;
  5835. Spawn* spawn = lua_interface->GetSpawn(state);
  5836. bool val = lua_interface->GetBooleanValue(state, 2);
  5837. if (!spawn) {
  5838. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5839. return 0;
  5840. }
  5841. if (!spawn->IsEntity()) {
  5842. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5843. return 0;
  5844. }
  5845. ((Entity*)spawn)->InCombat(val);
  5846. if (val) {
  5847. spawn->ClearRunningLocations();
  5848. spawn->CalculateRunningLocation(true);
  5849. }
  5850. return 0;
  5851. }
  5852. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5853. if (!lua_interface)
  5854. return 0;
  5855. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5856. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5857. if (!spawn1) {
  5858. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. if (!spawn2) {
  5862. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5866. return 1;
  5867. }
  5868. int EQ2Emu_lua_Runback(lua_State* state) {
  5869. if (!lua_interface)
  5870. return 0;
  5871. Spawn* spawn = lua_interface->GetSpawn(state);
  5872. if (!spawn) {
  5873. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5874. return 0;
  5875. }
  5876. if (!spawn->IsNPC()) {
  5877. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5878. return 0;
  5879. }
  5880. ((NPC*)spawn)->Runback();
  5881. return 0;
  5882. }
  5883. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5884. if (!lua_interface)
  5885. return 0;
  5886. Spawn* spawn = lua_interface->GetSpawn(state);
  5887. if (!spawn) {
  5888. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. if (!spawn->IsNPC()) {
  5892. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5893. return 0;
  5894. }
  5895. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5896. return 1;
  5897. }
  5898. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5899. if (!lua_interface)
  5900. return 0;
  5901. Spawn* spawn = lua_interface->GetSpawn(state);
  5902. if (!spawn) {
  5903. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!spawn->IsEntity()) {
  5907. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5911. return 1;
  5912. }
  5913. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5914. if (!lua_interface)
  5915. return 0;
  5916. Spawn* spawn = lua_interface->GetSpawn(state);
  5917. if (!spawn) {
  5918. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5919. return 0;
  5920. }
  5921. if (!spawn->IsEntity()) {
  5922. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5923. return 0;
  5924. }
  5925. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5926. return 1;
  5927. }
  5928. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5929. if (!lua_interface)
  5930. return 0;
  5931. Spawn* spawn = lua_interface->GetSpawn(state);
  5932. if (!spawn) {
  5933. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. if (!spawn->IsEntity()) {
  5937. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5938. return 0;
  5939. }
  5940. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5941. return 1;
  5942. }
  5943. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5944. if (!lua_interface)
  5945. return 0;
  5946. Spawn* spawn = lua_interface->GetSpawn(state);
  5947. if (!spawn) {
  5948. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!spawn->IsEntity()) {
  5952. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5956. return 1;
  5957. }
  5958. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5959. if (!lua_interface)
  5960. return 0;
  5961. Spawn* spawn = lua_interface->GetSpawn(state);
  5962. Spawn* target = lua_interface->GetSpawn(state, 2);
  5963. float distance = lua_interface->GetFloatValue(state, 3);
  5964. if (!spawn) {
  5965. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5966. return 0;
  5967. }
  5968. if (!target) {
  5969. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5970. return 0;
  5971. }
  5972. if (!spawn->IsNPC()) {
  5973. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5974. return 0;
  5975. }
  5976. if (!target->IsEntity()) {
  5977. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5981. return 1;
  5982. }
  5983. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5984. if (!lua_interface)
  5985. return 0;
  5986. Spawn* spawn = lua_interface->GetSpawn(state);
  5987. Spawn* target = lua_interface->GetSpawn(state, 2);
  5988. float distance = lua_interface->GetFloatValue(state, 3);
  5989. if (!spawn) {
  5990. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5991. return 0;
  5992. }
  5993. if (!target) {
  5994. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. if (!spawn->IsNPC()) {
  5998. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (!target->IsEntity()) {
  6002. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6006. return 0;
  6007. }
  6008. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6009. if (!lua_interface)
  6010. return 0;
  6011. Spawn* spawn = lua_interface->GetSpawn(state);
  6012. if (!spawn) {
  6013. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6014. return 0;
  6015. }
  6016. if (!spawn->IsNPC()) {
  6017. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6018. return 0;
  6019. }
  6020. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6021. return 1;
  6022. }
  6023. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6024. if (!lua_interface)
  6025. return 0;
  6026. Spawn* spawn = lua_interface->GetSpawn(state);
  6027. if (!spawn) {
  6028. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6029. return 0;
  6030. }
  6031. if (!spawn->IsNPC()) {
  6032. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6033. return 0;
  6034. }
  6035. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6036. return 1;
  6037. }
  6038. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6039. if (!lua_interface)
  6040. return 0;
  6041. Spawn* spawn = lua_interface->GetSpawn(state);
  6042. if (!spawn) {
  6043. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6044. return 0;
  6045. }
  6046. if (!spawn->IsNPC()) {
  6047. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6048. return 0;
  6049. }
  6050. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6051. if (hated) {
  6052. lua_interface->SetSpawnValue(state, hated);
  6053. return 1;
  6054. }
  6055. return 0;
  6056. }
  6057. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. Spawn* spawn = lua_interface->GetSpawn(state);
  6061. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6062. if (!spawn) {
  6063. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. if (!spawn->IsNPC()) {
  6067. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6068. return 0;
  6069. }
  6070. if (!hated) {
  6071. ((NPC*)spawn)->Brain()->ClearHate();
  6072. return 0;
  6073. }
  6074. else
  6075. {
  6076. if (!hated->IsEntity()) {
  6077. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6081. return 0;
  6082. }
  6083. return 0;
  6084. }
  6085. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6086. if (!lua_interface)
  6087. return 0;
  6088. Spawn* spawn = lua_interface->GetSpawn(state);
  6089. if (!spawn) {
  6090. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6091. return 0;
  6092. }
  6093. if (!spawn->IsNPC()) {
  6094. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6095. return 0;
  6096. }
  6097. ((NPC*)spawn)->Brain()->ClearEncounter();
  6098. return 0;
  6099. }
  6100. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6101. if (!lua_interface)
  6102. return 0;
  6103. Spawn* spawn = lua_interface->GetSpawn(state);
  6104. if (!spawn) {
  6105. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6106. return 0;
  6107. }
  6108. if (!spawn->IsNPC()) {
  6109. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6110. return 0;
  6111. }
  6112. // Temp list to store hate list
  6113. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6114. if (encounterList->size() == 0) {
  6115. safe_delete(encounterList);
  6116. return 0;
  6117. }
  6118. lua_createtable(state, encounterList->size(), 0);
  6119. int newTable = lua_gettop(state);
  6120. for (int32 i = 0; i < encounterList->size(); i++) {
  6121. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6122. if (temp)
  6123. lua_interface->SetSpawnValue(state, temp);
  6124. lua_rawseti(state, newTable, i + 1);
  6125. }
  6126. safe_delete(encounterList);
  6127. return 1;
  6128. }
  6129. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6130. if (!lua_interface)
  6131. return 0;
  6132. Spawn* spawn = lua_interface->GetSpawn(state);
  6133. if (!spawn) {
  6134. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. if (!spawn->IsNPC()) {
  6138. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6139. return 0;
  6140. }
  6141. // Temp list to store hate list
  6142. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6143. if (hateList->size() == 0) {
  6144. safe_delete(hateList);
  6145. return 0;
  6146. }
  6147. lua_createtable(state, hateList->size(), 0);
  6148. int newTable = lua_gettop(state);
  6149. for (int32 i = 0; i < hateList->size(); i++) {
  6150. lua_interface->SetSpawnValue(state, hateList->at(i));
  6151. lua_rawseti(state, newTable, i + 1);
  6152. }
  6153. safe_delete(hateList);
  6154. return 1;
  6155. }
  6156. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6157. if (!lua_interface)
  6158. return 0;
  6159. Spawn* spawn = lua_interface->GetSpawn(state);
  6160. if (!spawn) {
  6161. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (spawn->IsPlayer()) {
  6165. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6166. lua_interface->SetBooleanValue(state, true);
  6167. else
  6168. lua_interface->SetBooleanValue(state, false);
  6169. return 1;
  6170. }
  6171. else {
  6172. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6173. return 1;
  6174. }
  6175. }
  6176. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6177. if (!lua_interface)
  6178. return 0;
  6179. Quest* quest = lua_interface->GetQuest(state);
  6180. if (!quest) {
  6181. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6182. return 0;
  6183. }
  6184. quest->SetCompletedFlag(true);
  6185. return 0;
  6186. }
  6187. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6188. if (!lua_interface)
  6189. return 0;
  6190. Spawn* spawn = lua_interface->GetSpawn(state);
  6191. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6192. int8 tier = lua_interface->GetInt8Value(state, 3);
  6193. if (!spawn) {
  6194. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6195. return 0;
  6196. }
  6197. if (!spawn->IsEntity()) {
  6198. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6199. return 0;
  6200. }
  6201. if (spellID == 0) {
  6202. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6203. return 0;
  6204. }
  6205. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6206. if (effect) {
  6207. if (tier > 0) {
  6208. // If a tier was passed chec to see if it is the same as the effect
  6209. if (tier == effect->tier)
  6210. lua_interface->SetBooleanValue(state, true);
  6211. else
  6212. lua_interface->SetBooleanValue(state, false);
  6213. return 1;
  6214. }
  6215. else {
  6216. // Have an effect but no tier was passed so return true
  6217. lua_interface->SetBooleanValue(state, true);
  6218. }
  6219. return 1;
  6220. }
  6221. // no effect so return false
  6222. lua_interface->SetBooleanValue(state, false);
  6223. return 1;
  6224. }
  6225. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6226. if (!lua_interface)
  6227. return 0;
  6228. Spawn* spawn = lua_interface->GetSpawn(state);
  6229. int32 id = lua_interface->GetInt32Value(state, 2);
  6230. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6231. Spawn* spawn2 = 0;
  6232. vector<Spawn*> list;
  6233. if (!spawn) {
  6234. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6235. return 0;
  6236. }
  6237. //If zone not provided, use spawn's zone
  6238. if (!zone)
  6239. zone = spawn->GetZone();
  6240. list = zone->GetSpawnsByID(id);
  6241. if (list.size() == 0) {
  6242. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6243. return 0;
  6244. }
  6245. vector<Spawn*>::iterator itr = list.begin();
  6246. for (int8 i = 0; i < list.size(); i++) {
  6247. spawn2 = itr[i];
  6248. if (spawn2)
  6249. spawn2->AddAllowAccessSpawn(spawn);
  6250. }
  6251. return 0;
  6252. }
  6253. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6254. if (!lua_interface)
  6255. return 0;
  6256. Spawn* spawn = lua_interface->GetSpawn(state);
  6257. int32 id = lua_interface->GetInt32Value(state, 2);
  6258. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6259. Spawn* spawn2 = 0;
  6260. if (!spawn) {
  6261. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6262. return 0;
  6263. }
  6264. //If zone not provided, use spawn's zone
  6265. if (!zone)
  6266. zone = spawn->GetZone();
  6267. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6268. vector<Spawn*>::iterator itr = list.begin();
  6269. if (list.size() == 0) {
  6270. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. for (int8 i = 0; i < list.size(); i++) {
  6274. spawn2 = itr[i];
  6275. if (spawn2)
  6276. spawn2->RemoveSpawnAccess(spawn);
  6277. }
  6278. return 0;
  6279. }
  6280. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6281. if (!lua_interface)
  6282. return 0;
  6283. Quest* quest = lua_interface->GetQuest(state);
  6284. if (!quest) {
  6285. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6286. return 0;
  6287. }
  6288. quest->SetYellowName(true);
  6289. return 0;
  6290. }
  6291. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6292. if (!lua_interface)
  6293. return 0;
  6294. Spawn* spawn = lua_interface->GetSpawn(state);
  6295. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6296. if (!spawn) {
  6297. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6298. return 0;
  6299. }
  6300. if (!spawn->IsPlayer()) {
  6301. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6302. return 0;
  6303. }
  6304. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6305. return 1;
  6306. }
  6307. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6308. if (!lua_interface)
  6309. return 0;
  6310. Spawn* spawn = lua_interface->GetSpawn(state);
  6311. if (!spawn) {
  6312. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6313. return 0;
  6314. }
  6315. if (!spawn->IsPlayer()) {
  6316. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. ZoneServer* zone = spawn->GetZone();
  6320. if (!zone) {
  6321. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6322. return 0;
  6323. }
  6324. Instance_Type iType = zone->GetInstanceType();
  6325. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6326. iType == GROUP_LOCKOUT_INSTANCE ||
  6327. iType == RAID_LOCKOUT_INSTANCE ||
  6328. iType == SOLO_PERSIST_INSTANCE ||
  6329. iType == GROUP_PERSIST_INSTANCE ||
  6330. iType == RAID_PERSIST_INSTANCE) {
  6331. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6332. if (data) {
  6333. // Check to see if the timer has already been set, if it has return out.
  6334. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6335. return 0;
  6336. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6337. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6338. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6339. if (client) {
  6340. string time_msg = "";
  6341. int32 time = data->success_lockout_time;
  6342. int16 hour;
  6343. int8 min;
  6344. int8 sec;
  6345. hour = time / 3600;
  6346. time = time % 3600;
  6347. min = time / 60;
  6348. time = time % 60;
  6349. sec = time;
  6350. if (hour > 0) {
  6351. char temp[10];
  6352. sprintf(temp, " %i", hour);
  6353. time_msg.append(temp);
  6354. time_msg.append(" hour");
  6355. time_msg.append((hour > 1) ? "s" : "");
  6356. }
  6357. if (min > 0) {
  6358. char temp[5];
  6359. sprintf(temp, " %i", min);
  6360. time_msg.append(temp);
  6361. time_msg.append(" minute");
  6362. time_msg.append((min > 1) ? "s" : "");
  6363. }
  6364. // Only add seconds if minutes and hours are 0
  6365. if (hour == 0 && min == 0 && sec > 0) {
  6366. char temp[5];
  6367. sprintf(temp, " %i", sec);
  6368. time_msg.append(temp);
  6369. time_msg.append(" second");
  6370. time_msg.append((sec > 1) ? "s" : "");
  6371. }
  6372. 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());
  6373. }
  6374. }
  6375. else
  6376. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6377. }
  6378. else
  6379. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6380. return 0;
  6381. }
  6382. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6383. if (!lua_interface)
  6384. return 0;
  6385. Spawn* spawn = lua_interface->GetSpawn(state);
  6386. if (!spawn) {
  6387. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6388. return 0;
  6389. }
  6390. if (!spawn->IsPlayer()) {
  6391. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6392. return 0;
  6393. }
  6394. ZoneServer* zone = spawn->GetZone();
  6395. if (!zone) {
  6396. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6397. return 0;
  6398. }
  6399. Instance_Type iType = zone->GetInstanceType();
  6400. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6401. iType == GROUP_LOCKOUT_INSTANCE ||
  6402. iType == RAID_LOCKOUT_INSTANCE ||
  6403. iType == SOLO_PERSIST_INSTANCE ||
  6404. iType == GROUP_PERSIST_INSTANCE ||
  6405. iType == RAID_PERSIST_INSTANCE) {
  6406. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6407. if (data) {
  6408. // Check to see if the timer has already been set, if it has return out.
  6409. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6410. return 0;
  6411. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6412. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6413. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6414. if (client) {
  6415. string time_msg = "";
  6416. int32 time = data->failure_lockout_time;
  6417. int16 hour;
  6418. int8 min;
  6419. int8 sec;
  6420. hour = time / 3600;
  6421. time = time % 3600;
  6422. min = time / 60;
  6423. time = time % 60;
  6424. sec = time;
  6425. if (hour > 0) {
  6426. char temp[10];
  6427. sprintf(temp, " %i", hour);
  6428. time_msg.append(temp);
  6429. time_msg.append(" hour");
  6430. time_msg.append((hour > 1) ? "s" : "");
  6431. }
  6432. if (min > 0) {
  6433. char temp[5];
  6434. sprintf(temp, " %i", min);
  6435. time_msg.append(temp);
  6436. time_msg.append(" minute");
  6437. time_msg.append((min > 1) ? "s" : "");
  6438. }
  6439. // Only add seconds if minutes and hours are 0
  6440. if (hour == 0 && min == 0 && sec > 0) {
  6441. char temp[5];
  6442. sprintf(temp, " %i", sec);
  6443. time_msg.append(temp);
  6444. time_msg.append(" second");
  6445. time_msg.append((sec > 1) ? "s" : "");
  6446. }
  6447. 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());
  6448. }
  6449. }
  6450. else
  6451. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6452. }
  6453. else
  6454. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6455. return 0;
  6456. }
  6457. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6458. if (!lua_interface)
  6459. return 0;
  6460. Spawn* spawn = lua_interface->GetSpawn(state);
  6461. if (!spawn) {
  6462. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6463. return 0;
  6464. }
  6465. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6466. return 1;
  6467. }
  6468. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6469. if (!lua_interface)
  6470. return 0;
  6471. Spawn* player = lua_interface->GetSpawn(state);
  6472. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6473. if (!player) {
  6474. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. if (!player->IsPlayer()) {
  6478. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6479. return 0;
  6480. }
  6481. if (!ground) {
  6482. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. if (!ground->IsGroundSpawn()) {
  6486. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6487. return 0;
  6488. }
  6489. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6490. if (!groundspawn_entries) {
  6491. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6492. return 0;
  6493. }
  6494. Skill* skill = 0;
  6495. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6496. if (collection_skill == "Collecting")
  6497. skill = ((Player*)player)->GetSkillByName("Gathering");
  6498. else
  6499. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6500. if (!skill) {
  6501. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6502. return 0;
  6503. }
  6504. vector<GroundSpawnEntry*>::iterator itr;
  6505. GroundSpawnEntry* entry = 0;
  6506. bool can_harvest = false;
  6507. sint32 min_skill = -1;
  6508. int16 totalSkill = skill->current_val;
  6509. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6510. if(skillID != 0xFFFFFFFF)
  6511. {
  6512. ((Entity*)player)->MStats.lock();
  6513. totalSkill += ((Entity*)player)->stats[skillID];
  6514. ((Entity*)player)->MStats.unlock();
  6515. }
  6516. // first, iterate through groundspawn_entries, discard tables player cannot use
  6517. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6518. {
  6519. entry = *itr;
  6520. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6521. min_skill = entry->min_skill_level;
  6522. // if player lacks skill, skip table
  6523. if (entry->min_skill_level > totalSkill)
  6524. continue;
  6525. // if bonus, but player lacks level, skip table
  6526. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6527. continue;
  6528. can_harvest = true;
  6529. break;
  6530. }
  6531. lua_interface->SetBooleanValue(state, can_harvest);
  6532. // If false, send the message to the client
  6533. if (!can_harvest) {
  6534. Client* client = player->GetZone()->GetClientBySpawn(player);
  6535. if (client) {
  6536. string msg = "You do not have enough skill to ";
  6537. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6538. msg.append("gather");
  6539. else if (collection_skill == "Mining")
  6540. msg.append("mine");
  6541. else if (collection_skill == "Trapping")
  6542. msg.append("trap");
  6543. else if (collection_skill == "Foresting")
  6544. msg.append("forest");
  6545. else if (collection_skill == "Fishing")
  6546. msg.append("catch");
  6547. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6548. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6549. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6550. }
  6551. }
  6552. return 1;
  6553. }
  6554. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6555. if (!lua_interface)
  6556. return 0;
  6557. Spawn* player = lua_interface->GetSpawn(state);
  6558. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6559. if (!player) {
  6560. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6561. return 0;
  6562. }
  6563. if (!player->IsPlayer()) {
  6564. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6568. lua_interface->SetBooleanValue(state, ret);
  6569. return 1;
  6570. }
  6571. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6572. // Check to see if we have a valid lua_interface
  6573. if (!lua_interface)
  6574. return 0;
  6575. // Get the spawn that is getting the pet
  6576. Spawn* spawn = lua_interface->GetSpawn(state);
  6577. Spawn* target = lua_interface->GetSpawn(state, 2);
  6578. // Get the DB ID of the pet
  6579. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6580. float x = lua_interface->GetFloatValue(state, 4);
  6581. float y = lua_interface->GetFloatValue(state, 5);
  6582. float z = lua_interface->GetFloatValue(state, 6);
  6583. // Get the spell that this command was called from
  6584. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6585. // Check to make sure the spawn pointer is valid
  6586. if (!spawn) {
  6587. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6588. return 0;
  6589. }
  6590. // Check to make sure the spawn is an entity
  6591. if (!spawn->IsEntity()) {
  6592. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6593. return 0;
  6594. }
  6595. if (!target) {
  6596. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6597. return 0;
  6598. }
  6599. if (!target->IsEntity()) {
  6600. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6601. return 0;
  6602. }
  6603. // Check to see if the DB ID for the pet is set
  6604. if (pet_id == 0) {
  6605. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6606. return 0;
  6607. }
  6608. // Check to see if the pointer to the spell is valid
  6609. if (!luaspell) {
  6610. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6611. return 0;
  6612. }
  6613. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6614. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6615. if (!pet) {
  6616. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6617. return 0;
  6618. }
  6619. // Check to make sure the pet is an npc
  6620. if (!pet->IsNPC()) {
  6621. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6622. return 0;
  6623. }
  6624. if (x == 0)
  6625. x = spawn->GetX();
  6626. if (y == 0)
  6627. y = spawn->GetY();
  6628. if (z == 0)
  6629. z = spawn->GetZ();
  6630. // Spawn the pet at the same location as the owner
  6631. pet->SetX(x);
  6632. pet->SetY(y);
  6633. pet->SetZ(z);
  6634. pet->SetLocation(spawn->GetLocation());
  6635. pet->SetHeading(spawn->GetHeading());
  6636. spawn->GetZone()->AddSpawn(pet);
  6637. /*
  6638. const char* spawn_script = world.GetSpawnScript(pet_id);
  6639. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6640. spawn->SetSpawnScript(string(spawn_script));
  6641. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6642. }*/
  6643. // Get a random pet name
  6644. string random_pet_name;
  6645. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6646. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6647. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6648. // Set the pets name
  6649. pet->SetName(random_pet_name.c_str());
  6650. // Set the level of the pet to the owners level
  6651. pet->SetLevel(spawn->GetLevel());
  6652. // Set the faction of the pet to the same faction as the owner
  6653. pet->SetFactionID(spawn->GetFactionID());
  6654. // Set the spawn as a pet
  6655. pet->SetPet(true);
  6656. // Give a pointer of the owner to the pet
  6657. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6658. // Set the pet type
  6659. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6660. // Set the spell id used to create this pet
  6661. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6662. // Set the spell tier used to create this pet
  6663. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6664. // Set the pets spawn type to 6
  6665. pet->SetSpawnType(6);
  6666. // Set the pets brain
  6667. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6668. // Check to see if the pet has a subtitle
  6669. if (strlen(pet->GetSubTitle()) > 0) {
  6670. // Add the players name to the front of the sub title
  6671. string pet_subtitle;
  6672. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6673. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6674. // Set the pets subtitle to the new one
  6675. pet->SetSubTitle(pet_subtitle.c_str());
  6676. }
  6677. // Set the pet as the return value for this function
  6678. lua_interface->SetSpawnValue(state, pet);
  6679. return 1;
  6680. }
  6681. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6682. if (!lua_interface)
  6683. return 0;
  6684. Spawn* spawn = lua_interface->GetSpawn(state);
  6685. Spawn* player = lua_interface->GetSpawn(state, 2);
  6686. float max_distance = lua_interface->GetFloatValue(state, 3);
  6687. string type = lua_interface->GetStringValue(state, 4);
  6688. if (!spawn || (spawn && spawn->IsPlayer())) {
  6689. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6690. return 0;
  6691. }
  6692. if (!player || (player && !player->IsPlayer())) {
  6693. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6694. return 0;
  6695. }
  6696. Client* client = 0;
  6697. if (player->GetZone())
  6698. client = player->GetZone()->GetClientBySpawn(player);
  6699. if (!client) {
  6700. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6701. return 0;
  6702. }
  6703. //Set max_distance to default if not set or not proper value
  6704. if (max_distance <= 0)
  6705. max_distance = 500;
  6706. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6707. if (packet) {
  6708. float unknown2_3 = 0;
  6709. int8 placement_mode = 0;
  6710. if (type == "wall") {
  6711. placement_mode = 2;
  6712. unknown2_3 = 150;
  6713. }
  6714. else if (type == "ceiling")
  6715. placement_mode = 1;
  6716. packet->setDataByName("placement_mode", placement_mode);
  6717. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6718. packet->setDataByName("model_type", spawn->GetModelType());
  6719. packet->setDataByName("unknown", 1); //size
  6720. packet->setDataByName("unknown2", 1); //size 2
  6721. packet->setDataByName("unknown2", .5, 1); //size 3
  6722. packet->setDataByName("unknown2", 3, 2);
  6723. packet->setDataByName("unknown2", unknown2_3, 3);
  6724. packet->setDataByName("max_distance", max_distance);
  6725. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6726. client->QueuePacket(packet->serialize());
  6727. safe_delete(packet);
  6728. }
  6729. return 0;
  6730. }
  6731. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6732. if (!lua_interface)
  6733. return 0;
  6734. Item* item = lua_interface->GetItem(state);
  6735. if (!item) {
  6736. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6740. return 1;
  6741. }
  6742. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6743. if (!lua_interface)
  6744. return 0;
  6745. Spawn* spawn = lua_interface->GetSpawn(state);
  6746. if (!spawn) {
  6747. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6748. return 0;
  6749. }
  6750. if (spawn->GetZone())
  6751. spawn->GetZone()->AddTransportSpawn(spawn);
  6752. return 0;
  6753. }
  6754. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6755. if (!lua_interface)
  6756. return 0;
  6757. Skill* skill = lua_interface->GetSkill(state);
  6758. if (!skill) {
  6759. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6760. return 0;
  6761. }
  6762. lua_interface->SetInt32Value(state, skill->current_val);
  6763. return 1;
  6764. }
  6765. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6766. if (!lua_interface)
  6767. return 0;
  6768. Skill* skill = lua_interface->GetSkill(state);
  6769. if (!skill) {
  6770. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. lua_interface->SetInt32Value(state, skill->max_val);
  6774. return 1;
  6775. }
  6776. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6777. if (!lua_interface)
  6778. return 0;
  6779. Skill* skill = lua_interface->GetSkill(state);
  6780. if (!skill) {
  6781. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6782. return 0;
  6783. }
  6784. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6785. return 1;
  6786. }
  6787. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6788. if (!lua_interface)
  6789. return 0;
  6790. Skill* skill = lua_interface->GetSkill(state);
  6791. int16 value = lua_interface->GetInt16Value(state, 2);
  6792. if (!skill) {
  6793. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. skill->max_val = value;
  6797. if (skill->max_val < skill->current_val)
  6798. skill->current_val = skill->max_val;
  6799. return 0;
  6800. }
  6801. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6802. if (!lua_interface)
  6803. return 0;
  6804. Skill* skill = lua_interface->GetSkill(state);
  6805. int16 value = lua_interface->GetInt16Value(state, 2);
  6806. if (!skill) {
  6807. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6808. return 0;
  6809. }
  6810. if (value > skill->max_val)
  6811. skill->current_val = skill->max_val;
  6812. else
  6813. skill->current_val = value;
  6814. return 0;
  6815. }
  6816. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6817. if (!lua_interface)
  6818. return 0;
  6819. Spawn* player = lua_interface->GetSpawn(state);
  6820. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6821. if (skill_id > 0 && player && player->IsPlayer()) {
  6822. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6823. return 1;
  6824. }
  6825. return 0;
  6826. }
  6827. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6828. if (!lua_interface)
  6829. return 0;
  6830. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6831. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6832. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6833. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6834. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6835. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6836. if (player_spawn && player_spawn->IsPlayer()) {
  6837. Player* player = (Player*)player_spawn;
  6838. bool added = false;
  6839. if (!player->skill_list.HasSkill(skill_id)) {
  6840. player->AddSkill(skill_id, current_val, max_val, true);
  6841. added = true;
  6842. }
  6843. 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
  6844. Client* client = player->GetClient();
  6845. if (client) {
  6846. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6847. if (packet)
  6848. client->QueuePacket(packet);
  6849. }
  6850. }
  6851. if (added) {
  6852. lua_interface->SetBooleanValue(state, true);
  6853. return 1;
  6854. }
  6855. }
  6856. else {
  6857. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6858. }
  6859. }
  6860. else {
  6861. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6862. }
  6863. lua_interface->SetBooleanValue(state, false);
  6864. return 1;
  6865. }
  6866. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6867. if (!lua_interface)
  6868. return 0;
  6869. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6870. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6871. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6872. if (skill_id > 0) {
  6873. if (player_spawn && player_spawn->IsPlayer()) {
  6874. Player* player = (Player*)player_spawn;
  6875. if (player->skill_list.HasSkill(skill_id)) {
  6876. player->RemovePlayerSkill(skill_id);
  6877. if (!more_to_remove) {
  6878. Client* client = player->GetClient();
  6879. if (client) {
  6880. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6881. if (packet)
  6882. client->QueuePacket(packet);
  6883. }
  6884. }
  6885. }
  6886. }
  6887. else {
  6888. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6889. }
  6890. }
  6891. else {
  6892. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6893. }
  6894. return 0;
  6895. }
  6896. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6897. if (!lua_interface)
  6898. return 0;
  6899. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6900. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6901. int16 amount = lua_interface->GetInt8Value(state, 3);
  6902. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6903. if (amount > 0 && skill_type < 100) {
  6904. if (player_spawn && player_spawn->IsPlayer()) {
  6905. Player* player = (Player*)player_spawn;
  6906. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6907. if (!more_to_increase) {
  6908. Client* client = player->GetClient();
  6909. if (client) {
  6910. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6911. if (packet)
  6912. client->QueuePacket(packet);
  6913. }
  6914. }
  6915. }
  6916. else {
  6917. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6918. }
  6919. }
  6920. else {
  6921. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6922. }
  6923. return 0;
  6924. }
  6925. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6926. if (!lua_interface)
  6927. return 0;
  6928. Spawn* spawn = lua_interface->GetSpawn(state);
  6929. string name = lua_interface->GetStringValue(state, 2);
  6930. if (!spawn) {
  6931. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6932. return 0;
  6933. }
  6934. if (!spawn->IsEntity()) {
  6935. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6936. return 0;
  6937. }
  6938. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6939. if (skill) {
  6940. lua_interface->SetSkillValue(state, skill);
  6941. return 1;
  6942. }
  6943. return 0;
  6944. }
  6945. int EQ2Emu_lua_AddProc(lua_State* state) {
  6946. if (!lua_interface)
  6947. return 0;
  6948. Spawn* spawn = lua_interface->GetSpawn(state);
  6949. int8 type = lua_interface->GetInt8Value(state, 2);
  6950. float chance = lua_interface->GetFloatValue(state, 3);
  6951. Item* item = lua_interface->GetItem(state, 4);
  6952. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6953. LuaSpell* spell = 0;
  6954. if (!spawn && (!spell || !use_all_spelltargets)) {
  6955. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6956. return 0;
  6957. }
  6958. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6959. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6960. return 0;
  6961. }
  6962. if (!item)
  6963. spell = lua_interface->GetCurrentSpell(state);
  6964. if (!item && !spell) {
  6965. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6966. return 0;
  6967. }
  6968. if (spell && use_all_spelltargets) {
  6969. Spawn* target;
  6970. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6971. for (int8 i = 0; i < spell->targets.size(); i++) {
  6972. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6973. if (!target || !target->IsEntity())
  6974. continue;
  6975. ((Entity*)target)->AddProc(type, chance, item, spell);
  6976. }
  6977. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6978. }
  6979. else
  6980. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6981. return 0;
  6982. }
  6983. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6984. if (!lua_interface)
  6985. return 0;
  6986. Spawn* spawn = lua_interface->GetSpawn(state);
  6987. Item* item = lua_interface->GetItem(state, 2);
  6988. LuaSpell* spell = 0;
  6989. if (!spawn) {
  6990. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6991. return 0;
  6992. }
  6993. if (!spawn->IsEntity()) {
  6994. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6995. return 0;
  6996. }
  6997. if (!item)
  6998. spell = lua_interface->GetCurrentSpell(state);
  6999. if (!item && !spell) {
  7000. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7001. return 0;
  7002. }
  7003. if (spell) {
  7004. Spawn* target;
  7005. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7006. for (int8 i = 0; i < spell->targets.size(); i++) {
  7007. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7008. if (!target || !target->IsEntity())
  7009. continue;
  7010. ((Entity*)target)->RemoveProc(item, spell);
  7011. }
  7012. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7013. spell->caster->RemoveProc(item, spell);
  7014. }
  7015. else
  7016. ((Entity*)spawn)->RemoveProc(item, spell);
  7017. return 0;
  7018. }
  7019. int EQ2Emu_lua_Knockback(lua_State* state) {
  7020. if (!lua_interface)
  7021. return 0;
  7022. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7023. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7024. int32 duration = lua_interface->GetInt32Value(state, 3);
  7025. float vertical = lua_interface->GetFloatValue(state, 4);
  7026. float horizontal = lua_interface->GetFloatValue(state, 5);
  7027. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7028. if (!target_spawn) {
  7029. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7030. return 0;
  7031. }
  7032. if (!spawn) {
  7033. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7037. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7038. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7039. if (packet) {
  7040. packet->setDataByName("target_x", target_spawn->GetX());
  7041. packet->setDataByName("target_y", target_spawn->GetY());
  7042. packet->setDataByName("target_z", target_spawn->GetZ());
  7043. packet->setDataByName("vertical_movement", vertical);
  7044. packet->setDataByName("horizontal_movement", horizontal);
  7045. if (use_heading)
  7046. packet->setDataByName("use_player_heading", 1);
  7047. client->QueuePacket(packet->serialize());
  7048. }
  7049. safe_delete(packet);
  7050. }
  7051. return 0;
  7052. }
  7053. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7054. if (!lua_interface)
  7055. return 0;
  7056. Spawn* spawn = lua_interface->GetSpawn(state);
  7057. if (!spawn) {
  7058. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7059. return 0;
  7060. }
  7061. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7062. return 1;
  7063. }
  7064. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7065. if (!lua_interface)
  7066. return 0;
  7067. Spawn* caster = lua_interface->GetSpawn(state);
  7068. Spawn* target = lua_interface->GetSpawn(state, 2);
  7069. string name = lua_interface->GetStringValue(state, 3);
  7070. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7071. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7072. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7073. string success_msg = lua_interface->GetStringValue(state, 7);
  7074. string effect_msg = lua_interface->GetStringValue(state, 8);
  7075. if (!caster) {
  7076. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7077. return 0;
  7078. }
  7079. if (!caster->IsEntity()) {
  7080. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7081. return 0;
  7082. }
  7083. if (!target) {
  7084. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. if (!target->IsEntity()) {
  7088. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7089. return 0;
  7090. }
  7091. if (name.length() == 0) {
  7092. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7093. return 0;
  7094. }
  7095. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7096. return 0;
  7097. }
  7098. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7099. if (!lua_interface)
  7100. return 0;
  7101. string name = lua_interface->GetStringValue(state);
  7102. if (name.length() == 0) {
  7103. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7104. return 0;
  7105. }
  7106. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7107. if (!skill) {
  7108. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7109. return 0;
  7110. }
  7111. lua_interface->SetInt32Value(state, skill->skill_id);
  7112. return 1;
  7113. }
  7114. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7115. if (!lua_interface)
  7116. return 0;
  7117. Spawn* spawn = lua_interface->GetSpawn(state);
  7118. if (!spawn) {
  7119. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7120. return 0;
  7121. }
  7122. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7123. return 1;
  7124. }
  7125. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7126. if (!lua_interface)
  7127. return 0;
  7128. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7129. if (!luaspell) {
  7130. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7131. return 0;
  7132. }
  7133. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7134. return 1;
  7135. }
  7136. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7137. if (!lua_interface)
  7138. return 0;
  7139. Spawn* spawn = lua_interface->GetSpawn(state);
  7140. Spawn* target = lua_interface->GetSpawn(state, 2);
  7141. if (!spawn) {
  7142. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7143. return 0;
  7144. }
  7145. if (!spawn->IsEntity()) {
  7146. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7147. return 0;
  7148. }
  7149. if (!target) {
  7150. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7151. return 0;
  7152. }
  7153. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7154. return 1;
  7155. }
  7156. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7157. if (!lua_interface)
  7158. return 0;
  7159. Spawn* spawn = lua_interface->GetSpawn(state);
  7160. Spawn* target = lua_interface->GetSpawn(state, 2);
  7161. if (!spawn) {
  7162. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7163. return 0;
  7164. }
  7165. if (!spawn->IsEntity()) {
  7166. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7167. return 0;
  7168. }
  7169. if (!target) {
  7170. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7171. return 0;
  7172. }
  7173. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7174. return 1;
  7175. }
  7176. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7177. if (!lua_interface)
  7178. return 0;
  7179. Item* item = lua_interface->GetItem(state);
  7180. if (!item) {
  7181. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7182. return 0;
  7183. }
  7184. lua_interface->SetInt32Value(state, item->details.count);
  7185. return 1;
  7186. }
  7187. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7188. if (!lua_interface)
  7189. return 0;
  7190. Item* item = lua_interface->GetItem(state);
  7191. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7192. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7193. if (!item) {
  7194. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7195. return 0;
  7196. }
  7197. if (!owner) {
  7198. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (!owner->IsPlayer()) {
  7202. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. if (item->stack_count < new_count) {
  7206. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7207. return 0;
  7208. }
  7209. if (new_count > 0) {
  7210. item->details.count = new_count;
  7211. item->save_needed = true;
  7212. }
  7213. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7214. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7215. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7216. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7217. else
  7218. {
  7219. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7220. return 0;
  7221. }
  7222. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7223. if (!client)
  7224. return 0;
  7225. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7226. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7227. if (app)
  7228. client->QueuePacket(app);
  7229. return 0;
  7230. }
  7231. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7232. if (!lua_interface)
  7233. return 0;
  7234. int32 time = lua_interface->GetInt32Value(state);
  7235. string function = lua_interface->GetStringValue(state, 2);
  7236. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7237. Spawn* target = lua_interface->GetSpawn(state, 4);
  7238. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7239. if (time == 0) {
  7240. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7241. return 0;
  7242. }
  7243. if (function.length() == 0) {
  7244. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7245. return 0;
  7246. }
  7247. if (!spell) {
  7248. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. SpellScriptTimer* timer = new SpellScriptTimer;
  7252. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7253. #ifdef WIN32
  7254. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7255. #else
  7256. bzero(timer, sizeof(SpellScriptTimer));
  7257. #endif*/
  7258. timer->caster = 0;
  7259. timer->deleteWhenDone = false;
  7260. timer->target = 0;
  7261. timer->time = Timer::GetCurrentTime2() + time;
  7262. timer->customFunction = function;
  7263. timer->spell = spell;
  7264. if (caster)
  7265. timer->caster = caster->GetID();
  7266. if (target)
  7267. timer->target = target->GetID();
  7268. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7269. return 0;
  7270. }
  7271. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7272. if (!lua_interface)
  7273. return 0;
  7274. float hp_perc = lua_interface->GetFloatValue(state);
  7275. float power_perc = lua_interface->GetFloatValue(state, 2);
  7276. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7277. Spawn* target = lua_interface->GetSpawn(state, 4);
  7278. string heal_name = lua_interface->GetStringValue(state, 5);
  7279. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7280. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7281. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7282. if (!spell) {
  7283. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7284. return 0;
  7285. }
  7286. Entity* caster = spell->caster;
  7287. if (!caster) {
  7288. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7289. return 0;
  7290. }
  7291. Client* client = 0;
  7292. PendingResurrection* rez = 0;
  7293. ZoneServer* zone = spell->caster->GetZone();
  7294. if (!target) {
  7295. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7296. if (spell->targets.size() > 0) {
  7297. vector<int32> spell_targets = spell->targets;
  7298. for (int8 i = 0; i < spell_targets.size(); i++) {
  7299. target = zone->GetSpawnByID(spell_targets.at(i));
  7300. if (!target)
  7301. continue;
  7302. if (!target->IsPlayer())
  7303. continue;
  7304. client = target->GetZone()->GetClientBySpawn(target);
  7305. if (!client)
  7306. continue;
  7307. rez = client->GetCurrentRez();
  7308. if (rez->active)
  7309. continue;
  7310. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7311. rez->active = true;
  7312. rez->caster = caster;
  7313. rez->expire_timer = new Timer;
  7314. int32 duration = spell->spell->GetSpellDuration();
  7315. rez->expire_timer->Start(duration * 100);
  7316. rez->hp_perc = hp_perc;
  7317. rez->mp_perc = power_perc;
  7318. rez->range = spell->spell->GetSpellData()->range;
  7319. rez->spell_name = spell->spell->GetName();
  7320. if (heal_name.length() > 0)
  7321. rez->heal_name = heal_name;
  7322. else
  7323. rez->heal_name = rez->spell_name;
  7324. rez->no_calcs = no_calcs;
  7325. rez->crit_mod = crit_mod;
  7326. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7327. if (send_window)
  7328. client->SendResurrectionWindow();
  7329. else {
  7330. target->GetZone()->ResurrectSpawn(target, client);
  7331. rez->should_delete = true;
  7332. }
  7333. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7334. }
  7335. }
  7336. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7337. }
  7338. else {
  7339. client = target->GetZone()->GetClientBySpawn(target);
  7340. if (!client)
  7341. return 0;
  7342. rez = client->GetCurrentRez();
  7343. if (rez->active)
  7344. return 0;
  7345. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7346. rez->active = true;
  7347. rez->caster = caster;
  7348. rez->expire_timer = new Timer;
  7349. int32 duration = spell->spell->GetSpellDuration();
  7350. rez->expire_timer->Start(duration * 100);
  7351. rez->hp_perc = hp_perc;
  7352. rez->mp_perc = power_perc;
  7353. rez->range = spell->spell->GetSpellData()->range;
  7354. rez->spell_name = spell->spell->GetName();
  7355. if (heal_name.length() > 0)
  7356. rez->heal_name = heal_name;
  7357. else
  7358. rez->heal_name = rez->spell_name;
  7359. rez->no_calcs = no_calcs;
  7360. rez->crit_mod = crit_mod;
  7361. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7362. if (send_window)
  7363. client->SendResurrectionWindow();
  7364. else {
  7365. target->GetZone()->ResurrectSpawn(target, client);
  7366. rez->should_delete = true;
  7367. }
  7368. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7369. }
  7370. return 0;
  7371. }
  7372. int EQ2Emu_lua_SetVision(lua_State* state) {
  7373. if (!lua_interface)
  7374. return 0;
  7375. Spawn* spawn = lua_interface->GetSpawn(state);
  7376. int8 vision = lua_interface->GetInt8Value(state, 2);
  7377. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7378. if (!spawn) {
  7379. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7380. return 0;
  7381. }
  7382. if (!spawn->IsEntity()) {
  7383. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7384. return 0;
  7385. }
  7386. if (spell && spell->targets.size() > 0) {
  7387. ZoneServer* zone = spell->caster->GetZone();
  7388. for (int8 i = 0; i < spell->targets.size(); i++) {
  7389. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7390. if (target->IsEntity()) {
  7391. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7392. if (target->IsPlayer())
  7393. ((Player*)target)->SetCharSheetChanged(true);
  7394. }
  7395. }
  7396. }
  7397. else {
  7398. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7399. if (spawn->IsPlayer())
  7400. ((Player*)spawn)->SetCharSheetChanged(true);
  7401. }
  7402. return 0;
  7403. }
  7404. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7405. if (!lua_interface)
  7406. return 0;
  7407. Spawn* spawn = lua_interface->GetSpawn(state);
  7408. float intensity = lua_interface->GetFloatValue(state, 2);
  7409. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7410. if (!spawn) {
  7411. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7412. return 0;
  7413. }
  7414. if (!spawn->IsEntity()) {
  7415. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7416. return 0;
  7417. }
  7418. if (spell && spell->targets.size() > 0) {
  7419. ZoneServer* zone = spell->caster->GetZone();
  7420. for (int8 i = 0; i < spell->targets.size(); i++) {
  7421. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7422. if (target && target->IsEntity()) {
  7423. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7424. if (target->IsPlayer())
  7425. ((Player*)target)->SetCharSheetChanged(true);
  7426. }
  7427. }
  7428. }
  7429. else {
  7430. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7431. if (spawn->IsPlayer())
  7432. ((Player*)spawn)->SetCharSheetChanged(true);
  7433. }
  7434. return 0;
  7435. }
  7436. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7437. if (!lua_interface)
  7438. return 0;
  7439. Spawn* spawn = lua_interface->GetSpawn(state);
  7440. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7441. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7442. if (!spawn) {
  7443. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7444. return 0;
  7445. }
  7446. if (!spawn->IsEntity()) {
  7447. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7448. return 0;
  7449. }
  7450. if (spell && spell->targets.size() > 0) {
  7451. ZoneServer* zone = spell->caster->GetZone();
  7452. for (int8 i = 0; i < spell->targets.size(); i++) {
  7453. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7454. if (target->IsEntity()) {
  7455. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7456. if (target->IsPlayer())
  7457. ((Player*)target)->SetCharSheetChanged(true);
  7458. }
  7459. }
  7460. }
  7461. else {
  7462. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7463. if (spawn->IsPlayer())
  7464. ((Player*)spawn)->SetCharSheetChanged(true);
  7465. }
  7466. return 0;
  7467. }
  7468. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7469. if (!lua_interface)
  7470. return 0;
  7471. Item* item = lua_interface->GetItem(state);
  7472. int8 type = lua_interface->GetInt32Value(state, 2);
  7473. if (!item) {
  7474. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7475. return 0;
  7476. }
  7477. if (type == 1)
  7478. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7479. else if (type == 2)
  7480. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7481. return 1;
  7482. }
  7483. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7484. if (!lua_interface)
  7485. return 0;
  7486. Spawn* target = lua_interface->GetSpawn(state);
  7487. float val = lua_interface->GetFloatValue(state, 2);
  7488. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7489. // Added from Gangrenous post
  7490. if (spell && spell->resisted)
  7491. return 0;
  7492. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7493. if (val > 1.0f)
  7494. val = 1.0f - (val / 100.0f);
  7495. if (spell && spell->spell && spell->targets.size() > 0) {
  7496. ZoneServer* zone = spell->caster->GetZone();
  7497. for (int32 i = 0; i != spell->targets.size(); i++) {
  7498. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7499. if (spawn && spawn->IsEntity()) {
  7500. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7501. if (spawn->IsPlayer())
  7502. ((Player*)spawn)->SetCharSheetChanged(true);
  7503. }
  7504. }
  7505. }
  7506. else {
  7507. if (target && target->IsEntity()) {
  7508. ((Entity*)target)->SetSpeedMultiplier(val);
  7509. if (target->IsPlayer())
  7510. ((Player*)target)->SetCharSheetChanged(true);
  7511. }
  7512. }
  7513. return 0;
  7514. }
  7515. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Spawn* spawn = lua_interface->GetSpawn(state);
  7519. int16 model = lua_interface->GetInt16Value(state, 2);
  7520. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7521. if (spell && spell->spell && spell->targets.size() > 0) {
  7522. ZoneServer* zone = spell->caster->GetZone();
  7523. for (int32 i = 0; i < spell->targets.size(); i++) {
  7524. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7525. if (target)
  7526. target->SetIllusionModel(model);
  7527. }
  7528. }
  7529. else {
  7530. if (!spawn) {
  7531. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7532. return 0;
  7533. }
  7534. spawn->SetIllusionModel(model);
  7535. }
  7536. return 0;
  7537. }
  7538. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7539. if (!lua_interface)
  7540. return 0;
  7541. Spawn* spawn = lua_interface->GetSpawn(state);
  7542. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7543. if (spell && spell->spell && spell->targets.size() > 0) {
  7544. ZoneServer* zone = spell->caster->GetZone();
  7545. for (int32 i = 0; i < spell->targets.size(); i++) {
  7546. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7547. if (target)
  7548. target->SetIllusionModel(0);
  7549. }
  7550. }
  7551. else {
  7552. if (!spawn) {
  7553. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7554. return 0;
  7555. }
  7556. spawn->SetIllusionModel(0);
  7557. }
  7558. return 0;
  7559. }
  7560. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7561. if (!lua_interface)
  7562. return 0;
  7563. Spawn* caster = lua_interface->GetSpawn(state);
  7564. Spawn* target = lua_interface->GetSpawn(state, 2);
  7565. float chance = lua_interface->GetFloatValue(state, 3);
  7566. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7567. if (!caster) {
  7568. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7569. return 0;
  7570. }
  7571. if (!caster->IsEntity()) {
  7572. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7573. return 0;
  7574. }
  7575. if (!target) {
  7576. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7577. return 0;
  7578. }
  7579. if (!target->IsEntity()) {
  7580. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7581. return 0;
  7582. }
  7583. if (chance <= 0) {
  7584. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7585. return 0;
  7586. }
  7587. if (!spell) {
  7588. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7589. return 0;
  7590. }
  7591. if (((Entity*)caster)->GetThreatTransfer()) {
  7592. return 0;
  7593. }
  7594. ThreatTransfer* transfer = new ThreatTransfer;
  7595. transfer->Target = target->GetID();
  7596. transfer->Amount = chance;
  7597. transfer->Spell = spell;
  7598. ((Entity*)caster)->SetThreatTransfer(transfer);
  7599. return 0;
  7600. }
  7601. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7602. if (!lua_interface)
  7603. return 0;
  7604. Spawn* spawn = lua_interface->GetSpawn(state);
  7605. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7606. if (!spawn) {
  7607. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7608. return 0;
  7609. }
  7610. if (!spell) {
  7611. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7612. return 0;
  7613. }
  7614. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7615. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7616. ((Entity*)spawn)->SetThreatTransfer(0);
  7617. safe_delete(transfer);
  7618. }
  7619. return 0;
  7620. }
  7621. int EQ2Emu_lua_CureByType(lua_State* state) {
  7622. if (!lua_interface)
  7623. return 0;
  7624. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7625. if (!spell) {
  7626. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7627. return 0;
  7628. }
  7629. int8 cure_count = lua_interface->GetInt8Value(state);
  7630. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7631. string cure_name = lua_interface->GetStringValue(state, 3);
  7632. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7633. Spawn* target = lua_interface->GetSpawn(state, 5);
  7634. if (target) {
  7635. if (!target->IsEntity()) {
  7636. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7637. return 0;
  7638. }
  7639. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7640. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7641. }
  7642. else {
  7643. ZoneServer* zone = spell->caster->GetZone();
  7644. vector<int32> targets = spell->targets;
  7645. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7646. for (int8 i = 0; i < targets.size(); i++) {
  7647. target = zone->GetSpawnByID(targets.at(i));
  7648. if (!target || !target->IsEntity())
  7649. continue;
  7650. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7651. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7652. }
  7653. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7654. }
  7655. return 0;
  7656. }
  7657. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7658. if (!lua_interface)
  7659. return 0;
  7660. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7661. if (!spell) {
  7662. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7663. return 0;
  7664. }
  7665. int8 cure_count = lua_interface->GetInt8Value(state);
  7666. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7667. string cure_name = lua_interface->GetStringValue(state, 3);
  7668. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7669. Spawn* target = lua_interface->GetSpawn(state, 5);
  7670. if (target) {
  7671. if (!target->IsEntity()) {
  7672. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7673. return 0;
  7674. }
  7675. if (((Entity*)target)->GetDetCount() > 0)
  7676. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7677. }
  7678. else {
  7679. ZoneServer* zone = spell->caster->GetZone();
  7680. vector<int32> targets = spell->targets;
  7681. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7682. for (int8 i = 0; i < targets.size(); i++) {
  7683. target = zone->GetSpawnByID(targets.at(i));
  7684. if (!target || !target->IsEntity())
  7685. continue;
  7686. if (((Entity*)target)->GetDetCount() > 0)
  7687. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7688. }
  7689. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7690. }
  7691. return 0;
  7692. }
  7693. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7694. if (!lua_interface)
  7695. return 0;
  7696. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7697. if (!spell) {
  7698. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7699. return 0;
  7700. }
  7701. if (!spell->caster) {
  7702. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. if (!spell->caster->GetZone()) {
  7706. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7707. return 0;
  7708. }
  7709. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7710. return 0;
  7711. }
  7712. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7713. if (!lua_interface)
  7714. return 0;
  7715. Spawn* spawn = lua_interface->GetSpawn(state);
  7716. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7717. if (!spell) {
  7718. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7719. return 0;
  7720. }
  7721. if (spawn && spawn->IsEntity())
  7722. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7723. else {
  7724. ZoneServer* zone = spell->caster->GetZone();
  7725. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7726. for (int32 i = 0; i < spell->targets.size(); i++) {
  7727. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7728. if (!spawn || !spawn->IsEntity())
  7729. continue;
  7730. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7731. }
  7732. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7733. }
  7734. return 0;
  7735. }
  7736. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7737. if (!lua_interface)
  7738. return 0;
  7739. Spawn* spawn = lua_interface->GetSpawn(state);
  7740. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7741. if (!spell) {
  7742. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7743. return 0;
  7744. }
  7745. if (spawn && spawn->IsEntity())
  7746. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7747. else {
  7748. ZoneServer* zone = spell->caster->GetZone();
  7749. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7750. for (int32 i = 0; i < spell->targets.size(); i++) {
  7751. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7752. if (!spawn || !spawn->IsEntity())
  7753. continue;
  7754. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7755. }
  7756. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7757. }
  7758. return 0;
  7759. }
  7760. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7761. if (!lua_interface)
  7762. return 0;
  7763. Spawn* caster = lua_interface->GetSpawn(state);
  7764. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7765. if (!caster) {
  7766. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7767. return 0;
  7768. }
  7769. if (!caster->IsPlayer()) {
  7770. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7771. return 0;
  7772. }
  7773. Spawn* target = caster->GetTarget();
  7774. if (!target) {
  7775. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7776. return 0;
  7777. }
  7778. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7779. if (!client) {
  7780. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7781. return 0;
  7782. }
  7783. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7784. if (ho) {
  7785. ho->SetTarget(target->GetID());
  7786. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7787. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7788. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7789. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7790. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7791. deque<GroupMemberInfo*>::iterator itr;
  7792. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7793. if (group)
  7794. {
  7795. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7796. deque<GroupMemberInfo*>* members = group->GetMembers();
  7797. for (itr = members->begin(); itr != members->end(); itr++) {
  7798. if ((*itr)->client)
  7799. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7800. }
  7801. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7802. }
  7803. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7804. }
  7805. else
  7806. safe_delete(ho);
  7807. }
  7808. else {
  7809. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7810. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7811. }
  7812. else
  7813. safe_delete(ho);
  7814. }
  7815. }
  7816. return 0;
  7817. }
  7818. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7819. if (!lua_interface)
  7820. return 0;
  7821. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7822. if (!spell) {
  7823. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7824. return 0;
  7825. }
  7826. int16 triggerCount = lua_interface->GetInt16Value(state);
  7827. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7828. if (!triggerCount) {
  7829. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. spell->num_triggers = triggerCount;
  7833. spell->had_triggers = true;
  7834. spell->cancel_after_all_triggers = cancel_after_triggers;
  7835. return 0;
  7836. }
  7837. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7838. if (!lua_interface)
  7839. return 0;
  7840. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7841. if (!spell) {
  7842. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. lua_interface->SetInt32Value(state, spell->num_triggers);
  7846. return 1;
  7847. }
  7848. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7849. if (!lua_interface)
  7850. return 0;
  7851. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7852. if (!spell) {
  7853. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7854. return 0;
  7855. }
  7856. int16 remove_count = lua_interface->GetInt16Value(state);
  7857. if (!remove_count)
  7858. remove_count = 1;
  7859. if (remove_count >= spell->num_triggers) {
  7860. spell->num_triggers = 0;
  7861. if (spell->cancel_after_all_triggers)
  7862. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7863. }
  7864. else {
  7865. spell->num_triggers -= remove_count;
  7866. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7867. }
  7868. return 0;
  7869. }
  7870. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7871. if (!lua_interface)
  7872. return 0;
  7873. Spawn* spawn = lua_interface->GetSpawn(state);
  7874. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7875. if (!spawn) {
  7876. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7877. return 0;
  7878. }
  7879. if (!copy_spawn) {
  7880. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7881. return 0;
  7882. }
  7883. spawn->CopySpawnAppearance(copy_spawn);
  7884. return 0;
  7885. }
  7886. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7887. Spawn* spawn = lua_interface->GetSpawn(state);
  7888. int8 type = lua_interface->GetInt8Value(state, 2);
  7889. if (!spawn) {
  7890. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7891. return 0;
  7892. }
  7893. else if (!spawn->IsEntity()) {
  7894. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7895. return 0;
  7896. }
  7897. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7898. return 1;
  7899. }
  7900. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7901. if (!lua_interface)
  7902. return 0;
  7903. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7904. int8 type = lua_interface->GetInt8Value(state);
  7905. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7906. if (!spell) {
  7907. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7908. return 0;
  7909. }
  7910. if (spawn) {
  7911. if (!spawn->IsEntity()) {
  7912. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7913. return 0;
  7914. }
  7915. Entity* entity = ((Entity*)spawn);
  7916. entity->AddImmunity(spell, type);
  7917. }
  7918. else {
  7919. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7920. for (int8 i = 0; i < spell->targets.size(); i++) {
  7921. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7922. if (!spawn || !spawn->IsEntity())
  7923. continue;
  7924. Entity* entity = ((Entity*)spawn);
  7925. entity->AddImmunity(spell, type);
  7926. }
  7927. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7928. }
  7929. return 0;
  7930. }
  7931. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7932. if (!lua_interface)
  7933. return 0;
  7934. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7935. int8 type = lua_interface->GetInt8Value(state);
  7936. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7937. if (!spell) {
  7938. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. if (spawn) {
  7942. if (!spawn->IsEntity()) {
  7943. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. Entity* entity = ((Entity*)spawn);
  7947. entity->RemoveImmunity(spell, type);
  7948. }
  7949. else {
  7950. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7951. for (int8 i = 0; i < spell->targets.size(); i++) {
  7952. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7953. if (!spawn || !spawn->IsEntity())
  7954. continue;
  7955. Entity* entity = ((Entity*)spawn);
  7956. entity->RemoveImmunity(spell, type);
  7957. }
  7958. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7959. }
  7960. return 0;
  7961. }
  7962. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7963. if (!lua_interface)
  7964. return 0;
  7965. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7966. if (!spell) {
  7967. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7968. return 0;
  7969. }
  7970. float snare = lua_interface->GetFloatValue(state);
  7971. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7972. // convert the val to the speed multipler value (100 - val)
  7973. float val = 100.0 - snare;
  7974. val /= 100.0;
  7975. if (spawn) {
  7976. if (!spawn->IsEntity()) {
  7977. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7978. return 0;
  7979. }
  7980. ((Entity*)spawn)->SetSnareValue(spell, val);
  7981. }
  7982. else {
  7983. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7984. for (int8 i = 0; i < spell->targets.size(); i++) {
  7985. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7986. if (!spawn || !spawn->IsEntity())
  7987. continue;
  7988. ((Entity*)spawn)->SetSnareValue(spell, val);
  7989. }
  7990. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7991. }
  7992. return 0;
  7993. }
  7994. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7995. if (!lua_interface)
  7996. return 0;
  7997. Spawn* spawn = lua_interface->GetSpawn(state);
  7998. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7999. if (!spawn) {
  8000. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8001. return 0;
  8002. }
  8003. if (race_id == 0) {
  8004. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8005. return 0;
  8006. }
  8007. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8008. return 1;
  8009. }
  8010. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8011. if (!lua_interface)
  8012. return 0;
  8013. Spawn* spawn = lua_interface->GetSpawn(state);
  8014. if (!spawn) {
  8015. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8016. return 0;
  8017. }
  8018. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8019. return 1;
  8020. }
  8021. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8022. if (!lua_interface)
  8023. return 0;
  8024. Spawn* spawn = lua_interface->GetSpawn(state);
  8025. if (!spawn) {
  8026. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8030. return 1;
  8031. }
  8032. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8033. if (!lua_interface)
  8034. return 0;
  8035. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8036. if (!spell) {
  8037. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8038. return 0;
  8039. }
  8040. lua_interface->SetStringValue(state, spell->spell->GetName());
  8041. return 1;
  8042. }
  8043. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8044. if (!lua_interface)
  8045. return 0;
  8046. Quest* quest = lua_interface->GetQuest(state);
  8047. if (!quest) {
  8048. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8049. return 0;
  8050. }
  8051. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8052. return 1;
  8053. }
  8054. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8055. if (!lua_interface)
  8056. return 0;
  8057. Quest* quest = lua_interface->GetQuest(state);
  8058. int32 flags = lua_interface->GetInt32Value(state, 2);
  8059. if (!quest) {
  8060. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8061. return 0;
  8062. }
  8063. quest->SetQuestFlags(flags);
  8064. return 0;
  8065. }
  8066. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8067. if (!lua_interface)
  8068. return 0;
  8069. Quest* quest = lua_interface->GetQuest(state);
  8070. Spawn* player = lua_interface->GetSpawn(state, 2);
  8071. int32 step = lua_interface->GetInt32Value(state, 3);
  8072. int32 duration = lua_interface->GetInt32Value(state, 4);
  8073. string action = lua_interface->GetStringValue(state, 5);
  8074. if (!quest) {
  8075. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. if (!player) {
  8079. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8080. return 0;
  8081. }
  8082. if (!player->IsPlayer()) {
  8083. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8084. return 0;
  8085. }
  8086. if (step == 0) {
  8087. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8088. return 0;
  8089. }
  8090. if (duration == 0) {
  8091. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. if (action.length() == 0) {
  8095. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8096. return 0;
  8097. }
  8098. Client* client = player->GetZone()->GetClientBySpawn(player);
  8099. if (!client) {
  8100. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8101. return 0;
  8102. }
  8103. quest->SetTimerStep(step);
  8104. quest->AddFailedAction(step, action);
  8105. quest->SetStepTimer(duration);
  8106. client->AddQuestTimer(quest->GetQuestID());
  8107. return 0;
  8108. }
  8109. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8110. if (!lua_interface)
  8111. return 0;
  8112. Quest* quest = lua_interface->GetQuest(state);
  8113. Spawn* player = lua_interface->GetSpawn(state, 2);
  8114. if (!quest) {
  8115. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. if (!player) {
  8119. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8120. return 0;
  8121. }
  8122. if (!player->IsPlayer()) {
  8123. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8124. return 0;
  8125. }
  8126. Client* client = player->GetZone()->GetClientBySpawn(player);
  8127. if (!client) {
  8128. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8129. return 0;
  8130. }
  8131. quest->SetTimerStep(0);
  8132. quest->SetStepTimer(0);
  8133. client->RemoveQuestTimer(quest->GetQuestID());
  8134. return 0;
  8135. }
  8136. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8137. if (!lua_interface)
  8138. return 0;
  8139. Spawn* player = lua_interface->GetSpawn(state);
  8140. Quest* quest = lua_interface->GetQuest(state, 2);
  8141. int32 step = lua_interface->GetInt32Value(state, 3);
  8142. if (!player) {
  8143. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8144. return 0;
  8145. }
  8146. if (!player->IsPlayer()) {
  8147. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8148. return 0;
  8149. }
  8150. if (!quest) {
  8151. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8152. return 0;
  8153. }
  8154. if (step == 0) {
  8155. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. Client* client = player->GetZone()->GetClientBySpawn(player);
  8159. if (!client) {
  8160. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8161. return 0;
  8162. }
  8163. if (quest->RemoveQuestStep(step, client)) {
  8164. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8165. client->GetCurrentZone()->SendQuestUpdates(client);
  8166. }
  8167. else
  8168. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8169. return 0;
  8170. }
  8171. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8172. if (!lua_interface)
  8173. return 0;
  8174. Quest* quest = lua_interface->GetQuest(state, 1);
  8175. int32 step = lua_interface->GetInt32Value(state, 2);
  8176. string desc = lua_interface->GetStringValue(state, 3);
  8177. string task_group = lua_interface->GetStringValue(state, 4);
  8178. if (!quest) {
  8179. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. if (step == 0) {
  8183. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8184. return 0;
  8185. }
  8186. QuestStep* quest_step = quest->GetQuestStep(step);
  8187. if (!quest_step) {
  8188. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. quest_step->SetStepProgress(0);
  8192. quest_step->SetTaskGroup(task_group);
  8193. quest_step->SetDescription(desc);
  8194. return 0;
  8195. }
  8196. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8197. if (!lua_interface)
  8198. return 0;
  8199. Quest* quest = lua_interface->GetQuest(state);
  8200. int32 step = lua_interface->GetInt32Value(state, 2);
  8201. string action = lua_interface->GetStringValue(state, 3);
  8202. if (!quest) {
  8203. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8204. return 0;
  8205. }
  8206. if (step == 0) {
  8207. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (action.length() == 0) {
  8211. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8212. return 0;
  8213. }
  8214. quest->AddFailedAction(step, action);
  8215. return 0;
  8216. }
  8217. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8218. if (!lua_interface)
  8219. return 0;
  8220. Spawn* player = lua_interface->GetSpawn(state);
  8221. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8222. int32 step = lua_interface->GetInt32Value(state, 3);
  8223. if (!player) {
  8224. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8225. return 0;
  8226. }
  8227. if (!player->IsPlayer()) {
  8228. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8229. return 0;
  8230. }
  8231. if (quest_id == 0) {
  8232. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8233. return 0;
  8234. }
  8235. if (step == 0) {
  8236. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8240. if (!quest) {
  8241. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8242. return 0;
  8243. }
  8244. quest->StepFailed(step);
  8245. return 0;
  8246. }
  8247. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8248. if (!lua_interface)
  8249. return 0;
  8250. Spawn* player = lua_interface->GetSpawn(state);
  8251. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8252. if (!player) {
  8253. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8254. return 0;
  8255. }
  8256. if (!player->IsPlayer()) {
  8257. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8258. return 0;
  8259. }
  8260. if (quest_id == 0) {
  8261. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8262. return 0;
  8263. }
  8264. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8265. if (!quest) {
  8266. lua_interface->SetInt32Value(state, 0);
  8267. return 1;
  8268. }
  8269. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8270. return 1;
  8271. }
  8272. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8273. if (!lua_interface)
  8274. return 0;
  8275. string name = lua_interface->GetStringValue(state);
  8276. string value = lua_interface->GetStringValue(state, 2);
  8277. string comment = lua_interface->GetStringValue(state, 3);
  8278. if (name.length() == 0) {
  8279. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8280. return 0;
  8281. }
  8282. if (value.length() == 0) {
  8283. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8284. return 0;
  8285. }
  8286. string varname = string("lua_").append(name);
  8287. Variable* var = variables.FindVariable(varname);
  8288. if (var)
  8289. var->SetValue(value.c_str());
  8290. else {
  8291. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8292. variables.AddVariable(var);
  8293. }
  8294. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8295. return 0;
  8296. }
  8297. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8298. if (!lua_interface)
  8299. return 0;
  8300. string name = lua_interface->GetStringValue(state);
  8301. if (name.length() == 0) {
  8302. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8303. return 0;
  8304. }
  8305. string varname = string("lua_").append(name);
  8306. Variable* var = variables.FindVariable(varname);
  8307. if (var)
  8308. lua_interface->SetStringValue(state, var->GetValue());
  8309. else
  8310. lua_interface->SetStringValue(state, "NULL");
  8311. return 1;
  8312. }
  8313. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8314. if (!lua_interface)
  8315. return 0;
  8316. Spawn* player = lua_interface->GetSpawn(state);
  8317. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8318. if (!player) {
  8319. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8320. return 0;
  8321. }
  8322. if (!player->IsPlayer()) {
  8323. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8324. return 0;
  8325. }
  8326. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8327. return 1;
  8328. }
  8329. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8330. if (!lua_interface)
  8331. return 0;
  8332. Spawn* player = lua_interface->GetSpawn(state);
  8333. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8334. if (!player) {
  8335. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. if (!player->IsPlayer()) {
  8339. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. Language* language = master_languages_list.GetLanguage(language_id);
  8343. if (language)
  8344. {
  8345. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8346. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8347. }
  8348. return 0;
  8349. }
  8350. int EQ2Emu_lua_IsNight(lua_State* state) {
  8351. if (!lua_interface)
  8352. return 0;
  8353. ZoneServer* zone = lua_interface->GetZone(state);
  8354. if (!zone) {
  8355. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8356. return 0;
  8357. }
  8358. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8359. return 1;
  8360. }
  8361. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8362. if (!lua_interface)
  8363. return 0;
  8364. Spawn* spawn = lua_interface->GetSpawn(state);
  8365. if (!spawn) {
  8366. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. if (!spawn->IsWidget()) {
  8370. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. ((Widget*)spawn)->SetMultiFloorLift(true);
  8374. if (spawn->GetZone())
  8375. spawn->GetZone()->AddTransportSpawn(spawn);
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. Spawn* player = lua_interface->GetSpawn(state);
  8382. int32 path = lua_interface->GetInt32Value(state, 2);
  8383. if (!player) {
  8384. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. if (!player->IsPlayer()) {
  8388. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. if (path == 0) {
  8392. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. Client* client = player->GetZone()->GetClientBySpawn(player);
  8396. if (!client) {
  8397. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8398. return 0;
  8399. }
  8400. client->SendFlightAutoMount(path);
  8401. return 0;
  8402. }
  8403. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8404. if (!lua_interface)
  8405. return 0;
  8406. Spawn* player = lua_interface->GetSpawn(state);
  8407. if (!player) {
  8408. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8409. return 0;
  8410. }
  8411. if (!player->IsPlayer()) {
  8412. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8413. return 0;
  8414. }
  8415. Client* client = player->GetZone()->GetClientBySpawn(player);
  8416. if (!client) {
  8417. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8418. return 0;
  8419. }
  8420. client->EndAutoMount();
  8421. return 0;
  8422. }
  8423. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8424. if (!lua_interface)
  8425. return 0;
  8426. Spawn* player = lua_interface->GetSpawn(state);
  8427. if (!player) {
  8428. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8429. return 0;
  8430. }
  8431. if (!player->IsPlayer()) {
  8432. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8433. return 0;
  8434. }
  8435. Client* client = player->GetZone()->GetClientBySpawn(player);
  8436. if (!client) {
  8437. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8438. return 0;
  8439. }
  8440. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8441. return 1;
  8442. }
  8443. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8444. if (!lua_interface)
  8445. return 0;
  8446. Spawn* player = lua_interface->GetSpawn(state);
  8447. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8448. int32 value = lua_interface->GetInt32Value(state, 3);
  8449. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8450. if (!player) {
  8451. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!player->IsPlayer()) {
  8455. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8459. return 0;
  8460. }
  8461. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8462. if (!lua_interface)
  8463. return 0;
  8464. Spawn* player = lua_interface->GetSpawn(state);
  8465. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8466. if (!player) {
  8467. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8468. return 0;
  8469. }
  8470. if (!player->IsPlayer()) {
  8471. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8472. return 0;
  8473. }
  8474. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8475. if (!hd)
  8476. return 0;
  8477. lua_interface->SetInt32Value(state, hd->Value);
  8478. lua_interface->SetInt32Value(state, hd->Value2);
  8479. return 2;
  8480. }
  8481. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8482. if (!lua_interface)
  8483. return 0;
  8484. Spawn* spawn = lua_interface->GetSpawn(state);
  8485. int32 grid = lua_interface->GetInt32Value(state, 2);
  8486. if (!spawn) {
  8487. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8488. return 0;
  8489. }
  8490. if (grid == 0) {
  8491. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8495. return 0;
  8496. }
  8497. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8498. if (!lua_interface)
  8499. return 0;
  8500. Spawn* spawn = lua_interface->GetSpawn(state);
  8501. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8502. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8503. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8504. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8505. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8506. if (!spawn) {
  8507. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. //Add this quest to the list of required quests for this spawn
  8511. spawn->SetRequiredHistory(event_id, value1, value2);
  8512. //If private spawn value set
  8513. if (private_spawn) {
  8514. //Set the spawn to be private when not granted access via history
  8515. spawn->AddAllowAccessSpawn(spawn);
  8516. spawn->SetPrivateQuestSpawn(true);
  8517. }
  8518. //This value will override vis_flags in the vis packet
  8519. if (flag_override > 0)
  8520. spawn->SetQuestsRequiredOverride(flag_override);
  8521. return 0;
  8522. }
  8523. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8524. if (!lua_interface)
  8525. return 0;
  8526. Spawn* player = lua_interface->GetSpawn(state);
  8527. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8528. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8529. if (!player) {
  8530. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8531. return 0;
  8532. }
  8533. if (!player->IsPlayer()) {
  8534. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8535. return 0;
  8536. }
  8537. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8538. return 1;
  8539. }
  8540. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8541. if (!lua_interface)
  8542. return 0;
  8543. Spawn* player = lua_interface->GetSpawn(state);
  8544. int8 level = lua_interface->GetInt8Value(state, 2);
  8545. if (!player) {
  8546. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. if (!player->IsPlayer()) {
  8550. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. if (level == 0) {
  8554. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. Client* client = player->GetZone()->GetClientBySpawn(player);
  8558. if (!client) {
  8559. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8563. return 0;
  8564. }
  8565. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8566. if (!lua_interface)
  8567. return 0;
  8568. Spawn* player = lua_interface->GetSpawn(state);
  8569. int32 amount = lua_interface->GetInt32Value(state, 2);
  8570. if (!player) {
  8571. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8572. return 0;
  8573. }
  8574. if (!player->IsPlayer()) {
  8575. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8576. return 0;
  8577. }
  8578. if (amount == 0) {
  8579. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8580. return 0;
  8581. }
  8582. ((Player*)player)->AddCoins(amount);
  8583. return 0;
  8584. }
  8585. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8586. if (!lua_interface)
  8587. return 0;
  8588. Spawn* player = lua_interface->GetSpawn(state);
  8589. int32 amount = lua_interface->GetInt32Value(state, 2);
  8590. if (!player) {
  8591. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8592. return 0;
  8593. }
  8594. if (!player->IsPlayer()) {
  8595. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8596. return 0;
  8597. }
  8598. if (amount == 0) {
  8599. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8600. return 0;
  8601. }
  8602. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8603. return 1;
  8604. }
  8605. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8606. if (!lua_interface)
  8607. return 0;
  8608. ZoneServer* zone = lua_interface->GetZone(state);
  8609. if (!zone) {
  8610. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8611. return 0;
  8612. }
  8613. vector<Entity*> players = zone->GetPlayers();
  8614. if (players.size() == 0)
  8615. return 0;
  8616. lua_createtable(state, players.size(), 0);
  8617. int newTable = lua_gettop(state);
  8618. for (int32 i = 0; i < players.size(); i++) {
  8619. lua_interface->SetSpawnValue(state, players.at(i));
  8620. lua_rawseti(state, newTable, i + 1);
  8621. }
  8622. return 1;
  8623. }
  8624. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8625. if (!lua_interface)
  8626. return 0;
  8627. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8628. if (!zone) {
  8629. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8630. return 0;
  8631. }
  8632. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8633. //Map of <placement_id, location_id>
  8634. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8635. map<int32, int32>::iterator itr;
  8636. vector<Spawn*> group;
  8637. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8638. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8639. if (!location) {
  8640. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8641. return 0;
  8642. }
  8643. Spawn* spawn = 0;
  8644. if (location->entities[0]) {
  8645. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8646. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8647. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8648. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8649. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8650. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8651. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8652. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8653. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8654. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8655. if (spawn) {
  8656. const char* script = 0;
  8657. for (int x = 0; x < 3; x++) {
  8658. switch (x) {
  8659. case 0:
  8660. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8661. break;
  8662. case 1:
  8663. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8664. break;
  8665. case 2:
  8666. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8667. break;
  8668. }
  8669. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8670. spawn->SetSpawnScript(string(script));
  8671. break;
  8672. }
  8673. }
  8674. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8675. lua_interface->SetSpawnValue(state, spawn);
  8676. group.push_back(spawn);
  8677. }
  8678. else {
  8679. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8680. safe_delete(spawn);
  8681. }
  8682. }
  8683. }
  8684. if (!group.empty()) {
  8685. lua_createtable(state, group.size(), 0);
  8686. int newTable = lua_gettop(state);
  8687. for (int32 i = 0; i < group.size(); i++) {
  8688. lua_interface->SetSpawnValue(state, group[i]);
  8689. lua_rawseti(state, newTable, i + 1);
  8690. }
  8691. }
  8692. else
  8693. lua_pushnil(state);
  8694. return 1;
  8695. }
  8696. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8700. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8701. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8702. if (!spawn) {
  8703. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8704. return 0;
  8705. }
  8706. if (anim_id == 0) {
  8707. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8708. return 0;
  8709. }
  8710. if (leeway == 0)
  8711. leeway = 5000;
  8712. spawn->SetSpawnAnim(anim_id);
  8713. spawn->SetSpawnAnimLeeway(leeway);
  8714. return 0;
  8715. }
  8716. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8717. if (!lua_interface)
  8718. return 0;
  8719. Spawn* player = lua_interface->GetSpawn(state);
  8720. if (!player) {
  8721. return 0;
  8722. }
  8723. Client* client = player->GetZone()->GetClientBySpawn(player);
  8724. if (!client) {
  8725. return 0;
  8726. }
  8727. lua_interface->SetInt32Value(state, client->GetVersion());
  8728. return 1;
  8729. }
  8730. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8731. if (!lua_interface)
  8732. return 0;
  8733. Item* item = lua_interface->GetItem(state);
  8734. if (!item) {
  8735. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8736. return 0;
  8737. }
  8738. lua_interface->SetInt32Value(state, item->details.item_id);
  8739. return 1;
  8740. }
  8741. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8742. if (!lua_interface)
  8743. return 0;
  8744. Spawn* spawn = lua_interface->GetSpawn(state);
  8745. if (!spawn) {
  8746. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8750. return 1;
  8751. }
  8752. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8753. if (!lua_interface)
  8754. return 0;
  8755. Spawn* spawn = lua_interface->GetSpawn(state);
  8756. if (!spawn) {
  8757. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8758. return 0;
  8759. }
  8760. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8761. return 1;
  8762. }
  8763. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8764. if (!lua_interface)
  8765. return 0;
  8766. Spawn* spawn = lua_interface->GetSpawn(state);
  8767. if (!spawn) {
  8768. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8769. return 0;
  8770. }
  8771. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8772. return 1;
  8773. }
  8774. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8775. if (!lua_interface)
  8776. return 0;
  8777. Spawn* spawn = lua_interface->GetSpawn(state);
  8778. if (!spawn) {
  8779. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8780. return 0;
  8781. }
  8782. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8783. return 1;
  8784. }
  8785. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8786. if (!lua_interface)
  8787. return 0;
  8788. Spawn* spawn = lua_interface->GetSpawn(state);
  8789. float pct = lua_interface->GetFloatValue(state, 2);
  8790. if (!spawn) {
  8791. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8792. return 0;
  8793. }
  8794. if (pct == 0) {
  8795. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8796. return 0;
  8797. }
  8798. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8799. lua_interface->SetInt32Value(state, amount);
  8800. return 1;
  8801. }
  8802. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8803. if (!lua_interface)
  8804. return 0;
  8805. Spawn* spawn = lua_interface->GetSpawn(state);
  8806. float pct = lua_interface->GetFloatValue(state, 2);
  8807. if (!spawn) {
  8808. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8809. return 0;
  8810. }
  8811. if (pct == 0) {
  8812. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8813. return 0;
  8814. }
  8815. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8816. lua_interface->SetInt32Value(state, amount);
  8817. return 1;
  8818. }
  8819. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. Spawn* spawn = lua_interface->GetSpawn(state);
  8823. if (!spawn) {
  8824. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8825. return 0;
  8826. }
  8827. if (!spawn->IsPlayer()) {
  8828. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8829. return 0;
  8830. }
  8831. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8832. return 1;
  8833. }
  8834. int EQ2Emu_lua_Evac(lua_State* state) {
  8835. if (!lua_interface)
  8836. return 0;
  8837. Spawn* target = lua_interface->GetSpawn(state);
  8838. if (target) {
  8839. float x = target->GetZone()->GetSafeX();
  8840. float y = target->GetZone()->GetSafeY();
  8841. float z = target->GetZone()->GetSafeZ();
  8842. float h = target->GetZone()->GetSafeHeading();
  8843. target->SetX(x);
  8844. target->SetY(y);
  8845. target->SetZ(z);
  8846. target->SetHeading(h);
  8847. target->SetSpawnOrigX(target->GetX());
  8848. target->SetSpawnOrigY(target->GetY());
  8849. target->SetSpawnOrigZ(target->GetZ());
  8850. target->SetSpawnOrigHeading(target->GetHeading());
  8851. if (target->IsPlayer()) {
  8852. Client* client = target->GetZone()->GetClientBySpawn(target);
  8853. if (client) {
  8854. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8855. if (packet)
  8856. {
  8857. packet->setDataByName("x", x);
  8858. packet->setDataByName("y", y);
  8859. packet->setDataByName("z", z);
  8860. client->QueuePacket(packet->serialize());
  8861. safe_delete(packet);
  8862. }
  8863. }
  8864. }
  8865. }
  8866. else {
  8867. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8868. ZoneServer* zone = spell->caster->GetZone();
  8869. float x = spell->caster->GetZone()->GetSafeX();
  8870. float y = spell->caster->GetZone()->GetSafeY();
  8871. float z = spell->caster->GetZone()->GetSafeZ();
  8872. float h = spell->caster->GetZone()->GetSafeHeading();
  8873. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8874. for (int32 i = 0; i < spell->targets.size(); i++) {
  8875. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8876. if (!target2)
  8877. continue;
  8878. target2->SetX(x);
  8879. target2->SetY(y);
  8880. target2->SetZ(z);
  8881. target2->SetHeading(h);
  8882. target2->SetSpawnOrigX(target2->GetX());
  8883. target2->SetSpawnOrigY(target2->GetY());
  8884. target2->SetSpawnOrigZ(target2->GetZ());
  8885. target2->SetSpawnOrigHeading(target2->GetHeading());
  8886. if (target2->IsPlayer()) {
  8887. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8888. if (client) {
  8889. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8890. if (packet)
  8891. {
  8892. client->SetReloadingZone(true);
  8893. packet->setDataByName("x", x);
  8894. packet->setDataByName("y", y);
  8895. packet->setDataByName("z", z);
  8896. client->QueuePacket(packet->serialize());
  8897. safe_delete(packet);
  8898. }
  8899. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8900. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8901. }
  8902. }
  8903. }
  8904. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8905. }
  8906. return 0;
  8907. }
  8908. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8909. if (!lua_interface)
  8910. return 0;
  8911. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8912. if (!luaspell) {
  8913. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8914. return 0;
  8915. }
  8916. int8 tier = luaspell->spell->GetSpellTier();
  8917. lua_interface->SetInt32Value(state, tier);
  8918. return 1;
  8919. }
  8920. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8921. if (!lua_interface)
  8922. return 0;
  8923. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8924. if (!luaspell) {
  8925. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8926. return 0;
  8927. }
  8928. int32 spell_id = luaspell->spell->GetSpellID();
  8929. lua_interface->SetInt32Value(state, spell_id);
  8930. return 1;
  8931. }
  8932. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8933. if (!lua_interface)
  8934. return 0;
  8935. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8936. if (!spawn) {
  8937. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8938. return 0;
  8939. }
  8940. if (!spawn->IsPlayer()) {
  8941. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8942. return 0;
  8943. }
  8944. ZoneServer* zone = spawn->GetZone();
  8945. if (!zone) {
  8946. return 0;
  8947. }
  8948. Client* client = zone->GetClientBySpawn(spawn);
  8949. if (!client) {
  8950. return 0;
  8951. }
  8952. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8953. return 0;
  8954. }
  8955. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8956. if (!lua_interface)
  8957. return 0;
  8958. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8959. if (!spawn) {
  8960. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8961. return 0;
  8962. }
  8963. if (!spawn->IsPlayer()) {
  8964. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8965. return 0;
  8966. }
  8967. ZoneServer* zone = spawn->GetZone();
  8968. if (!zone) {
  8969. return 0;
  8970. }
  8971. Client* client = zone->GetClientBySpawn(spawn);
  8972. if (!client) {
  8973. return 0;
  8974. }
  8975. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8976. return 0;
  8977. }
  8978. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8979. if (!lua_interface)
  8980. return 0;
  8981. Spawn* caster = lua_interface->GetSpawn(state);
  8982. Spawn* target = lua_interface->GetSpawn(state, 2);
  8983. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8984. string spell_name = lua_interface->GetStringValue(state, 4);
  8985. if (!caster) {
  8986. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8987. return 0;
  8988. }
  8989. if (!caster->IsEntity()) {
  8990. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. if (!target) {
  8994. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8995. return 0;
  8996. }
  8997. if (!target->IsEntity()) {
  8998. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8999. return 0;
  9000. }
  9001. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9002. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9003. return 0;
  9004. }
  9005. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9006. if (!lua_interface)
  9007. return 0;
  9008. Spawn* player = lua_interface->GetSpawn(state);
  9009. int32 amount = lua_interface->GetInt32Value(state, 2);
  9010. if (player && player->IsPlayer() && amount > 0) {
  9011. ((Player*)player)->AddXP(amount);
  9012. ((Player*)player)->SetCharSheetChanged(true);
  9013. Client* client = player->GetZone()->GetClientBySpawn(player);
  9014. if (client) {
  9015. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9016. }
  9017. }
  9018. return 0;
  9019. }
  9020. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9021. if (!lua_interface)
  9022. return 0;
  9023. Spawn* player = lua_interface->GetSpawn(state);
  9024. int8 type = lua_interface->GetInt8Value(state, 2);
  9025. string text = lua_interface->GetStringValue(state, 3);
  9026. Client* client = 0;
  9027. if (player && player->IsPlayer())
  9028. client = player->GetZone()->GetClientBySpawn(player);
  9029. if (!client || text.length() == 0) {
  9030. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9031. return 0;
  9032. }
  9033. client->SimpleMessage(type, text.c_str());
  9034. return 0;
  9035. }
  9036. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9037. if (!lua_interface)
  9038. return 0;
  9039. Spawn* player = lua_interface->GetSpawn(state);
  9040. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9041. Client* client = 0;
  9042. if (player && player->IsPlayer())
  9043. client = player->GetZone()->GetClientBySpawn(player);
  9044. if (!client || !spawn) {
  9045. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9046. return 0;
  9047. }
  9048. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9049. if (!items) {
  9050. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9051. return 0;
  9052. }
  9053. client->Loot(spawn->GetLootCoins(), items, spawn);
  9054. return 0;
  9055. }
  9056. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9057. if (!lua_interface)
  9058. return 0;
  9059. Spawn* spawnref = lua_interface->GetSpawn(state);
  9060. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9061. if (spawn_id > 0 && spawnref) {
  9062. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9063. if (spawns.size() == 0) {
  9064. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9065. return 0;
  9066. }
  9067. Spawn* spawn = 0;
  9068. int16 index = MakeRandomInt(0, spawns.size());
  9069. if (index >= spawns.size() || index < 0)
  9070. index = 0;
  9071. spawn = spawns[index];
  9072. lua_interface->SetSpawnValue(state, spawn);
  9073. return 1;
  9074. }
  9075. else {
  9076. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9077. }
  9078. return 0;
  9079. }
  9080. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9081. Spawn* player = lua_interface->GetSpawn(state);
  9082. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9083. string name = lua_interface->GetStringValue(state, 3);
  9084. float distance = lua_interface->GetFloatValue(state, 4);
  9085. string command = lua_interface->GetStringValue(state, 5);
  9086. string error_text = lua_interface->GetStringValue(state, 6);
  9087. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9088. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9089. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9090. if (distance == 0)
  9091. distance = 10.0f;
  9092. if (command.length() == 0)
  9093. command = name;
  9094. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9095. if (spawns.size() == 0) {
  9096. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9097. return 0;
  9098. }
  9099. Spawn* spawn = 0;
  9100. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9101. spawn = *itr;
  9102. if (spawn) {
  9103. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9104. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9105. }
  9106. }
  9107. }
  9108. return 0;
  9109. }
  9110. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9111. if (!lua_interface)
  9112. return 0;
  9113. Client* client = 0;
  9114. Spawn* player = lua_interface->GetSpawn(state);
  9115. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9116. if (player && player->IsPlayer() && player->GetZone())
  9117. client = player->GetZone()->GetClientBySpawn(player);
  9118. else{
  9119. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9120. return 0;
  9121. }
  9122. if (client) {
  9123. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9124. if (packet) {
  9125. packet->setDataByName("goal_num", goal_num);
  9126. client->QueuePacket(packet->serialize());
  9127. safe_delete(packet);
  9128. }
  9129. }
  9130. return 0;
  9131. }
  9132. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9133. if (!lua_interface)
  9134. return 0;
  9135. Client* client = 0;
  9136. Spawn* player = lua_interface->GetSpawn(state);
  9137. if (player && player->IsPlayer() && player->GetZone())
  9138. client = player->GetZone()->GetClientBySpawn(player);
  9139. else {
  9140. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9141. return 0;
  9142. }
  9143. if (client) {
  9144. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9145. }
  9146. return 0;
  9147. }
  9148. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9149. if (!lua_interface)
  9150. return 0;
  9151. Client* client = 0;
  9152. Spawn* player = lua_interface->GetSpawn(state);
  9153. float duration = lua_interface->GetFloatValue(state, 2);
  9154. string text = lua_interface->GetStringValue(state, 3);
  9155. string voice = lua_interface->GetStringValue(state, 4);
  9156. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9157. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9158. string signal = lua_interface->GetStringValue(state, 7);
  9159. string goal1 = lua_interface->GetStringValue(state, 8);
  9160. string task1 = lua_interface->GetStringValue(state, 9);
  9161. string goal2 = lua_interface->GetStringValue(state, 10);
  9162. string task2 = lua_interface->GetStringValue(state, 11);
  9163. string goal3 = lua_interface->GetStringValue(state, 12);
  9164. string task3 = lua_interface->GetStringValue(state, 13);
  9165. string goal4 = lua_interface->GetStringValue(state, 14);
  9166. string task4 = lua_interface->GetStringValue(state, 15);
  9167. if (!player) {
  9168. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9169. return 0;
  9170. }
  9171. if (!player->IsPlayer()) {
  9172. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9173. return 0;
  9174. }
  9175. else
  9176. client = ((Player*)player)->GetClient();
  9177. if (!client) {
  9178. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9179. return 0;
  9180. }
  9181. if (text.length() == 0) {
  9182. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9183. return 0;
  9184. }
  9185. if (duration >= 0 && duration < 2)
  9186. duration = 2;
  9187. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9188. if (packet) {
  9189. packet->setDataByName("open_seconds_max", duration);
  9190. packet->setDataByName("text", text.c_str());
  9191. packet->setDataByName("voice", voice.c_str());
  9192. int8 num_goals = 1;
  9193. if (task2.length() > 0)
  9194. num_goals++;
  9195. if (task3.length() > 0)
  9196. num_goals++;
  9197. if (task4.length() > 0)
  9198. num_goals++;
  9199. packet->setArrayLengthByName("num_goals", num_goals);
  9200. for (int8 i = 0; i < num_goals; i++) {
  9201. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9202. }
  9203. if (goal1.length() > 0)
  9204. packet->setArrayDataByName("goal_text", goal1.c_str());
  9205. if (goal2.length() > 0)
  9206. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9207. if (goal3.length() > 0)
  9208. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9209. if (goal4.length() > 0)
  9210. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9211. packet->setSubArrayDataByName("task_text", task1.c_str());
  9212. if (task2.length() > 0)
  9213. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9214. if (task3.length() > 0)
  9215. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9216. if (task4.length() > 0)
  9217. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9218. packet->setDataByName("complete_sound", "click");
  9219. packet->setDataByName("signal", signal.c_str());
  9220. packet->setDataByName("voice_key1", voice_key1);
  9221. packet->setDataByName("voice_key2", voice_key2);
  9222. client->QueuePacket(packet->serialize());
  9223. safe_delete(packet);
  9224. }
  9225. return 0;
  9226. }
  9227. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9228. if (!lua_interface)
  9229. return 0;
  9230. Client* client = 0;
  9231. Spawn* player = lua_interface->GetSpawn(state);
  9232. string window = lua_interface->GetStringValue(state, 2);
  9233. int8 show = lua_interface->GetInt8Value(state, 3);
  9234. if (!player) {
  9235. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9236. return 0;
  9237. }
  9238. if (!player->IsPlayer()) {
  9239. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9240. return 0;
  9241. }
  9242. else
  9243. client = ((Player*)player)->GetClient();
  9244. if (!client) {
  9245. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9246. return 0;
  9247. }
  9248. if (window.length() == 0) {
  9249. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9250. return 0;
  9251. }
  9252. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9253. if (packet) {
  9254. packet->setDataByName("window", window.c_str());
  9255. packet->setDataByName("show", show);
  9256. client->QueuePacket(packet->serialize());
  9257. safe_delete(packet);
  9258. }
  9259. return 0;
  9260. }
  9261. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9262. //See GameEvents.txt for options that can be used for this function
  9263. if (!lua_interface)
  9264. return 0;
  9265. Client* client = 0;
  9266. Spawn* player = lua_interface->GetSpawn(state);
  9267. string event_name = lua_interface->GetStringValue(state, 2);
  9268. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9269. if (!player || !player->IsPlayer()) {
  9270. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9271. return 0;
  9272. }
  9273. if (player->GetZone())
  9274. client = player->GetZone()->GetClientBySpawn(player);
  9275. if (!client) {
  9276. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9277. return 0;
  9278. }
  9279. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9280. if (packet) {
  9281. packet->setDataByName("event_name", event_name.c_str());
  9282. packet->setDataByName("enabled", enabled);
  9283. client->QueuePacket(packet->serialize());
  9284. safe_delete(packet);
  9285. }
  9286. return 0;
  9287. }
  9288. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9289. if (!lua_interface)
  9290. return 0;
  9291. Spawn* player = lua_interface->GetSpawn(state);
  9292. if (player && player->IsPlayer()) {
  9293. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9294. return 1;
  9295. }
  9296. return 0;
  9297. }
  9298. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9299. if (!lua_interface)
  9300. return 0;
  9301. Spawn* player = lua_interface->GetSpawn(state);
  9302. int8 step = lua_interface->GetInt8Value(state, 2);
  9303. if (player && player->IsPlayer() && step > 0) {
  9304. ((Player*)player)->SetTutorialStep(step);
  9305. }
  9306. return 0;
  9307. }
  9308. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9309. if (!lua_interface)
  9310. return 0;
  9311. Client* client = 0;
  9312. Spawn* player = lua_interface->GetSpawn(state);
  9313. string window = lua_interface->GetStringValue(state, 2);
  9314. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9315. if (!player) {
  9316. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9317. return 0;
  9318. }
  9319. if (!player->IsPlayer()) {
  9320. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9321. return 0;
  9322. }
  9323. else
  9324. client = ((Player*)player)->GetClient();
  9325. if (!client) {
  9326. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9327. return 0;
  9328. }
  9329. if (window.length() == 0) {
  9330. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9331. return 0;
  9332. }
  9333. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9334. if (packet) {
  9335. packet->setDataByName("window", window.c_str());
  9336. packet->setDataByName("flash_seconds", flash_seconds);
  9337. client->QueuePacket(packet->serialize());
  9338. safe_delete(packet);
  9339. }
  9340. return 0;
  9341. }
  9342. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9343. if (!lua_interface)
  9344. return 0;
  9345. Spawn* spawn = lua_interface->GetSpawn(state);
  9346. Spawn* target = lua_interface->GetSpawn(state, 2);
  9347. if (spawn && target)
  9348. return spawn->CheckLoS(target);
  9349. return 0;
  9350. }
  9351. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9352. if (!lua_interface)
  9353. return 0;
  9354. Spawn* spawn = lua_interface->GetSpawn(state);
  9355. float x = lua_interface->GetFloatValue(state, 2);
  9356. float y = lua_interface->GetFloatValue(state, 3);
  9357. float z = lua_interface->GetFloatValue(state, 4);
  9358. if (spawn)
  9359. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9360. return 0;
  9361. }
  9362. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9363. if (!lua_interface)
  9364. return 0;
  9365. ZoneServer* zone = lua_interface->GetZone(state);
  9366. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9367. if (zone)
  9368. zone->SetExpansionFlag(xpackFlag);
  9369. return 0;
  9370. }
  9371. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9372. if (!lua_interface)
  9373. return 0;
  9374. ZoneServer* zone = lua_interface->GetZone(state);
  9375. if (zone) {
  9376. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9377. return 1;
  9378. }
  9379. return 0;
  9380. }
  9381. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9382. if (!lua_interface)
  9383. return 0;
  9384. ZoneServer* zone = lua_interface->GetZone(state);
  9385. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9386. if (zone)
  9387. zone->SetHolidayFlag(holidayFlag);
  9388. return 0;
  9389. }
  9390. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9391. if (!lua_interface)
  9392. return 0;
  9393. ZoneServer* zone = lua_interface->GetZone(state);
  9394. if (zone) {
  9395. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9396. return 1;
  9397. }
  9398. return 0;
  9399. }
  9400. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9401. if (!lua_interface)
  9402. return 0;
  9403. Spawn* spawn = lua_interface->GetSpawn(state);
  9404. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9405. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9406. float distance = lua_interface->GetFloatValue(state, 4);
  9407. string in_range_function = lua_interface->GetStringValue(state, 5);
  9408. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9409. if (spawn && distance > 0 && in_range_function.length() > 0)
  9410. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9411. return 0;
  9412. }
  9413. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9414. if (!lua_interface)
  9415. return 0;
  9416. Spawn* spawn = lua_interface->GetSpawn(state);
  9417. Spawn* target = lua_interface->GetSpawn(state, 2);
  9418. if (spawn && target)
  9419. {
  9420. if (spawn->IsPlayer() && target->IsEntity())
  9421. {
  9422. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9423. return 1;
  9424. }
  9425. else if (spawn->IsEntity() && target->IsEntity())
  9426. {
  9427. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9428. return 1;
  9429. }
  9430. }
  9431. return 0;
  9432. }
  9433. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9434. if (!lua_interface)
  9435. return 0;
  9436. Spawn* spawn = lua_interface->GetSpawn(state);
  9437. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9438. if (spawn && spawn->IsEntity())
  9439. {
  9440. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9441. if (spawn->IsPlayer())
  9442. {
  9443. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9444. if (client)
  9445. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9446. }
  9447. }
  9448. return 0;
  9449. }
  9450. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9451. if (!lua_interface)
  9452. return 0;
  9453. Spawn* spawn = lua_interface->GetSpawn(state);
  9454. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9455. if (spawn && spawn->IsEntity())
  9456. {
  9457. ((Entity*)spawn)->SetSeeHideSpell(val);
  9458. if (spawn->IsPlayer())
  9459. {
  9460. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9461. if (client)
  9462. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9463. }
  9464. }
  9465. return 0;
  9466. }
  9467. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9468. {
  9469. if (!lua_interface)
  9470. return 0;
  9471. Spawn* player = lua_interface->GetSpawn(state);
  9472. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9473. string command = lua_interface->GetStringValue(state, 3);
  9474. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9475. lua_interface->ResetFunctionStack(state);
  9476. if (spawn && player && player->IsPlayer())
  9477. {
  9478. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9479. bool res = false;
  9480. if (cmd)
  9481. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9482. lua_interface->SetBooleanValue(state, res);
  9483. return 1;
  9484. }
  9485. return 0;
  9486. }
  9487. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9488. {
  9489. if (!lua_interface)
  9490. return 0;
  9491. Spawn* spawn = lua_interface->GetSpawn(state);
  9492. int32 charID = lua_interface->GetInt32Value(state, 2);
  9493. string command = lua_interface->GetStringValue(state, 3);
  9494. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9495. lua_interface->ResetFunctionStack(state);
  9496. if (spawn && charID)
  9497. {
  9498. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9499. bool res = false;
  9500. if (cmd)
  9501. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9502. lua_interface->SetBooleanValue(state, res);
  9503. return 1;
  9504. }
  9505. return 0;
  9506. }
  9507. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9508. {
  9509. if (!lua_interface)
  9510. return 0;
  9511. Spawn* spawn = lua_interface->GetSpawn(state);
  9512. string command = lua_interface->GetStringValue(state, 2);
  9513. lua_interface->ResetFunctionStack(state);
  9514. if (spawn && command.length() > 0)
  9515. spawn->RemovePrimaryEntityCommand(command.c_str());
  9516. return 0;
  9517. }
  9518. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9519. if (!lua_interface)
  9520. return 0;
  9521. Spawn* spawn = lua_interface->GetSpawn(state);
  9522. float distance = lua_interface->GetFloatValue(state, 2);
  9523. string command = lua_interface->GetStringValue(state, 3);
  9524. Spawn* player = lua_interface->GetSpawn(state, 4);
  9525. lua_interface->ResetFunctionStack(state);
  9526. if (spawn) {
  9527. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9528. }
  9529. return 0;
  9530. }
  9531. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9532. if (!lua_interface)
  9533. return 0;
  9534. Spawn* spawn = lua_interface->GetSpawn(state);
  9535. Spawn* player = lua_interface->GetSpawn(state, 2);
  9536. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9537. lua_interface->ResetFunctionStack(state);
  9538. if (spawn && player && transport_id && player->IsPlayer()) {
  9539. Client* client = 0;
  9540. if (player && player->IsPlayer())
  9541. client = player->GetZone()->GetClientBySpawn(player);
  9542. if (!client)
  9543. return 0;
  9544. vector<TransportDestination*> destinations;
  9545. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9546. if (destinations.size())
  9547. {
  9548. client->SetTemporaryTransportID(transport_id);
  9549. client->ProcessTeleport(spawn, &destinations, transport_id);
  9550. }
  9551. else
  9552. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9553. }
  9554. return 0;
  9555. }
  9556. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9557. if (!lua_interface)
  9558. return 0;
  9559. Spawn* player = lua_interface->GetSpawn(state);
  9560. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9561. lua_interface->ResetFunctionStack(state);
  9562. if (player && player->IsPlayer()) {
  9563. Client* client = 0;
  9564. if (player && player->IsPlayer())
  9565. client = player->GetZone()->GetClientBySpawn(player);
  9566. if (!client)
  9567. return 0;
  9568. client->SetTemporaryTransportID(transport_id);
  9569. }
  9570. return 0;
  9571. }
  9572. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9573. if (!lua_interface)
  9574. return 0;
  9575. Spawn* player = lua_interface->GetSpawn(state);
  9576. lua_interface->ResetFunctionStack(state);
  9577. if (player && player->IsPlayer()) {
  9578. Client* client = 0;
  9579. if (player && player->IsPlayer())
  9580. client = player->GetZone()->GetClientBySpawn(player);
  9581. if (!client)
  9582. return 0;
  9583. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9584. return 1;
  9585. }
  9586. return 0;
  9587. }
  9588. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9589. if (!lua_interface)
  9590. return 0;
  9591. Spawn* spawn = lua_interface->GetSpawn(state);
  9592. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9593. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9594. if (!spawn) {
  9595. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9596. return 0;
  9597. }
  9598. if (!spawn->IsEntity()) {
  9599. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9600. return 0;
  9601. }
  9602. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9603. {
  9604. 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);
  9605. return 0;
  9606. }
  9607. lua_interface->ResetFunctionStack(state);
  9608. if (spell && spell->targets.size() > 0) {
  9609. ZoneServer* zone = spell->caster->GetZone();
  9610. for (int8 i = 0; i < spell->targets.size(); i++) {
  9611. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9612. if (target->IsEntity()) {
  9613. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9614. if (target->IsPlayer())
  9615. ((Player*)target)->SetCharSheetChanged(true);
  9616. }
  9617. }
  9618. }
  9619. else {
  9620. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9621. if (spawn->IsPlayer())
  9622. ((Player*)spawn)->SetCharSheetChanged(true);
  9623. }
  9624. return 0;
  9625. }
  9626. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9627. if (!lua_interface)
  9628. return 0;
  9629. Spawn* spawn = lua_interface->GetSpawn(state);
  9630. lua_interface->ResetFunctionStack(state);
  9631. if (!spawn) {
  9632. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9633. return 0;
  9634. }
  9635. if (!spawn->IsEntity()) {
  9636. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9637. return 0;
  9638. }
  9639. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9640. return 1;
  9641. }
  9642. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9643. if (!lua_interface)
  9644. return 0;
  9645. int32 spell_id = lua_interface->GetInt32Value(state);
  9646. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9647. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9648. if (spell_id > 0) {
  9649. if (spell_tier == 0)
  9650. spell_tier = 1;
  9651. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9652. LuaSpell* lua_spell = 0;
  9653. if(custom_lua_script.size() > 0)
  9654. {
  9655. // attempt to load the custom script since it isn't already loaded
  9656. // we will re-obtain the lua_spell further below
  9657. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9658. {
  9659. 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());
  9660. lua_interface->LoadLuaSpell(custom_lua_script);
  9661. }
  9662. }
  9663. else
  9664. custom_lua_script = spell->GetSpellData()->lua_script;
  9665. if (!lua_spell && lua_interface)
  9666. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9667. if (!lua_spell)
  9668. {
  9669. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9670. return 0;
  9671. }
  9672. lua_spell->spell = new Spell(spell);
  9673. lua_interface->AddCustomSpell(lua_spell);
  9674. lua_interface->SetSpellValue(state, lua_spell);
  9675. return 1;
  9676. }
  9677. return 0;
  9678. }
  9679. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9680. if (!lua_interface)
  9681. return 0;
  9682. LuaSpell* spell = lua_interface->GetSpell(state);
  9683. string field = lua_interface->GetStringValue(state, 2);
  9684. if (!spell) {
  9685. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9686. return 0;
  9687. }
  9688. if (!spell->spell || !spell->spell->GetSpellData()) {
  9689. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9690. return 0;
  9691. }
  9692. boost::to_lower(field);
  9693. return spell->spell->GetSpellData(state, field);
  9694. }
  9695. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9696. if (!lua_interface)
  9697. return 0;
  9698. LuaSpell* spell = lua_interface->GetSpell(state);
  9699. string field = lua_interface->GetStringValue(state, 2);
  9700. int8 fieldArg = 3; // field value after the initial set
  9701. if (!spell) {
  9702. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9703. return 0;
  9704. }
  9705. if (!spell->spell || !spell->spell->GetSpellData()) {
  9706. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9707. return 0;
  9708. }
  9709. boost::to_lower(field);
  9710. bool valSet = false;
  9711. spell->spell->SetSpellData(state, field, fieldArg);
  9712. return valSet;
  9713. }
  9714. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9715. if (!lua_interface)
  9716. return 0;
  9717. LuaSpell* spell = lua_interface->GetSpell(state);
  9718. int8 idx = lua_interface->GetInt32Value(state, 2);
  9719. if (!spell) {
  9720. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9721. return 0;
  9722. }
  9723. if (!spell->spell || !spell->spell->GetSpellData()) {
  9724. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9725. return 0;
  9726. }
  9727. if (spell->spell->lua_data.size() <= idx)
  9728. {
  9729. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9730. return 0;
  9731. }
  9732. bool setVal = true;
  9733. LUAData* data = spell->spell->lua_data[idx];
  9734. switch (data->type)
  9735. {
  9736. case 0:
  9737. {
  9738. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9739. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9740. data->int_value = value;
  9741. data->int_value2 = value2;
  9742. break;
  9743. }
  9744. case 1:
  9745. {
  9746. float value = lua_interface->GetFloatValue(state, 3);
  9747. float value2 = lua_interface->GetFloatValue(state, 4);
  9748. data->float_value = value;
  9749. data->float_value2 = value2;
  9750. break;
  9751. }
  9752. case 2:
  9753. {
  9754. bool value = lua_interface->GetBooleanValue(state, 3);
  9755. data->bool_value = value;
  9756. break;
  9757. }
  9758. case 3:
  9759. {
  9760. string value = lua_interface->GetStringValue(state, 3);
  9761. string value2 = lua_interface->GetStringValue(state, 4);
  9762. data->string_value = value;
  9763. data->string_value2 = value2;
  9764. break;
  9765. }
  9766. default:
  9767. setVal = false;
  9768. }
  9769. return setVal;
  9770. }
  9771. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9772. if (!lua_interface)
  9773. return 0;
  9774. LuaSpell* spell = lua_interface->GetSpell(state);
  9775. int8 idx = lua_interface->GetInt32Value(state, 2);
  9776. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9777. if (!spell) {
  9778. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9779. return 0;
  9780. }
  9781. if (!spell->spell || !spell->spell->GetSpellData()) {
  9782. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9783. return 0;
  9784. }
  9785. if (spell->spell->lua_data.size() <= idx)
  9786. {
  9787. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9788. return 0;
  9789. }
  9790. bool setVal = true;
  9791. LUAData* data = spell->spell->lua_data[idx];
  9792. switch (data->type)
  9793. {
  9794. case 0:
  9795. {
  9796. if(!secondfield)
  9797. lua_interface->SetSInt32Value(state, data->int_value);
  9798. else
  9799. lua_interface->SetSInt32Value(state, data->int_value2);
  9800. break;
  9801. }
  9802. case 1:
  9803. {
  9804. if (!secondfield)
  9805. lua_interface->SetFloatValue(state, data->float_value);
  9806. else
  9807. lua_interface->SetFloatValue(state, data->float_value2);
  9808. break;
  9809. }
  9810. case 2:
  9811. {
  9812. lua_interface->SetBooleanValue(state, data->bool_value);
  9813. break;
  9814. }
  9815. case 3:
  9816. {
  9817. if (!secondfield)
  9818. lua_interface->SetStringValue(state, data->string_value.c_str());
  9819. else
  9820. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9821. break;
  9822. }
  9823. default:
  9824. setVal = false;
  9825. }
  9826. return setVal;
  9827. }
  9828. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9829. if (!lua_interface)
  9830. return 0;
  9831. LuaSpell* spell = lua_interface->GetSpell(state);
  9832. int8 idx = lua_interface->GetInt32Value(state, 2);
  9833. string field = lua_interface->GetStringValue(state, 3);
  9834. boost::to_lower(field);
  9835. if (!spell) {
  9836. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9837. return 0;
  9838. }
  9839. if (!spell->spell || !spell->spell->GetSpellData()) {
  9840. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9841. return 0;
  9842. }
  9843. if (spell->spell->effects.size() <= idx)
  9844. {
  9845. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9846. return 0;
  9847. }
  9848. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9849. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9850. if (field == "description")
  9851. effect->description = string(lua_interface->GetStringValue(state, 4));
  9852. else if (field == "bullet")
  9853. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9854. else if (field == "percentage")
  9855. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9856. else // no match
  9857. return 0;
  9858. return 1;
  9859. }
  9860. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9861. if (!lua_interface)
  9862. return 0;
  9863. LuaSpell* spell = lua_interface->GetSpell(state);
  9864. int8 idx = lua_interface->GetInt32Value(state, 2);
  9865. string field = lua_interface->GetStringValue(state, 3);
  9866. boost::to_lower(field);
  9867. if (!spell) {
  9868. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9869. return 0;
  9870. }
  9871. if (!spell->spell || !spell->spell->GetSpellData()) {
  9872. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9873. return 0;
  9874. }
  9875. if (spell->spell->effects.size() <= idx)
  9876. {
  9877. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9878. return 0;
  9879. }
  9880. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9881. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9882. if (field == "description")
  9883. lua_interface->SetStringValue(state, effect->description.c_str());
  9884. else if (field == "bullet")
  9885. lua_interface->SetInt32Value(state, effect->subbullet);
  9886. else if (field == "percentage")
  9887. lua_interface->SetInt32Value(state, effect->percentage);
  9888. else // no match
  9889. return 0;
  9890. return 1;
  9891. }
  9892. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9893. if (!lua_interface)
  9894. return 0;
  9895. LuaSpell* spell = lua_interface->GetSpell(state);
  9896. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9897. Spawn* target = lua_interface->GetSpawn(state, 3);
  9898. if (!target) {
  9899. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9900. return 0;
  9901. }
  9902. if (!target->IsEntity()) {
  9903. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9904. return 0;
  9905. }
  9906. if (!spell) {
  9907. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9908. return 0;
  9909. }
  9910. if (caster && !caster->IsEntity()) {
  9911. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9912. return 0;
  9913. }
  9914. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9915. return 0;
  9916. }
  9917. int EQ2Emu_lua_InWater(lua_State* state) {
  9918. if (!lua_interface)
  9919. return 0;
  9920. Spawn* spawn = lua_interface->GetSpawn(state);
  9921. lua_interface->ResetFunctionStack(state);
  9922. if (spawn) {
  9923. lua_interface->SetBooleanValue(state, spawn->InWater());
  9924. return 1;
  9925. }
  9926. return 0;
  9927. }
  9928. int EQ2Emu_lua_InLava(lua_State* state) {
  9929. if (!lua_interface)
  9930. return 0;
  9931. Spawn* spawn = lua_interface->GetSpawn(state);
  9932. lua_interface->ResetFunctionStack(state);
  9933. if (spawn) {
  9934. lua_interface->SetBooleanValue(state, spawn->InLava());
  9935. return 1;
  9936. }
  9937. return 0;
  9938. }
  9939. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. Spawn* attacker = lua_interface->GetSpawn(state);
  9943. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9944. int8 type = lua_interface->GetInt8Value(state, 3);
  9945. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9946. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9947. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9948. string spell_name = lua_interface->GetStringValue(state, 7);
  9949. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9950. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9951. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9952. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9953. lua_interface->ResetFunctionStack(state);
  9954. if (!attacker) {
  9955. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9956. return 0;
  9957. }
  9958. if (!attacker->IsEntity()) {
  9959. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9960. return 0;
  9961. }
  9962. if (!victim) {
  9963. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9964. return 0;
  9965. }
  9966. if (!victim->IsEntity()) {
  9967. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9968. return 0;
  9969. }
  9970. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9971. return 0;
  9972. }
  9973. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9974. if (!lua_interface)
  9975. return 0;
  9976. Spawn* spawn = lua_interface->GetSpawn(state);
  9977. lua_interface->ResetFunctionStack(state);
  9978. if (spawn) {
  9979. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9980. return 1;
  9981. }
  9982. return 0;
  9983. }
  9984. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9985. if (!lua_interface)
  9986. return 0;
  9987. Spawn* spawn = lua_interface->GetSpawn(state);
  9988. bool invul = lua_interface->GetBooleanValue(state, 2);
  9989. lua_interface->ResetFunctionStack(state);
  9990. if (spawn) {
  9991. spawn->SetInvulnerable(invul);
  9992. }
  9993. return 0;
  9994. }
  9995. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. string category = lua_interface->GetStringValue(state);
  9999. string name = lua_interface->GetStringValue(state, 2);
  10000. lua_interface->ResetFunctionStack(state);
  10001. Rule *ret = 0;
  10002. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10003. lua_interface->SetBooleanValue(state, ret->GetBool());
  10004. return 1;
  10005. }
  10006. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10007. return 0;
  10008. }
  10009. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10010. if (!lua_interface)
  10011. return 0;
  10012. string category = lua_interface->GetStringValue(state);
  10013. string name = lua_interface->GetStringValue(state, 2);
  10014. lua_interface->ResetFunctionStack(state);
  10015. Rule *ret = 0;
  10016. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10017. lua_interface->SetInt32Value(state, ret->GetInt32());
  10018. return 1;
  10019. }
  10020. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10021. return 0;
  10022. }
  10023. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10024. if (!lua_interface)
  10025. return 0;
  10026. string category = lua_interface->GetStringValue(state);
  10027. string name = lua_interface->GetStringValue(state, 2);
  10028. lua_interface->ResetFunctionStack(state);
  10029. Rule *ret = 0;
  10030. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10031. lua_interface->SetFloatValue(state, ret->GetFloat());
  10032. return 1;
  10033. }
  10034. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10035. return 0;
  10036. }
  10037. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10038. if (!lua_interface)
  10039. return 0;
  10040. Spawn* spawn = lua_interface->GetSpawn(state);
  10041. string type = lua_interface->GetStringValue(state, 2);
  10042. lua_interface->ResetFunctionStack(state);
  10043. if (spawn) {
  10044. int res = 1;
  10045. boost::to_lower(type);
  10046. if(type == "assigned_aa")
  10047. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10048. else if ( type == "unassigned_aa")
  10049. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10050. else if ( type == "assigned_tradeskill_aa")
  10051. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10052. else if ( type == "unassigned_tradeskill_aa")
  10053. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10054. else if ( type == "assigned_prestige_aa")
  10055. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10056. else if ( type == "unassigned_prestige_aa")
  10057. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10058. else if ( type == "assigned_tradeskill_prestige_aa")
  10059. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10060. else if ( type == "unassigned_tradeskill_prestige_aa")
  10061. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10062. else
  10063. res = 0;
  10064. return res;
  10065. }
  10066. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10067. return 0;
  10068. }
  10069. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10070. if (!lua_interface)
  10071. return 0;
  10072. Spawn* spawn = lua_interface->GetSpawn(state);
  10073. string type = lua_interface->GetStringValue(state, 2);
  10074. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10075. lua_interface->ResetFunctionStack(state);
  10076. if (spawn) {
  10077. boost::to_lower(type);
  10078. if(type == "assigned_aa")
  10079. spawn->SetAssignedAA((sint16)value);
  10080. else if ( type == "unassigned_aa")
  10081. spawn->SetUnassignedAA((sint16)value);
  10082. else if ( type == "assigned_tradeskill_aa")
  10083. spawn->SetTradeskillAA((sint16)value);
  10084. else if ( type == "unassigned_tradeskill_aa")
  10085. spawn->SetUnassignedTradeskillAA((sint16)value);
  10086. else if ( type == "assigned_prestige_aa")
  10087. spawn->SetPrestigeAA((sint16)value);
  10088. else if ( type == "unassigned_prestige_aa")
  10089. spawn->SetUnassignedPrestigeAA((sint16)value);
  10090. else if ( type == "assigned_tradeskill_prestige_aa")
  10091. spawn->SetTradeskillPrestigeAA((sint16)value);
  10092. else if ( type == "unassigned_tradeskill_prestige_aa")
  10093. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10094. if(spawn->IsPlayer())
  10095. ((Player*)spawn)->SetCharSheetChanged(true);
  10096. }
  10097. return 0;
  10098. }
  10099. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10100. if (!lua_interface)
  10101. return 0;
  10102. string titleName = lua_interface->GetStringValue(state);
  10103. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10104. lua_interface->ResetFunctionStack(state);
  10105. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10106. lua_interface->SetSInt32Value(state, index);
  10107. return 1;
  10108. }
  10109. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10110. if (!lua_interface)
  10111. return 0;
  10112. Spawn* spawn = lua_interface->GetSpawn(state);
  10113. string titleName = lua_interface->GetStringValue(state, 2);
  10114. lua_interface->ResetFunctionStack(state);
  10115. if(!spawn->IsPlayer())
  10116. {
  10117. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10118. lua_interface->SetSInt32Value(state, -1);
  10119. return 1;
  10120. }
  10121. Player* player = (Player*)spawn;
  10122. // check if player already has the title, don't need to add twice
  10123. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10124. if ( playerHasTitle)
  10125. {
  10126. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10127. return 1;
  10128. }
  10129. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10130. if(!title)
  10131. {
  10132. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10133. lua_interface->SetSInt32Value(state, -1);
  10134. return 1;
  10135. }
  10136. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10137. if(returnIdx < 0)
  10138. {
  10139. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10140. }
  10141. lua_interface->SetSInt32Value(state, returnIdx);
  10142. player->GetClient()->SendTitleUpdate();
  10143. return 1;
  10144. }
  10145. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10146. if (!lua_interface)
  10147. return 0;
  10148. Spawn* spawn = lua_interface->GetSpawn(state);
  10149. string titleName = lua_interface->GetStringValue(state, 2);
  10150. lua_interface->ResetFunctionStack(state);
  10151. if(!spawn->IsPlayer())
  10152. {
  10153. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10154. return 0;
  10155. }
  10156. Player* player = (Player*)spawn;
  10157. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10158. if(!title)
  10159. {
  10160. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10161. return 0;
  10162. }
  10163. if(title->GetPrefix())
  10164. {
  10165. 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());
  10166. return 0;
  10167. }
  10168. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10169. player->GetClient()->SendTitleUpdate();
  10170. return 1;
  10171. }
  10172. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10173. if (!lua_interface)
  10174. return 0;
  10175. Spawn* spawn = lua_interface->GetSpawn(state);
  10176. string titleName = lua_interface->GetStringValue(state, 2);
  10177. lua_interface->ResetFunctionStack(state);
  10178. if(!spawn->IsPlayer())
  10179. {
  10180. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10181. return 0;
  10182. }
  10183. Player* player = (Player*)spawn;
  10184. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10185. if(!title)
  10186. {
  10187. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10188. return 0;
  10189. }
  10190. if(!title->GetPrefix())
  10191. {
  10192. 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());
  10193. return 0;
  10194. }
  10195. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10196. player->GetClient()->SendTitleUpdate();
  10197. return 1;
  10198. }
  10199. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10200. if (!lua_interface)
  10201. return 0;
  10202. Spawn* spawn = lua_interface->GetSpawn(state);
  10203. lua_interface->ResetFunctionStack(state);
  10204. if(!spawn->IsPlayer())
  10205. {
  10206. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10207. return 0;
  10208. }
  10209. Player* player = (Player*)spawn;
  10210. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10211. player->GetClient()->SendTitleUpdate();
  10212. return 1;
  10213. }
  10214. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10215. if (!lua_interface)
  10216. return 0;
  10217. Spawn* spawn = lua_interface->GetSpawn(state);
  10218. lua_interface->ResetFunctionStack(state);
  10219. if(!spawn->IsPlayer())
  10220. {
  10221. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10222. return 0;
  10223. }
  10224. Player* player = (Player*)spawn;
  10225. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10226. player->GetClient()->SendTitleUpdate();
  10227. return 1;
  10228. }
  10229. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10230. if (!lua_interface)
  10231. return 0;
  10232. Spawn* spawn = lua_interface->GetSpawn(state);
  10233. string field = lua_interface->GetStringValue(state, 2);
  10234. lua_interface->ResetFunctionStack(state);
  10235. if(!spawn || !spawn->IsEntity())
  10236. {
  10237. 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));
  10238. return 0;
  10239. }
  10240. Entity* ent = (Entity*)spawn;
  10241. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10242. return 1;
  10243. }
  10244. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10245. if (!lua_interface)
  10246. return 0;
  10247. Spawn* spawn = lua_interface->GetSpawn(state);
  10248. string field = lua_interface->GetStringValue(state, 2);
  10249. lua_interface->ResetFunctionStack(state);
  10250. if(!spawn || !spawn->IsEntity())
  10251. {
  10252. 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));
  10253. return 0;
  10254. }
  10255. Entity* ent = (Entity*)spawn;
  10256. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10257. return 1;
  10258. }
  10259. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10260. if (!lua_interface)
  10261. return 0;
  10262. Spawn* spawn = lua_interface->GetSpawn(state);
  10263. string field = lua_interface->GetStringValue(state, 2);
  10264. lua_interface->ResetFunctionStack(state);
  10265. if(!spawn || !spawn->IsEntity())
  10266. {
  10267. 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));
  10268. return 0;
  10269. }
  10270. Entity* ent = (Entity*)spawn;
  10271. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10272. return 1;
  10273. }
  10274. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10275. if (!lua_interface)
  10276. return 0;
  10277. Spawn* spawn = lua_interface->GetSpawn(state);
  10278. string field = lua_interface->GetStringValue(state, 2);
  10279. lua_interface->ResetFunctionStack(state);
  10280. if(!spawn || !spawn->IsEntity())
  10281. {
  10282. 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));
  10283. return 0;
  10284. }
  10285. Entity* ent = (Entity*)spawn;
  10286. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10287. return 1;
  10288. }
  10289. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10290. if (!lua_interface)
  10291. return 0;
  10292. Spawn* spawn = lua_interface->GetSpawn(state);
  10293. string field = lua_interface->GetStringValue(state, 2);
  10294. string value = lua_interface->GetStringValue(state, 3);
  10295. lua_interface->ResetFunctionStack(state);
  10296. if(!spawn || !spawn->IsEntity())
  10297. {
  10298. 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));
  10299. return 0;
  10300. }
  10301. Entity* ent = (Entity*)spawn;
  10302. bool set_ = ent->SetInfoStructString(field, value);
  10303. lua_interface->SetBooleanValue(state, set_);
  10304. return 1;
  10305. }
  10306. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10307. if (!lua_interface)
  10308. return 0;
  10309. Spawn* spawn = lua_interface->GetSpawn(state);
  10310. string field = lua_interface->GetStringValue(state, 2);
  10311. int64 value = lua_interface->GetInt64Value(state, 3);
  10312. lua_interface->ResetFunctionStack(state);
  10313. if(!spawn || !spawn->IsEntity())
  10314. {
  10315. 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));
  10316. return 0;
  10317. }
  10318. Entity* ent = (Entity*)spawn;
  10319. bool set_ = ent->SetInfoStructUInt(field, value);
  10320. lua_interface->SetBooleanValue(state, set_);
  10321. return 1;
  10322. }
  10323. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10324. if (!lua_interface)
  10325. return 0;
  10326. Spawn* spawn = lua_interface->GetSpawn(state);
  10327. string field = lua_interface->GetStringValue(state, 2);
  10328. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10329. lua_interface->ResetFunctionStack(state);
  10330. if(!spawn || !spawn->IsEntity())
  10331. {
  10332. 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));
  10333. return 0;
  10334. }
  10335. Entity* ent = (Entity*)spawn;
  10336. bool set_ = ent->SetInfoStructSInt(field, value);
  10337. lua_interface->SetBooleanValue(state, set_);
  10338. return 1;
  10339. }
  10340. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10341. if (!lua_interface)
  10342. return 0;
  10343. Spawn* spawn = lua_interface->GetSpawn(state);
  10344. string field = lua_interface->GetStringValue(state, 2);
  10345. float value = lua_interface->GetFloatValue(state, 3);
  10346. lua_interface->ResetFunctionStack(state);
  10347. if(!spawn || !spawn->IsEntity())
  10348. {
  10349. 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));
  10350. return 0;
  10351. }
  10352. Entity* ent = (Entity*)spawn;
  10353. bool set_ = ent->SetInfoStructFloat(field, value);
  10354. lua_interface->SetBooleanValue(state, set_);
  10355. return 1;
  10356. }
  10357. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10358. if (!lua_interface)
  10359. return 0;
  10360. Spawn* spawn = lua_interface->GetSpawn(state);
  10361. bool value = lua_interface->GetBooleanValue(state, 2);
  10362. lua_interface->ResetFunctionStack(state);
  10363. if(!spawn || !spawn->IsPlayer())
  10364. {
  10365. 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));
  10366. return 0;
  10367. }
  10368. ((Player*)spawn)->SetCharSheetChanged(value);
  10369. return 0;
  10370. }
  10371. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10372. if (!lua_interface)
  10373. return 0;
  10374. Spawn* spawn = lua_interface->GetSpawn(state);
  10375. std::string fromName = lua_interface->GetStringValue(state, 2);
  10376. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10377. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10378. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10379. int32 copper = lua_interface->GetInt32Value(state, 6);
  10380. int32 silver = lua_interface->GetInt32Value(state, 7);
  10381. int32 gold = lua_interface->GetInt32Value(state, 8);
  10382. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10383. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10384. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10385. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10386. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10387. lua_interface->ResetFunctionStack(state);
  10388. if(!spawn || !spawn->IsPlayer())
  10389. {
  10390. 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));
  10391. lua_interface->SetBooleanValue(state, false);
  10392. return 1;
  10393. }
  10394. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10395. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10396. lua_interface->SetBooleanValue(state, true);
  10397. return 1;
  10398. }
  10399. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10400. if (!lua_interface)
  10401. return 0;
  10402. int32 char_id = lua_interface->GetInt32Value(state);
  10403. std::string fromName = lua_interface->GetStringValue(state, 2);
  10404. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10405. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10406. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10407. int32 copper = lua_interface->GetInt32Value(state, 6);
  10408. int32 silver = lua_interface->GetInt32Value(state, 7);
  10409. int32 gold = lua_interface->GetInt32Value(state, 8);
  10410. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10411. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10412. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10413. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10414. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10415. lua_interface->ResetFunctionStack(state);
  10416. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10417. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10418. lua_interface->SetBooleanValue(state, true);
  10419. return 1;
  10420. }
  10421. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10422. Spawn* widget;
  10423. if (lua_interface) {
  10424. widget = lua_interface->GetSpawn(state);
  10425. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10426. lua_interface->ResetFunctionStack(state);
  10427. if (widget && widget->IsWidget())
  10428. {
  10429. ((Widget*)widget)->OpenDoor();
  10430. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10431. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10432. }
  10433. else
  10434. 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));
  10435. }
  10436. return 0;
  10437. }
  10438. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10439. Spawn* widget;
  10440. if (lua_interface) {
  10441. widget = lua_interface->GetSpawn(state);
  10442. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10443. lua_interface->ResetFunctionStack(state);
  10444. if (widget && widget->IsWidget())
  10445. {
  10446. ((Widget*)widget)->CloseDoor();
  10447. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10448. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10449. }
  10450. else
  10451. 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));
  10452. }
  10453. return 0;
  10454. }
  10455. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10456. if (!lua_interface)
  10457. return 0;
  10458. Spawn* widget = lua_interface->GetSpawn(state);
  10459. lua_interface->ResetFunctionStack(state);
  10460. if (widget && widget->IsWidget())
  10461. {
  10462. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10463. return 1;
  10464. }
  10465. return 0;
  10466. }
  10467. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10468. if (!lua_interface)
  10469. return 0;
  10470. sint32 min = lua_interface->GetSInt32Value(state);
  10471. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10472. lua_interface->ResetFunctionStack(state);
  10473. sint32 result = MakeRandomInt(min, max);
  10474. lua_interface->SetSInt32Value(state, result);
  10475. return 1;
  10476. }
  10477. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10478. if (!lua_interface)
  10479. return 0;
  10480. float min = lua_interface->GetFloatValue(state);
  10481. float max = lua_interface->GetFloatValue(state, 2);
  10482. lua_interface->ResetFunctionStack(state);
  10483. float result = MakeRandomFloat(min, max);
  10484. lua_interface->SetFloatValue(state, result);
  10485. return 1;
  10486. }
  10487. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10488. if (!lua_interface)
  10489. return 0;
  10490. Spawn* spawn = lua_interface->GetSpawn(state);
  10491. int32 value = lua_interface->GetInt32Value(state, 2);
  10492. lua_interface->ResetFunctionStack(state);
  10493. if(!spawn)
  10494. {
  10495. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10496. lua_interface->SetBooleanValue(state, false);
  10497. return 1;
  10498. }
  10499. spawn->AddIconValue(value);
  10500. lua_interface->SetBooleanValue(state, true);
  10501. return 1;
  10502. }
  10503. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10504. if (!lua_interface)
  10505. return 0;
  10506. Spawn* spawn = lua_interface->GetSpawn(state);
  10507. int32 value = lua_interface->GetInt32Value(state, 2);
  10508. lua_interface->ResetFunctionStack(state);
  10509. if(!spawn)
  10510. {
  10511. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10512. lua_interface->SetBooleanValue(state, false);
  10513. return 1;
  10514. }
  10515. spawn->RemoveIconValue(value);
  10516. lua_interface->SetBooleanValue(state, true);
  10517. return 1;
  10518. }
  10519. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10520. Spawn* npc = lua_interface->GetSpawn(state);
  10521. lua_interface->ResetFunctionStack(state);
  10522. if (npc && npc->IsNPC()) {
  10523. NPC* shard = (NPC*)npc;
  10524. int32 shardid = shard->GetShardID();
  10525. lua_interface->SetInt32Value(state, shardid);
  10526. return 1;
  10527. }
  10528. lua_interface->SetInt32Value(state, 0);
  10529. return 1;
  10530. }
  10531. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10532. Spawn* npc = lua_interface->GetSpawn(state);
  10533. lua_interface->ResetFunctionStack(state);
  10534. if (npc && npc->IsNPC()) {
  10535. NPC* shard = (NPC*)npc;
  10536. int32 charid = shard->GetShardCharID();
  10537. lua_interface->SetInt32Value(state, charid);
  10538. return 1;
  10539. }
  10540. lua_interface->SetInt32Value(state, 0);
  10541. return 1;
  10542. }
  10543. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10544. Spawn* npc = lua_interface->GetSpawn(state);
  10545. lua_interface->ResetFunctionStack(state);
  10546. if (npc && npc->IsNPC()) {
  10547. NPC* shard = (NPC*)npc;
  10548. int64 timestamp = shard->GetShardCreatedTimestamp();
  10549. lua_interface->SetSInt64Value(state, timestamp);
  10550. return 1;
  10551. }
  10552. lua_interface->SetSInt64Value(state, 0);
  10553. return 1;
  10554. }
  10555. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10556. if (!lua_interface)
  10557. return 0;
  10558. int32 shardid = lua_interface->GetInt32Value(state);
  10559. lua_interface->ResetFunctionStack(state);
  10560. if(shardid < 1)
  10561. lua_interface->SetBooleanValue(state, false);
  10562. else
  10563. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10564. return 1;
  10565. }
  10566. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10567. if (!lua_interface)
  10568. return 0;
  10569. Spawn* spawn = lua_interface->GetSpawn(state);
  10570. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10571. if (spawn) {
  10572. spawn->PauseMovement(delay_in_ms);
  10573. }
  10574. lua_interface->ResetFunctionStack(state);
  10575. return 0;
  10576. }
  10577. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10578. Player* player = (Player*)lua_interface->GetSpawn(state);
  10579. int8 level = lua_interface->GetInt8Value(state, 2);
  10580. lua_interface->ResetFunctionStack(state);
  10581. if (player && player->IsPlayer() && level > 0) {
  10582. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10583. return 1;
  10584. }
  10585. return 0;
  10586. }
  10587. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10588. Player* player = (Player*)lua_interface->GetSpawn(state);
  10589. int8 level = lua_interface->GetInt8Value(state, 2);
  10590. lua_interface->ResetFunctionStack(state);
  10591. if (player && player->IsPlayer() && level > 0) {
  10592. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10593. return 1;
  10594. }
  10595. return 0;
  10596. }