LuaFunctions.cpp 354 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570
  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. if (spawn) {
  346. spawn->GetZone()->SendStateCommand(spawn, new_state);
  347. }
  348. return 0;
  349. }
  350. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  351. if (!lua_interface)
  352. return 0;
  353. Spawn* spawn = lua_interface->GetSpawn(state);
  354. string variable = lua_interface->GetStringValue(state, 2);
  355. string value = lua_interface->GetStringValue(state, 3);
  356. 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.
  357. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  358. int32 type = commands.GetSpawnSetType(variable);
  359. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  360. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  361. return 0;
  362. }
  363. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  364. if (!lua_interface)
  365. return 0;
  366. Spawn* spawn = lua_interface->GetSpawn(state);
  367. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  368. if (spawn && spawn_id > 0) {
  369. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  370. if (closest_spawn) {
  371. lua_interface->SetSpawnValue(state, closest_spawn);
  372. return 1;
  373. }
  374. }
  375. return 0;
  376. }
  377. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  381. int32 position = lua_interface->GetInt32Value(state, 2);
  382. if (spawnList) {
  383. if (spawnList->size() > position) {
  384. lua_interface->SetSpawnValue(state, spawnList->at(position));
  385. return 1;
  386. }
  387. else {
  388. return 0;
  389. }
  390. return spawnList->size();
  391. }
  392. return 0;
  393. }
  394. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  395. if (!lua_interface)
  396. return 0;
  397. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  398. if (spawnList) {
  399. return spawnList->size();
  400. }
  401. return 0;
  402. }
  403. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  404. if (!lua_interface)
  405. return 0;
  406. vector<Spawn*>* spawnList = new vector<Spawn*>();
  407. lua_interface->SetSpawnListValue(state, spawnList);
  408. return 1;
  409. }
  410. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  411. if (!lua_interface)
  412. return 0;
  413. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  414. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  415. if (spawnList) {
  416. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  417. if (it == spawnList->end())
  418. spawnList->push_back(spawn);
  419. }
  420. return 0;
  421. }
  422. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  423. if (!lua_interface)
  424. return 0;
  425. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  427. if (spawnList) {
  428. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  429. if(it != spawnList->end())
  430. spawnList->erase(it);
  431. }
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. if (spawn) {
  440. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  441. if (spawns.size() > 0) {
  442. vector<Spawn*>* spawnList = new vector<Spawn*>();
  443. vector<Spawn*>::iterator itr;
  444. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  445. spawnList->push_back(*itr);
  446. }
  447. lua_interface->SetSpawnListValue(state, spawnList);
  448. return 1;
  449. }
  450. }
  451. return 0;
  452. }
  453. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  454. if (!lua_interface)
  455. return 0;
  456. string variable_name = lua_interface->GetStringValue(state);
  457. Variable* var = variables.FindVariable(variable_name);
  458. if (var) {
  459. lua_interface->SetStringValue(state, var->GetValue());
  460. return 1;
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. int32 total_coins = lua_interface->GetInt32Value(state);
  468. if (total_coins == 0) {
  469. lua_interface->SetStringValue(state, "0 copper");
  470. return 1;
  471. }
  472. char tmp[64] = { 0 };
  473. string message = "";
  474. int32 val = 0;
  475. if (total_coins >= 1000000) {
  476. val = total_coins / 1000000;
  477. total_coins -= 1000000 * val;
  478. sprintf(tmp, " %u Platinum", val);
  479. message.append(tmp);
  480. memset(tmp, 0, 64);
  481. }
  482. if (total_coins >= 10000) {
  483. val = total_coins / 10000;
  484. total_coins -= 10000 * val;
  485. sprintf(tmp, " %u Gold", val);
  486. message.append(tmp);
  487. memset(tmp, 0, 64);
  488. }
  489. if (total_coins >= 100) {
  490. val = total_coins / 100;
  491. total_coins -= 100 * val;
  492. sprintf(tmp, " %u Silver", val);
  493. message.append(tmp);
  494. memset(tmp, 0, 64);
  495. }
  496. if (total_coins > 0) {
  497. sprintf(tmp, " %u Copper", (int32)total_coins);
  498. message.append(tmp);
  499. }
  500. lua_interface->SetStringValue(state, message.c_str());
  501. return 1;
  502. }
  503. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  504. ZoneServer* zone = lua_interface->GetZone(state);
  505. int32 group_id = lua_interface->GetInt32Value(state, 2);
  506. if (zone) {
  507. Spawn* spawn = zone->GetSpawnGroup(group_id);
  508. if (spawn) {
  509. lua_interface->SetSpawnValue(state, spawn);
  510. return 1;
  511. }
  512. }
  513. return 0;
  514. }
  515. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  516. ZoneServer* zone = lua_interface->GetZone(state);
  517. int32 location_id = lua_interface->GetInt32Value(state, 2);
  518. if (zone) {
  519. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  520. if (spawn) {
  521. lua_interface->SetSpawnValue(state, spawn);
  522. return 1;
  523. }
  524. }
  525. return 0;
  526. }
  527. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. if (spawn) {
  530. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  536. Spawn* spawn = lua_interface->GetSpawn(state);
  537. if (spawn) {
  538. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  539. return 1;
  540. }
  541. return 0;
  542. }
  543. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  544. Spawn* spawn = lua_interface->GetSpawn(state);
  545. if (spawn) {
  546. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  547. return 1;
  548. }
  549. return 0;
  550. }
  551. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  552. Spawn* spawn = lua_interface->GetSpawn(state);
  553. if (spawn) {
  554. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  555. return 1;
  556. }
  557. return 0;
  558. }
  559. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  560. Player* player = (Player*)lua_interface->GetSpawn(state);
  561. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  562. if (player && player->IsPlayer() && faction_id > 0) {
  563. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  569. if (!lua_interface)
  570. return 0;
  571. Spawn* spawn = lua_interface->GetSpawn(state);
  572. int32 value = lua_interface->GetInt32Value(state, 2);
  573. if (spawn) {
  574. spawn->SetFactionID(value);
  575. }
  576. return 0;
  577. }
  578. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  579. Spawn* spawn = lua_interface->GetSpawn(state);
  580. if (spawn) {
  581. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  582. return 1;
  583. }
  584. return 0;
  585. }
  586. int EQ2Emu_lua_GetGender(lua_State* state) {
  587. Spawn* spawn = lua_interface->GetSpawn(state);
  588. if (spawn) {
  589. lua_interface->SetInt32Value(state, spawn->GetGender());
  590. return 1;
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetTarget(lua_State* state) {
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  597. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  598. return 1;
  599. }
  600. return 0;
  601. }
  602. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  603. if (!lua_interface)
  604. return 0;
  605. Spawn* spawn = lua_interface->GetSpawn(state);
  606. string mp3_string = lua_interface->GetStringValue(state, 2);
  607. int32 key1 = lua_interface->GetInt32Value(state, 3);
  608. int32 key2 = lua_interface->GetInt32Value(state, 4);
  609. Spawn* player = lua_interface->GetSpawn(state, 5);
  610. if (spawn && mp3_string.length() > 0) {
  611. Client* client = 0;
  612. if (player && player->IsPlayer())
  613. client = spawn->GetZone()->GetClientBySpawn(player);
  614. if (client) {
  615. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  616. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  617. }
  618. else
  619. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  620. }
  621. return 0;
  622. }
  623. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  624. if (!lua_interface)
  625. return 0;
  626. Spawn* spawn = lua_interface->GetSpawn(state);
  627. if (spawn) {
  628. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  629. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  630. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  631. return 3;
  632. }
  633. return 0;
  634. }
  635. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  636. if (!lua_interface)
  637. return 0;
  638. Spawn* spawn = lua_interface->GetSpawn(state);
  639. if (spawn) {
  640. int32 item_id = lua_interface->GetInt32Value(state, 2);
  641. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  642. return 1;
  643. }
  644. return 0;
  645. }
  646. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  647. if (!lua_interface)
  648. return 0;
  649. Spawn* spawn = lua_interface->GetSpawn(state);
  650. if (spawn && spawn->IsEntity()) {
  651. int32 item_id = lua_interface->GetInt32Value(state, 2);
  652. int16 charges = lua_interface->GetInt16Value(state, 3);
  653. if (charges == 0)
  654. charges = 1;
  655. ((Entity*)spawn)->AddLootItem(item_id, charges);
  656. }
  657. return 0;
  658. }
  659. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  660. if (!lua_interface)
  661. return 0;
  662. Spawn* spawn = lua_interface->GetSpawn(state);
  663. if (spawn && spawn->IsEntity()) {
  664. int32 item_id = lua_interface->GetInt32Value(state, 2);
  665. spawn->LootItem(item_id);
  666. }
  667. return 0;
  668. }
  669. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  670. if (!lua_interface)
  671. return 0;
  672. Spawn* spawn = lua_interface->GetSpawn(state);
  673. if (spawn) {
  674. int32 val = lua_interface->GetInt32Value(state, 2);
  675. spawn->AddLootCoins(val);
  676. }
  677. return 0;
  678. }
  679. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* entity = lua_interface->GetSpawn(state);
  683. Spawn* player = lua_interface->GetSpawn(state, 2);
  684. if (entity && player && player->IsPlayer()) {
  685. int32 coins = lua_interface->GetInt32Value(state, 3);
  686. vector<Item*>* items = 0;
  687. int i = 0;
  688. int32 item_id = 0;
  689. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  690. if (items == 0)
  691. items = new vector<Item*>;
  692. if (master_item_list.GetItem(item_id))
  693. items->push_back(master_item_list.GetItem(item_id));
  694. i++;
  695. }
  696. Client* client = 0;
  697. client = player->GetZone()->GetClientBySpawn(player);
  698. if (client)
  699. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  700. if(coins > 0)
  701. entity->AddLootCoins(coins);
  702. safe_delete(items);
  703. }
  704. return 0;
  705. }
  706. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  707. if (!lua_interface)
  708. return 0;
  709. Spawn* entity = lua_interface->GetSpawn(state);
  710. Spawn* player = lua_interface->GetSpawn(state, 2);
  711. int32 item_id = lua_interface->GetInt32Value(state, 3);
  712. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  713. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  714. return 1;
  715. }
  716. return 0;
  717. }
  718. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  719. if (!lua_interface)
  720. return 0;
  721. Spawn* entity = lua_interface->GetSpawn(state);
  722. Spawn* player = lua_interface->GetSpawn(state, 2);
  723. if (entity && player && player->IsPlayer()) {
  724. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  725. return 1;
  726. }
  727. return 0;
  728. }
  729. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  730. if (!lua_interface)
  731. return 0;
  732. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  733. safe_delete(conversation);
  734. conversation = new vector<ConversationOption>();
  735. lua_interface->SetConversationValue(state, conversation);
  736. return 1;
  737. }
  738. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  739. if (!lua_interface)
  740. return 0;
  741. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  742. if (conversation) {
  743. ConversationOption conv_option;
  744. conv_option.option = lua_interface->GetStringValue(state, 2);
  745. conv_option.function = lua_interface->GetStringValue(state, 3);
  746. if (conv_option.option.length() > 0)
  747. conversation->push_back(conv_option);
  748. }
  749. return 0;
  750. }
  751. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* npc = lua_interface->GetSpawn(state);
  755. Spawn* player = lua_interface->GetSpawn(state, 2);
  756. if (npc && player && player->IsPlayer() && player->GetZone()) {
  757. Client* client = player->GetZone()->GetClientBySpawn(player);
  758. if (client) {
  759. int32 conversation_id = client->GetConversationID(npc, 0);
  760. client->CloseDialog(conversation_id);
  761. }
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Item* item = lua_interface->GetItem(state);
  769. Spawn* player = lua_interface->GetSpawn(state, 2);
  770. if (item && player && player->IsPlayer() && player->GetZone()) {
  771. Client* client = player->GetZone()->GetClientBySpawn(player);
  772. if (client) {
  773. int32 conversation_id = client->GetConversationID(0, item);
  774. client->CloseDialog(conversation_id);
  775. }
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  783. Spawn* spawn = 0;
  784. Item* item = 0;
  785. int8 type = lua_interface->GetInt8Value(state, 2);
  786. if (type == 1 || type == 3)
  787. spawn = lua_interface->GetSpawn(state, 3);
  788. else if (type == 2 || type == 4)
  789. item = lua_interface->GetItem(state, 3);
  790. Spawn* player = lua_interface->GetSpawn(state, 4);
  791. string text = lua_interface->GetStringValue(state, 5);
  792. string mp3 = lua_interface->GetStringValue(state, 6);
  793. int32 key1 = lua_interface->GetInt32Value(state, 7);
  794. int32 key2 = lua_interface->GetInt32Value(state, 8);
  795. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  796. Client* client = player->GetZone()->GetClientBySpawn(player);
  797. if (client) {
  798. if (spawn) {
  799. // Need to do this so the function works the same as it did before
  800. if (type == 1)
  801. type++;
  802. if (mp3.length() > 0)
  803. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  804. else
  805. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  806. }
  807. else {
  808. if (mp3.length() > 0)
  809. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  810. else
  811. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  812. }
  813. }
  814. }
  815. safe_delete(conversation);
  816. lua_interface->SetConversationValue(state, NULL);
  817. return 0;
  818. }
  819. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  820. if(!lua_interface)
  821. return 0;
  822. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  823. Item* item = lua_interface->GetItem(state, 2);
  824. Spawn* player = lua_interface->GetSpawn(state, 3);
  825. string text = lua_interface->GetStringValue(state, 4);
  826. string mp3 = lua_interface->GetStringValue(state, 5);
  827. int32 key1 = lua_interface->GetInt32Value(state, 6);
  828. int32 key2 = lua_interface->GetInt32Value(state, 7);
  829. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  830. Client* client = player->GetZone()->GetClientBySpawn(player);
  831. if(client){
  832. if(mp3.length() > 0)
  833. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  834. else
  835. client->DisplayConversation(item, conversation, (char*)text.c_str());
  836. }
  837. safe_delete(conversation);
  838. }
  839. return 0;
  840. }*/
  841. int EQ2Emu_lua_StartConversation(lua_State* state) {
  842. if (!lua_interface)
  843. return 0;
  844. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  845. Spawn* npc = lua_interface->GetSpawn(state, 2);
  846. Spawn* player = lua_interface->GetSpawn(state, 3);
  847. string text = lua_interface->GetStringValue(state, 4);
  848. string mp3 = lua_interface->GetStringValue(state, 5);
  849. int32 key1 = lua_interface->GetInt32Value(state, 6);
  850. int32 key2 = lua_interface->GetInt32Value(state, 7);
  851. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  852. Client* client = npc->GetZone()->GetClientBySpawn(player);
  853. if (mp3.length() > 0)
  854. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  855. else
  856. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  857. safe_delete(conversation);
  858. lua_interface->SetConversationValue(state, NULL);
  859. }
  860. else
  861. 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.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  862. return 0;
  863. }
  864. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  865. if (!lua_interface)
  866. return 0;
  867. Spawn* spawn = lua_interface->GetSpawn(state);
  868. float distance = lua_interface->GetFloatValue(state, 2);
  869. string in_range_function = lua_interface->GetStringValue(state, 3);
  870. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  871. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  872. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  876. ZoneServer* zone = lua_interface->GetZone(state);
  877. float x = lua_interface->GetFloatValue(state, 2);
  878. float y = lua_interface->GetFloatValue(state, 3);
  879. float z = lua_interface->GetFloatValue(state, 4);
  880. float max_variation = lua_interface->GetFloatValue(state, 5);
  881. string in_range_function = lua_interface->GetStringValue(state, 6);
  882. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  883. if (zone && in_range_function.length() > 0)
  884. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  885. return 0;
  886. }
  887. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  888. if (!lua_interface)
  889. return 0;
  890. Spawn* spawn = lua_interface->GetSpawn(state);
  891. if (spawn && spawn->IsEntity()) {
  892. int32 val = lua_interface->GetInt32Value(state, 2);
  893. ((Entity*)spawn)->SetLootCoins(val);
  894. }
  895. return 0;
  896. }
  897. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. Spawn* spawn = lua_interface->GetSpawn(state);
  901. if (spawn && spawn->IsEntity()) {
  902. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  903. return 1;
  904. }
  905. return 0;
  906. }
  907. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. Spawn* spawn = lua_interface->GetSpawn(state);
  911. float x = lua_interface->GetFloatValue(state, 2);
  912. float y = lua_interface->GetFloatValue(state, 3);
  913. float z = lua_interface->GetFloatValue(state, 4);
  914. float speed = lua_interface->GetFloatValue(state, 5);
  915. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  916. string function = lua_interface->GetStringValue(state, 7);
  917. if (spawn) {
  918. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  919. spawn->GetZone()->AddMovementNPC(spawn);
  920. }
  921. lua_interface->ResetFunctionStack(state);
  922. return 0;
  923. }
  924. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  925. if (!lua_interface)
  926. return 0;
  927. Spawn* spawn = lua_interface->GetSpawn(state);
  928. if (spawn) {
  929. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  930. return 1;
  931. }
  932. return 0;
  933. }
  934. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  935. if (!lua_interface)
  936. return 0;
  937. Spawn* spawn = lua_interface->GetSpawn(state);
  938. Spawn* target = lua_interface->GetSpawn(state, 2);
  939. if (spawn && target) {
  940. if (spawn->IsEntity())
  941. // ((Entity*)spawn)->FaceTarget(target);
  942. static_cast<Entity*>(spawn)->FaceTarget(target);
  943. }
  944. lua_interface->ResetFunctionStack(state);
  945. return 0;
  946. }
  947. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  948. if (!lua_interface)
  949. return 0;
  950. Spawn* spawn = lua_interface->GetSpawn(state);
  951. float x = lua_interface->GetFloatValue(state, 2);
  952. float y = lua_interface->GetFloatValue(state, 3);
  953. float z = lua_interface->GetFloatValue(state, 4);
  954. float speed = lua_interface->GetFloatValue(state, 5);
  955. string lua_function = lua_interface->GetStringValue(state, 6);
  956. bool more_points = lua_interface->GetBooleanValue(state, 7);
  957. if (spawn) {
  958. if (speed == 0)
  959. speed = spawn->GetSpeed();
  960. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  961. }
  962. lua_interface->ResetFunctionStack(state);
  963. return 0;
  964. }
  965. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  966. if (!lua_interface)
  967. return 0;
  968. Spawn* spawn = lua_interface->GetSpawn(state);
  969. if (spawn) {
  970. spawn->ClearRunningLocations();
  971. }
  972. return 0;
  973. }
  974. int EQ2Emu_lua_Say(lua_State* state) {
  975. if (!lua_interface)
  976. return 0;
  977. Spawn* spawn = lua_interface->GetSpawn(state);
  978. string message = lua_interface->GetStringValue(state, 2);
  979. Spawn* player = lua_interface->GetSpawn(state, 3);
  980. int32 language = lua_interface->GetInt32Value(state, 4);
  981. if (spawn && message.length() > 0) {
  982. Client* client = 0;
  983. if (player && player->IsPlayer())
  984. client = spawn->GetZone()->GetClientBySpawn(player);
  985. if (client)
  986. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  987. else
  988. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  989. }
  990. lua_interface->ResetFunctionStack(state);
  991. return 0;
  992. }
  993. int EQ2Emu_lua_Shout(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. string message = lua_interface->GetStringValue(state, 2);
  998. Spawn* player = lua_interface->GetSpawn(state, 3);
  999. if (spawn && message.length() > 0) {
  1000. Client* client = 0;
  1001. if (player && player->IsPlayer())
  1002. client = spawn->GetZone()->GetClientBySpawn(player);
  1003. if (client)
  1004. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1005. else
  1006. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1007. }
  1008. lua_interface->ResetFunctionStack(state);
  1009. return 0;
  1010. }
  1011. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1012. if (!lua_interface)
  1013. return 0;
  1014. Spawn* spawn = lua_interface->GetSpawn(state);
  1015. string message = lua_interface->GetStringValue(state, 2);
  1016. Spawn* player = lua_interface->GetSpawn(state, 3);
  1017. if (spawn && message.length() > 0) {
  1018. Client* client = 0;
  1019. if (player && player->IsPlayer())
  1020. client = spawn->GetZone()->GetClientBySpawn(player);
  1021. if (client)
  1022. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1023. else
  1024. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1025. }
  1026. lua_interface->ResetFunctionStack(state);
  1027. return 0;
  1028. }
  1029. int EQ2Emu_lua_Emote(lua_State* state) {
  1030. if (!lua_interface)
  1031. return 0;
  1032. Spawn* spawn = lua_interface->GetSpawn(state);
  1033. string message = lua_interface->GetStringValue(state, 2);
  1034. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1035. Spawn* player = lua_interface->GetSpawn(state, 4);
  1036. char* to = 0;
  1037. if (spawn2)
  1038. to = spawn2->GetName();
  1039. if (spawn && message.length() > 0) {
  1040. Client* client = 0;
  1041. if (player && player->IsPlayer())
  1042. client = spawn->GetZone()->GetClientBySpawn(player);
  1043. if (client)
  1044. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1045. else
  1046. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1047. }
  1048. lua_interface->ResetFunctionStack(state);
  1049. return 0;
  1050. }
  1051. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1052. if (!lua_interface)
  1053. return 0;
  1054. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1055. if (!luaspell)
  1056. return 0;
  1057. Spawn* caster = luaspell->caster;
  1058. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1059. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1060. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1061. Spawn* target = lua_interface->GetSpawn(state, 4);
  1062. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1063. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1064. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (caster && caster->IsEntity()) {
  1067. bool success = false;
  1068. luaspell->resisted = false;
  1069. if (target) {
  1070. float distance = caster->GetDistance(target, true);
  1071. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1072. success = true;
  1073. }
  1074. if (luaspell->targets.size() > 0) {
  1075. Spawn* target = 0;
  1076. ZoneServer* zone = luaspell->caster->GetZone();
  1077. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1078. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1079. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1080. float distance = caster->GetDistance(target, true);
  1081. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1082. }
  1083. }
  1084. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1085. success = true;
  1086. }
  1087. if (success) {
  1088. if (caster->GetZone())
  1089. caster->GetZone()->TriggerCharSheetTimer();
  1090. }
  1091. }
  1092. return 0;
  1093. }
  1094. int EQ2Emu_lua_AddItem(lua_State* state) {
  1095. if (!lua_interface)
  1096. return 0;
  1097. Spawn* spawn = lua_interface->GetSpawn(state);
  1098. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1099. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1100. // default of 1 quantity to add
  1101. if (quantity == 0)
  1102. quantity = 1;
  1103. if (spawn && spawn->IsPlayer()) {
  1104. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1105. if (client && item_id > 0) {
  1106. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1107. return 1;
  1108. }
  1109. }
  1110. lua_interface->SetBooleanValue(state, false);
  1111. return 1;
  1112. }
  1113. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1114. if (!lua_interface)
  1115. return 0;
  1116. Spawn* spawn = lua_interface->GetSpawn(state);
  1117. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1118. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1119. string location = lua_interface->GetStringValue(state, 4);
  1120. if (spawn && spawn->IsPlayer()) {
  1121. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1122. if (client && item_id > 0) {
  1123. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1124. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1125. else
  1126. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1127. if (send_messages) {
  1128. Item* item = master_item_list.GetItem(item_id);
  1129. if (item) {
  1130. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1131. string popup_text = "You receive " + item->name;
  1132. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1133. }
  1134. }
  1135. return 1;
  1136. }
  1137. }
  1138. lua_interface->SetBooleanValue(state, false);
  1139. return 1;
  1140. }
  1141. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1142. Spawn* spawn = lua_interface->GetSpawn(state);
  1143. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1144. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1145. // default of 1 to remove
  1146. if (quantity == 0)
  1147. quantity = 1;
  1148. Client* client;
  1149. Item* item;
  1150. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1151. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1152. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1153. if (client->RemoveItem(item, quantity)) {
  1154. lua_interface->SetBooleanValue(state, true);
  1155. return 1;
  1156. }
  1157. }
  1158. }
  1159. }
  1160. lua_interface->SetBooleanValue(state, false);
  1161. return 1;
  1162. }
  1163. int EQ2Emu_lua_HasItem(lua_State* state) {
  1164. Spawn* player = lua_interface->GetSpawn(state);
  1165. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1166. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1167. if (player && player->IsPlayer()) {
  1168. bool hasItem = false;
  1169. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1170. if (!hasItem)
  1171. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1172. lua_interface->SetBooleanValue(state, hasItem);
  1173. return 1;
  1174. }
  1175. lua_interface->SetBooleanValue(state, false);
  1176. return 1;
  1177. }
  1178. int EQ2Emu_lua_Spawn(lua_State* state) {
  1179. if (!lua_interface)
  1180. return 0;
  1181. ZoneServer* zone = lua_interface->GetZone(state);
  1182. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1183. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1184. float x = lua_interface->GetFloatValue(state, 4);
  1185. float y = lua_interface->GetFloatValue(state, 5);
  1186. float z = lua_interface->GetFloatValue(state, 6);
  1187. float heading = lua_interface->GetFloatValue(state, 7);
  1188. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1189. Spawn* spawn = zone->GetSpawn(spawn_id);
  1190. if (!spawn)
  1191. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1192. else {
  1193. spawn->SetX(x);
  1194. spawn->SetZ(z);
  1195. spawn->SetY(y,true,true);
  1196. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1197. spawn->SetHeading(heading);
  1198. if (restricted_npc)
  1199. spawn->AddAllowAccessSpawn(spawn);
  1200. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1201. bool scriptActive = false;
  1202. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1203. scriptActive = true;
  1204. spawn->SetSpawnScript(string(spawn_script));
  1205. }
  1206. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1207. zone->AddSpawn(spawn);
  1208. if (scriptActive) {
  1209. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1210. }
  1211. lua_interface->SetSpawnValue(state, spawn);
  1212. return 1;
  1213. }
  1214. }
  1215. else {
  1216. string output = "Invalid paramaters to LUA Spawn command: \n";
  1217. if (!zone)
  1218. output = output.append("\t").append("Missing zone reference. \n");
  1219. if (spawn_id == 0)
  1220. output = output.append("\t").append("Missing spawn_id.");
  1221. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1222. }
  1223. return 0;
  1224. }
  1225. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1226. if (!lua_interface)
  1227. return 0;
  1228. ZoneServer* zone = lua_interface->GetZone(state);
  1229. if (zone) {
  1230. lua_interface->SetStringValue(state, zone->GetZoneName());
  1231. return 1;
  1232. }
  1233. return 0;
  1234. }
  1235. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1236. if (!lua_interface)
  1237. return 0;
  1238. ZoneServer* zone = lua_interface->GetZone(state);
  1239. if (zone) {
  1240. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1241. return 1;
  1242. }
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_GetZone(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. int32 zone_id = lua_interface->GetInt32Value(state);
  1249. ZoneServer* zone = 0;
  1250. if (zone_id > 0)
  1251. zone = zone_list.Get(zone_id);
  1252. else {
  1253. string zone_name = lua_interface->GetStringValue(state);
  1254. if (zone_name.length() > 0) {
  1255. zone = zone_list.Get(zone_name.c_str());
  1256. }
  1257. else {
  1258. Spawn* spawn = lua_interface->GetSpawn(state);
  1259. if (spawn)
  1260. zone = spawn->GetZone();
  1261. }
  1262. }
  1263. if (zone) {
  1264. lua_interface->SetZoneValue(state, zone);
  1265. return 1;
  1266. }
  1267. return 0;
  1268. }
  1269. int EQ2Emu_lua_AddHate(lua_State* state) {
  1270. Spawn* entity = lua_interface->GetSpawn(state);
  1271. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1272. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1273. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1274. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1275. if (entity && entity->IsEntity() && amount != 0) {
  1276. if (luaspell) {
  1277. ZoneServer* zone = luaspell->caster->GetZone();
  1278. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1279. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1280. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1281. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1282. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1283. if (send_packet)
  1284. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1285. }
  1286. }
  1287. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1288. }
  1289. else if (npc && npc->IsNPC() && npc->GetZone())
  1290. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1291. }
  1292. return 0;
  1293. }
  1294. int EQ2Emu_lua_Zone(lua_State* state) {
  1295. if (!lua_interface)
  1296. return 0;
  1297. ZoneServer* zone = lua_interface->GetZone(state);
  1298. Spawn* player = lua_interface->GetSpawn(state, 2);
  1299. Client* client = 0;
  1300. if (player && player->IsPlayer())
  1301. client = player->GetZone()->GetClientBySpawn(player);
  1302. float x = lua_interface->GetFloatValue(state, 3);
  1303. float y = lua_interface->GetFloatValue(state, 4);
  1304. float z = lua_interface->GetFloatValue(state, 5);
  1305. float heading = lua_interface->GetFloatValue(state, 6);
  1306. if (zone && client) {
  1307. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1308. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1309. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1310. {
  1311. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1312. return 0;
  1313. }
  1314. if (x != 0 || y != 0 || z != 0) {
  1315. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1316. player->SetX(x);
  1317. player->SetY(y);
  1318. player->SetZ(z);
  1319. player->SetHeading(heading);
  1320. client->Zone(zone->GetZoneName(), false);
  1321. }
  1322. else
  1323. client->Zone(zone->GetZoneName());
  1324. }
  1325. else
  1326. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1327. return 0;
  1328. }
  1329. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1330. if (!lua_interface)
  1331. return 0;
  1332. Spawn* spawn = lua_interface->GetSpawn(state);
  1333. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1334. if (spawn && spawn2)
  1335. spawn->AddAllowAccessSpawn(spawn2);
  1336. return 0;
  1337. }
  1338. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1339. if (!lua_interface)
  1340. return 0;
  1341. Spawn* target = lua_interface->GetSpawn(state);
  1342. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1343. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1344. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1345. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1346. if (!target) {
  1347. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1348. return 0;
  1349. }
  1350. if (!target->IsEntity()) {
  1351. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1352. return 0;
  1353. }
  1354. if (spell_id <= 0) {
  1355. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1356. return 0;
  1357. }
  1358. if (caster && !caster->IsEntity()) {
  1359. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1360. return 0;
  1361. }
  1362. if (spell_tier == 0)
  1363. spell_tier = 1;
  1364. if (!caster)
  1365. caster = target;
  1366. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1367. return 0;
  1368. }
  1369. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1370. if (!lua_interface)
  1371. return 0;
  1372. Spawn* target = lua_interface->GetSpawn(state);
  1373. int32 target_id = 0;
  1374. if (target)
  1375. target_id = target->GetID();
  1376. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1377. if (!luaspell)
  1378. return 0;
  1379. Spawn* caster = luaspell->caster;
  1380. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1381. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1382. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1383. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1384. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1385. //lua_interface->ResetFunctionStack(state);
  1386. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1387. vector<int16> faction_req;
  1388. vector<int16> race_req;
  1389. int32 class_req = 0;
  1390. int32 i = 0;
  1391. int8 f = 0;
  1392. int8 r = 0;
  1393. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1394. if (class_id < 100) {
  1395. class_req += pow(2.0, double(class_id - 1));
  1396. }
  1397. else if (class_id > 100 && class_id < 1000) {
  1398. race_req.push_back(class_id);
  1399. r++;
  1400. }
  1401. else {
  1402. faction_req.push_back(class_id);
  1403. f++;
  1404. }
  1405. i++;
  1406. }
  1407. if (caster && caster->IsEntity()) {
  1408. bool race_match = false;
  1409. bool success = false;
  1410. luaspell->resisted = false;
  1411. if (luaspell->initial_target == target_id) {
  1412. int xxx = 0;
  1413. }
  1414. if (luaspell->targets.size() > 0) {
  1415. ZoneServer* zone = luaspell->caster->GetZone();
  1416. Spawn* target = 0;
  1417. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1418. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1419. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1420. if (race_req.size() > 0) {
  1421. for (int8 i = 0; i < race_req.size(); i++) {
  1422. int32 xxx = target->GetLuaRaceId();
  1423. if (target->GetLuaRaceId() == race_req[i]) {
  1424. race_match = true;
  1425. }
  1426. }
  1427. }
  1428. else
  1429. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1430. if (race_match == true) {
  1431. float distance = caster->GetDistance(target, true);
  1432. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1433. }
  1434. }
  1435. }
  1436. success = true;
  1437. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1438. }
  1439. else if (target) {
  1440. //check class and race/faction here
  1441. if (race_req.size() > 0) {
  1442. for (int8 i = 0; i < race_req.size(); i++) {
  1443. if (target->GetLuaRaceId() == race_req[i]) {
  1444. race_match = true;
  1445. }
  1446. }
  1447. }
  1448. else
  1449. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1450. if (race_match == true) {
  1451. float distance = caster->GetDistance(target, true);
  1452. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1453. success = true;
  1454. }
  1455. }
  1456. if (success) {
  1457. Spell* spell = luaspell->spell;
  1458. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1459. ((Player*)caster)->InCombat(true);
  1460. if (caster->GetZone())
  1461. caster->GetZone()->TriggerCharSheetTimer();
  1462. }
  1463. }
  1464. }
  1465. return 0;
  1466. }
  1467. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1468. if (!lua_interface)
  1469. return 0;
  1470. Spawn* spawn = lua_interface->GetSpawn(state);
  1471. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1472. lua_interface->ResetFunctionStack(state);
  1473. if (spawn && value != 0) {
  1474. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1475. spawn->SetPower(spawn->GetTotalPower());
  1476. else
  1477. spawn->SetPower(spawn->GetPower() + value);
  1478. }
  1479. return 0;
  1480. }
  1481. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1482. if (!lua_interface)
  1483. return 0;
  1484. Spawn* spawn = lua_interface->GetSpawn(state);
  1485. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1486. lua_interface->ResetFunctionStack(state);
  1487. if (spawn && value != 0) {
  1488. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1489. spawn->SetHP(spawn->GetTotalHP());
  1490. else
  1491. spawn->SetHP(spawn->GetHP() + value);
  1492. }
  1493. return 0;
  1494. }
  1495. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1496. if (!lua_interface)
  1497. return 0;
  1498. Spawn* spawn = lua_interface->GetSpawn(state);
  1499. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1500. lua_interface->ResetFunctionStack(state);
  1501. if (spawn && value != 0) {
  1502. spawn->SetPower(spawn->GetPower() + value);
  1503. if (value > spawn->GetTotalHPBase())
  1504. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1505. }
  1506. return 0;
  1507. }
  1508. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1509. if (!lua_interface)
  1510. return 0;
  1511. Spawn* spawn = lua_interface->GetSpawn(state);
  1512. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1513. lua_interface->ResetFunctionStack(state);
  1514. if (spawn && value != 0) {
  1515. spawn->SetHP(spawn->GetHP() + value);
  1516. if (value > spawn->GetTotalHPBase())
  1517. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1518. }
  1519. return 0;
  1520. }
  1521. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1522. if (!lua_interface)
  1523. return 0;
  1524. Spawn* spawn = lua_interface->GetSpawn(state);
  1525. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1526. lua_interface->ResetFunctionStack(state);
  1527. if (spawn) {
  1528. spawn->SetHP(value);
  1529. if (value > spawn->GetTotalHPBase())
  1530. spawn->SetTotalHP(value);
  1531. }
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. Spawn* spawn = lua_interface->GetSpawn(state);
  1538. float value = lua_interface->GetFloatValue(state, 2);
  1539. lua_interface->ResetFunctionStack(state);
  1540. if (spawn && spawn->IsEntity() && value > 0)
  1541. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1542. if (spawn->IsPlayer())
  1543. ((Player*)spawn)->SetCharSheetChanged(true);
  1544. return 0;
  1545. }
  1546. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1547. if (!lua_interface)
  1548. return 0;
  1549. Spawn* spawn = lua_interface->GetSpawn(state);
  1550. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1551. lua_interface->ResetFunctionStack(state);
  1552. if (spawn && spawn->IsEntity() && value > 0)
  1553. ((Entity*)spawn)->SetTotalHPBase(value);
  1554. return 0;
  1555. }
  1556. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1557. if (!lua_interface)
  1558. return 0;
  1559. Spawn* spawn = lua_interface->GetSpawn(state);
  1560. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1561. lua_interface->ResetFunctionStack(state);
  1562. if (spawn && value > 0) {
  1563. spawn->SetPower(value);
  1564. if (value > spawn->GetTotalPowerBase())
  1565. spawn->SetTotalPower(value);
  1566. }
  1567. return 0;
  1568. }
  1569. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1570. if (!lua_interface)
  1571. return 0;
  1572. Spawn* spawn = lua_interface->GetSpawn(state);
  1573. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1574. lua_interface->ResetFunctionStack(state);
  1575. if (spawn && spawn->IsEntity() && value > 0)
  1576. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1577. return 0;
  1578. }
  1579. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1580. if (!lua_interface)
  1581. return 0;
  1582. Spawn* spawn = lua_interface->GetSpawn(state);
  1583. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1584. lua_interface->ResetFunctionStack(state);
  1585. if (spawn && spawn->IsEntity() && value > 0)
  1586. ((Entity*)spawn)->SetTotalPowerBase(value);
  1587. return 0;
  1588. }
  1589. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1590. if (!lua_interface)
  1591. return 0;
  1592. Spawn* spawn = lua_interface->GetSpawn(state);
  1593. float x = lua_interface->GetFloatValue(state, 2);
  1594. float y = lua_interface->GetFloatValue(state, 3);
  1595. float z = lua_interface->GetFloatValue(state, 4);
  1596. float heading = lua_interface->GetFloatValue(state, 5);
  1597. lua_interface->ResetFunctionStack(state);
  1598. if (spawn) {
  1599. spawn->SetX(x);
  1600. spawn->SetY(y);
  1601. spawn->SetZ(z);
  1602. if (heading != 0)
  1603. spawn->SetHeading(heading);
  1604. spawn->SetSpawnOrigX(spawn->GetX());
  1605. spawn->SetSpawnOrigY(spawn->GetY());
  1606. spawn->SetSpawnOrigZ(spawn->GetZ());
  1607. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1608. if (spawn->IsPlayer()) {
  1609. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1610. if (client) {
  1611. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1612. client->QueuePacket(packet);
  1613. }
  1614. }
  1615. }
  1616. return 0;
  1617. }
  1618. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1619. if (!lua_interface)
  1620. return 0;
  1621. Spawn* spawn = lua_interface->GetSpawn(state);
  1622. float value = lua_interface->GetFloatValue(state, 2);
  1623. lua_interface->ResetFunctionStack(state);
  1624. if (spawn) {
  1625. spawn->SetHeading(value);
  1626. if (spawn->IsPlayer()) {
  1627. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1628. if (client) {
  1629. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1630. client->QueuePacket(packet);
  1631. }
  1632. }
  1633. }
  1634. return 0;
  1635. }
  1636. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1637. if (!lua_interface)
  1638. return 0;
  1639. Spawn* spawn = lua_interface->GetSpawn(state);
  1640. int16 value = lua_interface->GetInt16Value(state, 2);
  1641. lua_interface->ResetFunctionStack(state);
  1642. if (spawn)
  1643. spawn->SetModelType(value);
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* spawn = lua_interface->GetSpawn(state);
  1650. int8 value = lua_interface->GetInt8Value(state, 2);
  1651. lua_interface->ResetFunctionStack(state);
  1652. if (spawn) {
  1653. if (spawn->IsPlayer())
  1654. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1655. else
  1656. spawn->SetAdventureClass(value);
  1657. }
  1658. return 0;
  1659. }
  1660. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1661. if (!lua_interface)
  1662. return 0;
  1663. Spawn* spawn = lua_interface->GetSpawn(state);
  1664. int8 value = lua_interface->GetInt8Value(state, 2);
  1665. lua_interface->ResetFunctionStack(state);
  1666. if (spawn) {
  1667. spawn->SetTradeskillClass(value);
  1668. if (spawn->IsEntity()) {
  1669. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1670. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1671. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1672. }
  1673. if (spawn->IsPlayer())
  1674. ((Player*)spawn)->SetCharSheetChanged(true);
  1675. }
  1676. return 0;
  1677. }
  1678. int EQ2Emu_lua_SetMount(lua_State* state) {
  1679. if (!lua_interface)
  1680. return 0;
  1681. Spawn* spawn = lua_interface->GetSpawn(state);
  1682. int16 value = lua_interface->GetInt16Value(state, 2);
  1683. if (spawn && spawn->IsEntity()) {
  1684. ((Entity*)spawn)->SetMount(value);
  1685. EQ2_Color color;
  1686. color.red = 255;
  1687. color.green = 255;
  1688. color.blue = 255;
  1689. ((Entity*)spawn)->SetMountColor(&color);
  1690. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1691. }
  1692. return 0;
  1693. }
  1694. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1695. if (!lua_interface)
  1696. return 0;
  1697. Spawn* spawn = lua_interface->GetSpawn(state);
  1698. EQ2_Color mount_color;
  1699. EQ2_Color saddle_color;
  1700. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1701. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1702. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1703. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1704. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1705. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1706. if (spawn && spawn->IsEntity()) {
  1707. ((Entity*)spawn)->SetMountColor(&mount_color);
  1708. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1709. }
  1710. return 0;
  1711. }
  1712. int EQ2Emu_lua_GetMount(lua_State* state) {
  1713. if (!lua_interface)
  1714. return 0;
  1715. Spawn* spawn = lua_interface->GetSpawn(state);
  1716. if (spawn && spawn->IsEntity()) {
  1717. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1718. return 1;
  1719. }
  1720. return 0;
  1721. }
  1722. int EQ2Emu_lua_GetRace(lua_State* state) {
  1723. if (!lua_interface)
  1724. return 0;
  1725. Spawn* spawn = lua_interface->GetSpawn(state);
  1726. if (spawn)
  1727. {
  1728. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1729. lua_interface->SetInt32Value(state, spawn->GetRace());
  1730. return 1;
  1731. }
  1732. return 0;
  1733. }
  1734. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1735. if (!lua_interface)
  1736. return 0;
  1737. Spawn* spawn = lua_interface->GetSpawn(state);
  1738. if (spawn) {
  1739. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1740. return 1;
  1741. }
  1742. return 0;
  1743. }
  1744. int EQ2Emu_lua_GetClass(lua_State* state) {
  1745. Spawn* spawn = lua_interface->GetSpawn(state);
  1746. if (spawn) {
  1747. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1748. return 1;
  1749. }
  1750. return 0;
  1751. }
  1752. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1753. Spawn* spawn = lua_interface->GetSpawn(state);
  1754. if (spawn) {
  1755. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1756. return 1;
  1757. }
  1758. return 0;
  1759. }
  1760. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1761. if (!lua_interface)
  1762. return 0;
  1763. Spawn* spawn = lua_interface->GetSpawn(state);
  1764. float value = lua_interface->GetFloatValue(state, 2);
  1765. lua_interface->ResetFunctionStack(state);
  1766. if (spawn) {
  1767. spawn->SetSpeed(value);
  1768. ((Entity*)spawn)->SetSpeed(value);
  1769. if (spawn->IsPlayer()) {
  1770. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1771. if (client) {
  1772. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1773. if (packet) {
  1774. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1775. packet->setDataByName("speed", value);
  1776. packet->setDataByName("size", 0.51);
  1777. EQ2Packet* app = packet->serialize();
  1778. client->QueuePacket(app);
  1779. safe_delete(packet);
  1780. }
  1781. }
  1782. }
  1783. }
  1784. return 0;
  1785. }
  1786. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1787. if (!lua_interface)
  1788. return 0;
  1789. Spawn* spawn = lua_interface->GetSpawn(state);
  1790. const int16 type = lua_interface->GetInt16Value(state, 2);
  1791. const float value = lua_interface->GetFloatValue(state, 3);
  1792. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1793. int64 class_req = 0;
  1794. int32 class_id = 0;
  1795. vector<int16> faction_req;
  1796. vector<int16> race_req;
  1797. int32 i = 0;
  1798. int8 f = 0;
  1799. int8 r = 0;
  1800. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1801. if (class_id < 100) {
  1802. class_req += pow(2.0, double(class_id - 1));
  1803. }
  1804. else if (class_id > 100 && class_id < 1000) {
  1805. race_req.push_back(class_id);
  1806. r++;
  1807. }
  1808. else {
  1809. faction_req.push_back(class_id);
  1810. f++;
  1811. }
  1812. i++;
  1813. }
  1814. if (value != 0 && type >= 0) {
  1815. if (luaspell && luaspell->spell && luaspell->caster) {
  1816. ZoneServer* zone = luaspell->caster->GetZone();
  1817. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1818. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1819. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1820. if (target) {
  1821. if (target->IsPlayer()) {
  1822. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1823. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1824. if (((Player*)target)->GetGroupMemberInfo())
  1825. ((Player*)target)->UpdateGroupMemberInfo();
  1826. ((Player*)target)->SetCharSheetChanged(true);
  1827. }
  1828. else if (target->IsNPC())
  1829. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1830. else
  1831. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1832. }
  1833. }
  1834. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1835. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1836. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1837. }
  1838. else if (spawn && spawn->IsEntity()) {
  1839. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1840. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1841. if (spawn->IsPlayer())
  1842. ((Player*)spawn)->SetCharSheetChanged(true);
  1843. }
  1844. else
  1845. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1846. }
  1847. else
  1848. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1849. return 0;
  1850. }
  1851. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1852. if (!lua_interface)
  1853. return 0;
  1854. Spawn* spawn = lua_interface->GetSpawn(state);
  1855. int16 type = lua_interface->GetInt16Value(state, 2);
  1856. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1857. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1858. if (!spawn) {
  1859. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1860. return 0;
  1861. }
  1862. if (!spawn->IsEntity()) {
  1863. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1864. return 0;
  1865. }
  1866. if (value == 0) {
  1867. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1868. return 0;
  1869. }
  1870. if (!luaspell || !luaspell->spell) {
  1871. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1872. return 0;
  1873. }
  1874. int32 class_req = 0;
  1875. vector<int16> faction_req;
  1876. vector<int16> race_req;
  1877. int32 class_id = 0;
  1878. int32 i = 0;
  1879. int8 f = 0;
  1880. int8 r = 0;
  1881. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1882. if (class_id < 100) {
  1883. class_req += pow(2.0, double(class_id - 1));
  1884. }
  1885. else if (class_id > 100 && class_id < 1000) {
  1886. race_req.push_back(class_id);
  1887. r++;
  1888. }
  1889. else {
  1890. faction_req.push_back(class_id);
  1891. f++;
  1892. }
  1893. i++;
  1894. }
  1895. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1896. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1897. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1898. if (spawn->IsPlayer())
  1899. ((Player*)spawn)->SetCharSheetChanged(true);
  1900. return 0;
  1901. }
  1902. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1903. if (!lua_interface)
  1904. return 0;
  1905. Spawn* spawn = lua_interface->GetSpawn(state);
  1906. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1907. if (luaspell && luaspell->spell) {
  1908. ZoneServer* zone = luaspell->caster->GetZone();
  1909. Spawn* target = 0;
  1910. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1911. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1912. target = zone->GetSpawnByID(luaspell->targets[i]);
  1913. if (target && target->IsEntity()) {
  1914. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1915. if (target->IsPlayer())
  1916. ((Player*)target)->SetCharSheetChanged(true);
  1917. }
  1918. }
  1919. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1920. }
  1921. else if (spawn && spawn->IsEntity()) {
  1922. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1923. if (spawn->IsPlayer())
  1924. ((Player*)spawn)->SetCharSheetChanged(true);
  1925. }
  1926. return 0;
  1927. }
  1928. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1929. if (!lua_interface)
  1930. return 0;
  1931. Spawn* spawn = lua_interface->GetSpawn(state);
  1932. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1933. float value = lua_interface->GetFloatValue(state, 3);
  1934. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1935. if (value != 0) {
  1936. int32 spell_id = 0;
  1937. if (luaspell && luaspell->spell && luaspell->caster) {
  1938. spell_id = luaspell->spell->GetSpellID();
  1939. ZoneServer* zone = luaspell->caster->GetZone();
  1940. Spawn* target = 0;
  1941. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1942. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1943. target = zone->GetSpawnByID(luaspell->targets[i]);
  1944. if (target && target->Alive()) {
  1945. if (target->IsPlayer()) {
  1946. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1947. Client* client = target->GetZone()->GetClientBySpawn(target);
  1948. if (client) {
  1949. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1950. if (packet)
  1951. client->QueuePacket(packet);
  1952. }
  1953. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1954. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1955. }
  1956. else if (target->IsNPC()) {
  1957. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1958. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1959. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1960. }
  1961. else
  1962. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1963. }
  1964. }
  1965. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1966. }
  1967. else if (spawn) {
  1968. if (spawn->IsPlayer()) {
  1969. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1970. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1971. if (client) {
  1972. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1973. if (packet)
  1974. client->QueuePacket(packet);
  1975. }
  1976. }
  1977. else if (spawn->IsNPC())
  1978. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1979. else
  1980. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1981. }
  1982. }
  1983. else
  1984. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1985. return 0;
  1986. }
  1987. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1988. if (!lua_interface)
  1989. return 0;
  1990. Spawn* spawn = lua_interface->GetSpawn(state);
  1991. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1992. if (spawn && spawn->IsPlayer()) {
  1993. int32 spell_id = 0;
  1994. if (luaspell && luaspell->spell) {
  1995. spell_id = luaspell->spell->GetSpellID();
  1996. ZoneServer* zone = luaspell->caster->GetZone();
  1997. Spawn* target = 0;
  1998. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1999. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2000. target = zone->GetSpawnByID(luaspell->targets[i]);
  2001. if (target) {
  2002. if (target->IsPlayer()) {
  2003. ((Player*)target)->RemoveSkillBonus(spell_id);
  2004. Client* client = target->GetZone()->GetClientBySpawn(target);
  2005. if (client) {
  2006. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2007. if (packet)
  2008. client->QueuePacket(packet);
  2009. }
  2010. }
  2011. else if (target->IsNPC())
  2012. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2013. else
  2014. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2015. }
  2016. }
  2017. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2018. }
  2019. else if (spawn) {
  2020. if (spawn->IsPlayer()) {
  2021. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2022. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2023. if (client) {
  2024. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2025. if (packet)
  2026. client->QueuePacket(packet);
  2027. }
  2028. }
  2029. else if (spawn->IsNPC())
  2030. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2031. else
  2032. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2033. }
  2034. }
  2035. return 0;
  2036. }
  2037. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2038. if (!lua_interface)
  2039. return 0;
  2040. Spawn* spawn = lua_interface->GetSpawn(state);
  2041. int8 type = lua_interface->GetInt32Value(state, 2);
  2042. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2043. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2044. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2045. ZoneServer* zone = luaspell->caster->GetZone();
  2046. Spawn* target = 0;
  2047. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2048. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2049. target = zone->GetSpawnByID(luaspell->targets[i]);
  2050. if (target && target->IsEntity()) {
  2051. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2052. ((Entity*)target)->AddMezSpell(luaspell);
  2053. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2054. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2055. if (target->IsNPC())
  2056. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2057. }
  2058. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2059. ((Entity*)target)->AddStifleSpell(luaspell);
  2060. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2061. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2062. if (target->IsNPC())
  2063. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2064. }
  2065. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2066. ((Entity*)target)->AddDazeSpell(luaspell);
  2067. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2068. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2069. if (target->IsNPC())
  2070. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2071. }
  2072. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2073. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2074. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2075. ((Entity*)target)->AddStunSpell(luaspell);
  2076. if (target->IsNPC())
  2077. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2078. }
  2079. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2080. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2081. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2082. ((Entity*)target)->AddRootSpell(luaspell);
  2083. if (target->IsNPC())
  2084. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2085. }
  2086. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2087. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2088. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2089. ((Entity*)target)->AddFearSpell(luaspell);
  2090. if (target->IsNPC())
  2091. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2092. }
  2093. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2094. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2095. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2096. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2097. }
  2098. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2099. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2100. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2101. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2102. }
  2103. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2104. ((Entity*)target)->AddSnareSpell(luaspell);
  2105. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2106. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2107. if (target->IsNPC())
  2108. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2109. }
  2110. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2111. ((Entity*)target)->AddFlightSpell(luaspell);
  2112. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2113. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2114. }
  2115. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2116. ((Entity*)target)->AddGlideSpell(luaspell);
  2117. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2118. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2119. }
  2120. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2121. ((Entity*)target)->AddSafefallSpell(luaspell);
  2122. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2123. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2124. }
  2125. else
  2126. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2127. }
  2128. else
  2129. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2130. }
  2131. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2132. }
  2133. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2134. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2135. ((Entity*)spawn)->AddMezSpell(luaspell);
  2136. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2137. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2138. }
  2139. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2140. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2141. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2142. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2143. }
  2144. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2145. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2146. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2147. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2148. }
  2149. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2150. ((Entity*)spawn)->AddStunSpell(luaspell);
  2151. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2152. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2153. }
  2154. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2155. ((Entity*)spawn)->AddRootSpell(luaspell);
  2156. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2157. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2158. }
  2159. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2160. ((Entity*)spawn)->AddFearSpell(luaspell);
  2161. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2162. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2163. }
  2164. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2165. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2166. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2167. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2168. }
  2169. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2170. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2171. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2172. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2173. }
  2174. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2175. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2176. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2177. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2178. }
  2179. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2180. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2181. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2182. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2183. }
  2184. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2185. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2186. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2187. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2188. }
  2189. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2190. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2191. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2192. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2193. }
  2194. else
  2195. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2196. }
  2197. else
  2198. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2199. return 0;
  2200. }
  2201. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2202. if (!lua_interface)
  2203. return 0;
  2204. Spawn* spawn = lua_interface->GetSpawn(state);
  2205. int8 type = lua_interface->GetInt8Value(state, 2);
  2206. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2207. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2208. if (spawn && spawn->IsEntity()) {
  2209. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2210. ZoneServer* zone = luaspell->caster->GetZone();
  2211. Spawn* target = 0;
  2212. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2213. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2214. target = zone->GetSpawnByID(luaspell->targets[i]);
  2215. if (target) {
  2216. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2217. ((Entity*)target)->RemoveMezSpell(luaspell);
  2218. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2219. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2220. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2221. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2222. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2223. ((Entity*)target)->RemoveStunSpell(luaspell);
  2224. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2225. ((Entity*)target)->RemoveRootSpell(luaspell);
  2226. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2227. ((Entity*)target)->RemoveFearSpell(luaspell);
  2228. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2229. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2230. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2231. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2232. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2233. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2234. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2235. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2236. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2237. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2238. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2239. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2240. else
  2241. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2242. }
  2243. }
  2244. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2245. }
  2246. else if (only_remove_spawn) {
  2247. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2248. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2249. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2250. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2251. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2252. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2253. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2254. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2255. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2256. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2257. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2258. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2259. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2260. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2261. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2262. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2263. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2264. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2265. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2266. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2267. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2268. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2269. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2270. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2271. else
  2272. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2273. }
  2274. }
  2275. return 0;
  2276. }
  2277. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2278. if (!lua_interface)
  2279. return 0;
  2280. Spawn* spawn = lua_interface->GetSpawn(state);
  2281. int8 type = lua_interface->GetInt8Value(state, 2);
  2282. bool hasEffect = false;
  2283. if (!spawn)
  2284. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2285. else if (!spawn->IsEntity())
  2286. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2287. else if (type < CONTROL_MAX_EFFECTS)
  2288. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2289. else
  2290. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2291. lua_interface->SetBooleanValue(state, hasEffect);
  2292. return 1;
  2293. }
  2294. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2295. if (!lua_interface)
  2296. return 0;
  2297. Spawn* spawn = lua_interface->GetSpawn(state);
  2298. float distance = 0.0f;
  2299. if (!spawn)
  2300. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2301. else if (!spawn->IsNPC())
  2302. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2303. else
  2304. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2305. lua_interface->SetFloatValue(state, distance);
  2306. return 1;
  2307. }
  2308. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2309. if (!lua_interface)
  2310. return 0;
  2311. Spawn* spawn = lua_interface->GetSpawn(state);
  2312. float distance = 0.0f;
  2313. if (!spawn)
  2314. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2315. else if (!spawn->IsNPC())
  2316. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2317. else
  2318. distance = ((NPC*)spawn)->GetAggroRadius();
  2319. lua_interface->SetFloatValue(state, distance);
  2320. return 1;
  2321. }
  2322. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2323. if (!lua_interface)
  2324. return 0;
  2325. Spawn* spawn = lua_interface->GetSpawn(state);
  2326. float distance = lua_interface->GetFloatValue(state, 2);
  2327. bool override = lua_interface->GetBooleanValue(state, 3);
  2328. bool result = false;
  2329. lua_interface->ResetFunctionStack(state);
  2330. if (!spawn)
  2331. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2332. else if (!spawn->IsNPC())
  2333. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2334. else
  2335. {
  2336. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2337. result = true;
  2338. }
  2339. lua_interface->SetBooleanValue(state, result);
  2340. return 1;
  2341. }
  2342. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2343. if (!lua_interface)
  2344. return 0;
  2345. Spawn* spawn = lua_interface->GetSpawn(state);
  2346. int16 value = lua_interface->GetInt16Value(state, 2);
  2347. if (spawn && spawn->IsEntity()) {
  2348. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2349. if (spawn->IsPlayer())
  2350. ((Player*)spawn)->SetCharSheetChanged(true);
  2351. }
  2352. return 0;
  2353. }
  2354. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2355. if (!lua_interface)
  2356. return 0;
  2357. Spawn* spawn = lua_interface->GetSpawn(state);
  2358. int16 value = lua_interface->GetInt16Value(state, 2);
  2359. if (spawn && spawn->IsEntity()) {
  2360. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2361. if (spawn->IsPlayer())
  2362. ((Player*)spawn)->SetCharSheetChanged(true);
  2363. }
  2364. return 0;
  2365. }
  2366. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2367. if (!lua_interface)
  2368. return 0;
  2369. Spawn* spawn = lua_interface->GetSpawn(state);
  2370. int16 value = lua_interface->GetInt16Value(state, 2);
  2371. if (spawn && spawn->IsEntity()) {
  2372. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2373. if (spawn->IsPlayer())
  2374. ((Player*)spawn)->SetCharSheetChanged(true);
  2375. }
  2376. return 0;
  2377. }
  2378. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2379. if (!lua_interface)
  2380. return 0;
  2381. Spawn* spawn = lua_interface->GetSpawn(state);
  2382. int16 value = lua_interface->GetInt16Value(state, 2);
  2383. if (spawn && spawn->IsEntity()) {
  2384. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2385. if (spawn->IsPlayer())
  2386. ((Player*)spawn)->SetCharSheetChanged(true);
  2387. }
  2388. return 0;
  2389. }
  2390. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2391. if (!lua_interface)
  2392. return 0;
  2393. Spawn* spawn = lua_interface->GetSpawn(state);
  2394. int16 value = lua_interface->GetInt16Value(state, 2);
  2395. if (spawn && spawn->IsEntity()) {
  2396. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2397. if (spawn->IsPlayer())
  2398. ((Player*)spawn)->SetCharSheetChanged(true);
  2399. }
  2400. return 0;
  2401. }
  2402. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2403. if (!lua_interface)
  2404. return 0;
  2405. Spawn* spawn = lua_interface->GetSpawn(state);
  2406. int8 value = lua_interface->GetInt8Value(state, 2);
  2407. if (spawn && spawn->IsEntity()) {
  2408. ((Entity*)spawn)->SetDeity(value);
  2409. if (spawn->IsPlayer())
  2410. ((Player*)spawn)->SetCharSheetChanged(true);
  2411. }
  2412. lua_interface->ResetFunctionStack(state);
  2413. return 0;
  2414. }
  2415. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2416. if (!lua_interface)
  2417. return 0;
  2418. Spawn* spawn = lua_interface->GetSpawn(state);
  2419. if (spawn && spawn->IsEntity()) {
  2420. int8 deity = ((Entity*)spawn)->GetDeity();
  2421. lua_interface->SetInt32Value(state, deity);
  2422. return 1;
  2423. }
  2424. return 0;
  2425. }
  2426. int EQ2Emu_lua_SetInt(lua_State* state) {
  2427. if (!lua_interface)
  2428. return 0;
  2429. Spawn* spawn = lua_interface->GetSpawn(state);
  2430. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2431. if (spawn && spawn->IsEntity()) {
  2432. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2433. if (spawn->IsPlayer())
  2434. ((Player*)spawn)->SetCharSheetChanged(true);
  2435. }
  2436. return 0;
  2437. }
  2438. int EQ2Emu_lua_SetWis(lua_State* state) {
  2439. if (!lua_interface)
  2440. return 0;
  2441. Spawn* spawn = lua_interface->GetSpawn(state);
  2442. float value = lua_interface->GetFloatValue(state, 2);
  2443. if (spawn && spawn->IsEntity()) {
  2444. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2445. if (spawn->IsPlayer())
  2446. ((Player*)spawn)->SetCharSheetChanged(true);
  2447. }
  2448. return 0;
  2449. }
  2450. int EQ2Emu_lua_SetSta(lua_State* state) {
  2451. if (!lua_interface)
  2452. return 0;
  2453. Spawn* spawn = lua_interface->GetSpawn(state);
  2454. float value = lua_interface->GetFloatValue(state, 2);
  2455. if (spawn && spawn->IsEntity()) {
  2456. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2457. if (spawn->IsPlayer())
  2458. ((Player*)spawn)->SetCharSheetChanged(true);
  2459. }
  2460. return 0;
  2461. }
  2462. int EQ2Emu_lua_SetStr(lua_State* state) {
  2463. if (!lua_interface)
  2464. return 0;
  2465. Spawn* spawn = lua_interface->GetSpawn(state);
  2466. float value = lua_interface->GetFloatValue(state, 2);
  2467. if (spawn && spawn->IsEntity()) {
  2468. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2469. if (spawn->IsPlayer())
  2470. ((Player*)spawn)->SetCharSheetChanged(true);
  2471. }
  2472. return 0;
  2473. }
  2474. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2475. if (!lua_interface)
  2476. return 0;
  2477. Spawn* spawn = lua_interface->GetSpawn(state);
  2478. float value = lua_interface->GetFloatValue(state, 2);
  2479. if (spawn && spawn->IsEntity()) {
  2480. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2481. if (spawn->IsPlayer())
  2482. ((Player*)spawn)->SetCharSheetChanged(true);
  2483. }
  2484. return 0;
  2485. }
  2486. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2487. if (!lua_interface)
  2488. return 0;
  2489. Spawn* spawn = lua_interface->GetSpawn(state);
  2490. if (spawn) {
  2491. lua_interface->SetInt32Value(state, spawn->GetHP());
  2492. return 1;
  2493. }
  2494. return 0;
  2495. }
  2496. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2497. if (!lua_interface)
  2498. return 0;
  2499. Spawn* spawn = lua_interface->GetSpawn(state);
  2500. if (spawn) {
  2501. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2502. return 1;
  2503. }
  2504. return 0;
  2505. }
  2506. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2507. if (!lua_interface)
  2508. return 0;
  2509. Spawn* spawn = lua_interface->GetSpawn(state);
  2510. if (spawn) {
  2511. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2512. return 1;
  2513. }
  2514. return 0;
  2515. }
  2516. int EQ2Emu_lua_GetName(lua_State* state) {
  2517. if (!lua_interface)
  2518. return 0;
  2519. Spawn* spawn = lua_interface->GetSpawn(state);
  2520. if (spawn) {
  2521. lua_interface->SetStringValue(state, spawn->GetName());
  2522. return 1;
  2523. }
  2524. return 0;
  2525. }
  2526. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2527. Spawn* spawn = lua_interface->GetSpawn(state);
  2528. if (spawn) {
  2529. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2530. return 1;
  2531. }
  2532. return 0;
  2533. }
  2534. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2535. if (!lua_interface)
  2536. return 0;
  2537. Spawn* spawn = lua_interface->GetSpawn(state);
  2538. if (spawn) {
  2539. lua_interface->SetInt32Value(state, spawn->GetPower());
  2540. return 1;
  2541. }
  2542. return 0;
  2543. }
  2544. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2545. if (!lua_interface)
  2546. return 0;
  2547. Spawn* spawn = lua_interface->GetSpawn(state);
  2548. if (spawn) {
  2549. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2550. return 1;
  2551. }
  2552. return 0;
  2553. }
  2554. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2555. if (!lua_interface)
  2556. return 0;
  2557. Spawn* spawn = lua_interface->GetSpawn(state);
  2558. if (spawn) {
  2559. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2560. return 1;
  2561. }
  2562. return 0;
  2563. }
  2564. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2565. if (!lua_interface)
  2566. return 0;
  2567. Spawn* spawn = lua_interface->GetSpawn(state);
  2568. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2569. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2570. if (spawn && spawn2) {
  2571. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2572. lua_interface->SetFloatValue(state, distance);
  2573. return 1;
  2574. }
  2575. return 0;
  2576. }
  2577. int EQ2Emu_lua_GetX(lua_State* state) {
  2578. if (!lua_interface)
  2579. return 0;
  2580. Spawn* spawn = lua_interface->GetSpawn(state);
  2581. if (spawn) {
  2582. lua_interface->SetFloatValue(state, spawn->GetX());
  2583. return 1;
  2584. }
  2585. return 0;
  2586. }
  2587. int EQ2Emu_lua_GetY(lua_State* state) {
  2588. if (!lua_interface)
  2589. return 0;
  2590. Spawn* spawn = lua_interface->GetSpawn(state);
  2591. if (spawn) {
  2592. lua_interface->SetFloatValue(state, spawn->GetY());
  2593. return 1;
  2594. }
  2595. return 0;
  2596. }
  2597. int EQ2Emu_lua_GetZ(lua_State* state) {
  2598. if (!lua_interface)
  2599. return 0;
  2600. Spawn* spawn = lua_interface->GetSpawn(state);
  2601. if (spawn) {
  2602. lua_interface->SetFloatValue(state, spawn->GetZ());
  2603. return 1;
  2604. }
  2605. return 0;
  2606. }
  2607. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2608. if (!lua_interface)
  2609. return 0;
  2610. Spawn* spawn = lua_interface->GetSpawn(state);
  2611. if (spawn) {
  2612. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2613. return 1;
  2614. }
  2615. return 0;
  2616. }
  2617. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Spawn* spawn = lua_interface->GetSpawn(state);
  2621. if (spawn) {
  2622. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2623. return 1;
  2624. }
  2625. return 0;
  2626. }
  2627. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2628. if (!lua_interface)
  2629. return 0;
  2630. Spawn* spawn = lua_interface->GetSpawn(state);
  2631. if (spawn) {
  2632. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2633. return 1;
  2634. }
  2635. return 0;
  2636. }
  2637. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2638. if (!lua_interface)
  2639. return 0;
  2640. Spawn* spawn = lua_interface->GetSpawn(state);
  2641. if (spawn && spawn->IsEntity()) {
  2642. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2643. return 1;
  2644. }
  2645. return 0;
  2646. }
  2647. int EQ2Emu_lua_GetInt(lua_State* state) {
  2648. if (!lua_interface)
  2649. return 0;
  2650. Spawn* spawn = lua_interface->GetSpawn(state);
  2651. if (spawn && spawn->IsEntity()) {
  2652. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2653. return 1;
  2654. }
  2655. return 0;
  2656. }
  2657. int EQ2Emu_lua_GetWis(lua_State* state) {
  2658. if (!lua_interface)
  2659. return 0;
  2660. Spawn* spawn = lua_interface->GetSpawn(state);
  2661. if (spawn && spawn->IsEntity()) {
  2662. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2663. return 1;
  2664. }
  2665. return 0;
  2666. }
  2667. int EQ2Emu_lua_GetSta(lua_State* state) {
  2668. if (!lua_interface)
  2669. return 0;
  2670. Spawn* spawn = lua_interface->GetSpawn(state);
  2671. if (spawn && spawn->IsEntity()) {
  2672. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2673. return 1;
  2674. }
  2675. return 0;
  2676. }
  2677. int EQ2Emu_lua_GetStr(lua_State* state) {
  2678. if (!lua_interface)
  2679. return 0;
  2680. Spawn* spawn = lua_interface->GetSpawn(state);
  2681. if (spawn && spawn->IsEntity()) {
  2682. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2683. return 1;
  2684. }
  2685. return 0;
  2686. }
  2687. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2688. if (!lua_interface)
  2689. return 0;
  2690. Spawn* spawn = lua_interface->GetSpawn(state);
  2691. if (spawn && spawn->IsEntity()) {
  2692. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2693. return 1;
  2694. }
  2695. return 0;
  2696. }
  2697. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2698. if (!lua_interface)
  2699. return 0;
  2700. Spawn* spawn = lua_interface->GetSpawn(state);
  2701. if (spawn && spawn->IsEntity()) {
  2702. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2703. return 1;
  2704. }
  2705. return 0;
  2706. }
  2707. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2708. if (!lua_interface)
  2709. return 0;
  2710. Spawn* spawn = lua_interface->GetSpawn(state);
  2711. if (spawn && spawn->IsEntity()) {
  2712. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2713. return 1;
  2714. }
  2715. return 0;
  2716. }
  2717. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2718. if (!lua_interface)
  2719. return 0;
  2720. Spawn* spawn = lua_interface->GetSpawn(state);
  2721. if (spawn && spawn->IsEntity()) {
  2722. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2723. return 1;
  2724. }
  2725. return 0;
  2726. }
  2727. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2728. if (!lua_interface)
  2729. return 0;
  2730. Spawn* spawn = lua_interface->GetSpawn(state);
  2731. if (spawn && spawn->IsEntity()) {
  2732. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2733. return 1;
  2734. }
  2735. return 0;
  2736. }
  2737. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2738. if (!lua_interface)
  2739. return 0;
  2740. Spawn* spawn = lua_interface->GetSpawn(state);
  2741. if (spawn && spawn->IsEntity()) {
  2742. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2743. return 1;
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2748. if (!lua_interface)
  2749. return 0;
  2750. Spawn* player = lua_interface->GetSpawn(state);
  2751. if (!player || !player->IsPlayer()) {
  2752. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2753. return 0;
  2754. }
  2755. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2756. if (quest_id <= 0) {
  2757. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2758. return 0;
  2759. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2760. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2761. return 0;
  2762. }
  2763. int32 step = lua_interface->GetInt32Value(state, 3);
  2764. if (step > 0) {
  2765. Client* client = player->GetZone()->GetClientBySpawn(player);
  2766. if (client)
  2767. client->AddPendingQuestUpdate(quest_id, step);
  2768. } else {
  2769. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2770. }
  2771. return 0;
  2772. }
  2773. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2774. Spawn* player = lua_interface->GetSpawn(state);
  2775. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2776. int32 step = lua_interface->GetInt32Value(state, 3);
  2777. int32 progress = lua_interface->GetInt32Value(state, 4);
  2778. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2779. Client* client = player->GetZone()->GetClientBySpawn(player);
  2780. if (client)
  2781. client->AddPendingQuestUpdate(quest_id, step, progress);
  2782. }
  2783. return 0;
  2784. }
  2785. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2786. if (!lua_interface)
  2787. return 0;
  2788. Spawn* player = lua_interface->GetSpawn(state);
  2789. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2790. if (player && player->IsPlayer() && quest_id > 0) {
  2791. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2792. return 1;
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* player = lua_interface->GetSpawn(state);
  2800. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2801. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2802. if (player && player->IsPlayer() && quest_id > 0) {
  2803. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2804. return 1;
  2805. }
  2806. return 0;
  2807. }
  2808. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2809. if (!lua_interface)
  2810. return 0;
  2811. Spawn* player = lua_interface->GetSpawn(state);
  2812. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2813. if (player && player->IsPlayer() && quest_id > 0) {
  2814. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2815. return 1;
  2816. }
  2817. return 0;
  2818. }
  2819. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Quest* quest = lua_interface->GetQuest(state);
  2823. string name = lua_interface->GetStringValue(state, 2);
  2824. string type = lua_interface->GetStringValue(state, 3);
  2825. string zone = lua_interface->GetStringValue(state, 4);
  2826. int16 level = lua_interface->GetInt16Value(state, 5);
  2827. string description = lua_interface->GetStringValue(state, 6);
  2828. bool load = true;
  2829. if (!quest) {
  2830. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2831. load = false;
  2832. }
  2833. if (load && name.length() == 0) {
  2834. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2835. load = false;
  2836. }
  2837. if (load && type.length() == 0) {
  2838. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2839. load = false;
  2840. }
  2841. if (load && zone.length() == 0) {
  2842. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2843. load = false;
  2844. }
  2845. if (load && description.length() == 0) {
  2846. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2847. load = false;
  2848. }
  2849. if (load && level == 0) {
  2850. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2851. load = false;
  2852. }
  2853. if (load)
  2854. quest->RegisterQuest(name, type, zone, level, description);
  2855. return 0;
  2856. }
  2857. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2858. if (!lua_interface)
  2859. return 0;
  2860. Quest* quest = lua_interface->GetQuest(state);
  2861. if (quest) {
  2862. int8 level = lua_interface->GetInt16Value(state, 2);
  2863. quest->SetPrereqLevel(level);
  2864. }
  2865. return 0;
  2866. }
  2867. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2868. if (!lua_interface)
  2869. return 0;
  2870. Quest* quest = lua_interface->GetQuest(state);
  2871. if (quest) {
  2872. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2873. quest->AddPrereqQuest(quest_id);
  2874. }
  2875. return 0;
  2876. }
  2877. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2878. if (!lua_interface)
  2879. return 0;
  2880. Quest* quest = lua_interface->GetQuest(state);
  2881. if (quest) {
  2882. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2883. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2884. if (quantity == 0)
  2885. quantity = 1;
  2886. Item* master_item = master_item_list.GetItem(item_id);
  2887. if (master_item) {
  2888. Item* item = new Item(master_item);
  2889. item->details.count = quantity;
  2890. quest->AddPrereqItem(item);
  2891. }
  2892. }
  2893. return 0;
  2894. }
  2895. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2896. if (!lua_interface)
  2897. return 0;
  2898. Spawn* player = lua_interface->GetSpawn(state);
  2899. if(!player || !player->IsPlayer()) {
  2900. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2901. return 0;
  2902. }
  2903. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2904. if (quest_id > 0) {
  2905. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2906. return 1;
  2907. } else {
  2908. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Quest* quest = lua_interface->GetQuest(state);
  2916. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2917. if (quest && spawn_id > 0)
  2918. quest->SetQuestReturnNPC(spawn_id);
  2919. return 0;
  2920. }
  2921. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2922. if (!lua_interface)
  2923. return 0;
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. if (!spawn) {
  2926. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2927. return 0;
  2928. }
  2929. int32 time = lua_interface->GetInt32Value(state, 2);
  2930. if (time <= 0) {
  2931. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2932. return 0;
  2933. }
  2934. string function = lua_interface->GetStringValue(state, 3);
  2935. if (function.length() == 0) {
  2936. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2937. return 0;
  2938. }
  2939. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2940. Spawn* player = lua_interface->GetSpawn(state, 5);
  2941. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2942. timer->timer = Timer::GetCurrentTime2() + time;
  2943. timer->function = function;
  2944. timer->spawn = spawn->GetID();
  2945. timer->player = player ? player->GetID() : 0;
  2946. if (max_count == 0)
  2947. max_count = 1;
  2948. timer->max_count = max_count;
  2949. timer->current_count = 0;
  2950. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2951. return 0;
  2952. }
  2953. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2954. if (!lua_interface)
  2955. return 0;
  2956. Spawn* player = lua_interface->GetSpawn(state);
  2957. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2958. if (player && player->IsPlayer() && quest_id > 0) {
  2959. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2960. return 1;
  2961. }
  2962. return 0;
  2963. }
  2964. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2965. if (!lua_interface)
  2966. return 0;
  2967. Spawn* player = lua_interface->GetSpawn(state);
  2968. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2969. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2970. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2971. if (quest)
  2972. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2973. return 1;
  2974. }
  2975. return 0;
  2976. }
  2977. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2978. if (!lua_interface)
  2979. return 0;
  2980. Spawn* player = lua_interface->GetSpawn(state);
  2981. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2982. if (player && player->IsPlayer() && quest_id > 0) {
  2983. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2984. return 1;
  2985. }
  2986. return 0;
  2987. }
  2988. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2989. if (!lua_interface)
  2990. return 0;
  2991. Spawn* npc = lua_interface->GetSpawn(state);
  2992. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2993. if (npc && !npc->IsPlayer() && quest_id > 0)
  2994. npc->AddProvidedQuest(quest_id);
  2995. return 0;
  2996. }
  2997. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2998. if (!lua_interface)
  2999. return 0;
  3000. Spawn* npc = lua_interface->GetSpawn(state);
  3001. Spawn* player = lua_interface->GetSpawn(state, 2);
  3002. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3003. bool forced = lua_interface->GetBooleanValue(state, 4);
  3004. /* NPC is allowed to be null */
  3005. if (player && player->IsPlayer() && quest_id > 0) {
  3006. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  3007. if (master_quest) {
  3008. Client* client = player->GetZone()->GetClientBySpawn(player);
  3009. if (!client) {
  3010. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3011. }
  3012. Quest* quest = new Quest(master_quest);
  3013. if (!quest) {
  3014. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3015. }
  3016. if (client && quest) {
  3017. if (npc)
  3018. quest->SetQuestGiver(npc->GetDatabaseID());
  3019. else
  3020. quest->SetQuestGiver(0);
  3021. client->AddPendingQuest(quest, forced);
  3022. }
  3023. }
  3024. else {
  3025. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3026. }
  3027. }
  3028. else {
  3029. 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);
  3030. }
  3031. return 0;
  3032. }
  3033. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3034. if (!lua_interface)
  3035. return 0;
  3036. Quest* quest = lua_interface->GetQuest(state);
  3037. if (quest) {
  3038. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3039. quest->AddPrereqClass(class_id);
  3040. }
  3041. return 0;
  3042. }
  3043. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3044. if (!lua_interface)
  3045. return 0;
  3046. Quest* quest = lua_interface->GetQuest(state);
  3047. if (quest) {
  3048. int8 race = lua_interface->GetInt8Value(state, 2);
  3049. quest->AddPrereqRace(race);
  3050. }
  3051. return 0;
  3052. }
  3053. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3054. if (!lua_interface)
  3055. return 0;
  3056. Quest* quest = lua_interface->GetQuest(state);
  3057. if (quest) {
  3058. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3059. quest->AddPrereqModelType(model_type);
  3060. }
  3061. return 0;
  3062. }
  3063. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3064. if (!lua_interface)
  3065. return 0;
  3066. Quest* quest = lua_interface->GetQuest(state);
  3067. if (!quest) {
  3068. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3069. return 0;
  3070. }
  3071. int8 level = lua_interface->GetInt8Value(state, 2);
  3072. quest->SetPrereqTSLevel(level);
  3073. return 0;
  3074. }
  3075. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3076. if (!lua_interface)
  3077. return 0;
  3078. Quest* quest = lua_interface->GetQuest(state);
  3079. if (!quest) {
  3080. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3081. return 0;
  3082. }
  3083. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3084. quest->AddPrereqTradeskillClass(class_id);
  3085. return 0;
  3086. }
  3087. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3088. if (!lua_interface)
  3089. return 0;
  3090. Quest* quest = lua_interface->GetQuest(state);
  3091. if (quest) {
  3092. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3093. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3094. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3095. quest->AddPrereqFaction(faction_id, min, max);
  3096. }
  3097. return 0;
  3098. }
  3099. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3100. if (!lua_interface)
  3101. return 0;
  3102. Quest* quest = lua_interface->GetQuest(state);
  3103. if (quest) {
  3104. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3105. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3106. if (quantity == 0)
  3107. quantity = 1;
  3108. Item* master_item = master_item_list.GetItem(item_id);
  3109. if (master_item) {
  3110. Item* item = new Item(master_item);
  3111. item->details.count = quantity;
  3112. quest->AddSelectableRewardItem(item);
  3113. }
  3114. }
  3115. return 0;
  3116. }
  3117. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3118. if (!lua_interface)
  3119. return 0;
  3120. Quest* quest = lua_interface->GetQuest(state);
  3121. if (quest) {
  3122. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3123. vector<Item*>* items = quest->GetRewardItems();
  3124. if (items) {
  3125. vector<Item*>::iterator itr;
  3126. for (itr = items->begin(); itr != items->end(); itr++) {
  3127. if (*itr && (*itr)->details.item_id == item_id) {
  3128. lua_interface->SetBooleanValue(state, true);
  3129. return 1;
  3130. }
  3131. }
  3132. }
  3133. }
  3134. lua_interface->SetBooleanValue(state, false);
  3135. return 1;
  3136. }
  3137. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3138. if (!lua_interface)
  3139. return 0;
  3140. Quest* quest = lua_interface->GetQuest(state);
  3141. if (quest) {
  3142. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3143. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3144. if (quantity == 0)
  3145. quantity = 1;
  3146. Item* master_item = master_item_list.GetItem(item_id);
  3147. if (master_item) {
  3148. Item* item = new Item(master_item);
  3149. item->details.count = quantity;
  3150. quest->AddRewardItem(item);
  3151. }
  3152. }
  3153. return 0;
  3154. }
  3155. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3156. if (!lua_interface)
  3157. return 0;
  3158. Quest* quest = lua_interface->GetQuest(state);
  3159. if (quest) {
  3160. int32 copper = lua_interface->GetInt32Value(state, 2);
  3161. int32 silver = lua_interface->GetInt32Value(state, 3);
  3162. int32 gold = lua_interface->GetInt32Value(state, 4);
  3163. int32 plat = lua_interface->GetInt32Value(state, 5);
  3164. quest->AddRewardCoins(copper, silver, gold, plat);
  3165. }
  3166. return 0;
  3167. }
  3168. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3169. if (!lua_interface)
  3170. return 0;
  3171. Quest* quest = lua_interface->GetQuest(state);
  3172. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3173. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3174. if (quest && faction_id > 0 && amount != 0)
  3175. quest->AddRewardFaction(faction_id, amount);
  3176. return 0;
  3177. }
  3178. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3179. if (!lua_interface)
  3180. return 0;
  3181. Quest* quest = lua_interface->GetQuest(state);
  3182. if (quest) {
  3183. int32 status = lua_interface->GetInt32Value(state, 2);
  3184. quest->SetRewardStatus(status);
  3185. }
  3186. return 0;
  3187. }
  3188. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3189. if (!lua_interface)
  3190. return 0;
  3191. Quest* quest = lua_interface->GetQuest(state);
  3192. if (quest) {
  3193. string comment = lua_interface->GetStringValue(state, 2);
  3194. quest->SetRewardComment(comment);
  3195. }
  3196. return 0;
  3197. }
  3198. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3199. if (!lua_interface)
  3200. return 0;
  3201. Quest* quest = lua_interface->GetQuest(state);
  3202. if (quest) {
  3203. int32 exp = lua_interface->GetInt32Value(state, 2);
  3204. quest->SetRewardXP(exp);
  3205. }
  3206. return 0;
  3207. }
  3208. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3209. Quest* quest = lua_interface->GetQuest(state);
  3210. if (quest) {
  3211. int32 step = lua_interface->GetInt32Value(state, 2);
  3212. string description = lua_interface->GetStringValue(state, 3);
  3213. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3214. float percentage = lua_interface->GetFloatValue(state, 5);
  3215. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3216. int16 icon = lua_interface->GetInt16Value(state, 7);
  3217. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3218. const char* taskgroup = 0;
  3219. if (str_taskgroup.length() > 0)
  3220. taskgroup = str_taskgroup.c_str();
  3221. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3222. if (quest_step && icon && quantity > 0)
  3223. quest_step->SetIcon(icon);
  3224. }
  3225. return 0;
  3226. }
  3227. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3228. if (!lua_interface)
  3229. return 0;
  3230. Quest* quest = lua_interface->GetQuest(state);
  3231. if (quest) {
  3232. int32 step = lua_interface->GetInt32Value(state, 2);
  3233. string description = lua_interface->GetStringValue(state, 3);
  3234. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3235. float percentage = lua_interface->GetFloatValue(state, 5);
  3236. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3237. int16 icon = lua_interface->GetInt16Value(state, 7);
  3238. const char* taskgroup = 0;
  3239. if (str_taskgroup.length() > 0)
  3240. taskgroup = str_taskgroup.c_str();
  3241. int32 npc_id = 0;
  3242. vector<int32>* ids = 0;
  3243. Spawn* spawn = nullptr;
  3244. int i = 0;
  3245. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3246. if (ids == 0)
  3247. ids = new vector<int32>;
  3248. ids->push_back(npc_id);
  3249. i++;
  3250. }
  3251. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3252. if (quest_step && icon > 0 && quantity > 0)
  3253. quest_step->SetIcon(icon);
  3254. if (quest->GetPlayer()) {
  3255. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3256. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3257. }
  3258. }
  3259. return 0;
  3260. }
  3261. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3262. if (!lua_interface)
  3263. return 0;
  3264. Quest* quest = lua_interface->GetQuest(state);
  3265. if (quest) {
  3266. int32 step = lua_interface->GetInt32Value(state, 2);
  3267. string description = lua_interface->GetStringValue(state, 3);
  3268. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3269. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3270. int16 icon = lua_interface->GetInt16Value(state, 6);
  3271. const char* taskgroup = 0;
  3272. if (str_taskgroup.length() > 0)
  3273. taskgroup = str_taskgroup.c_str();
  3274. int32 npc_id = 0;
  3275. vector<int32>* ids = 0;
  3276. int i = 0;
  3277. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3278. if (ids == 0)
  3279. ids = new vector<int32>;
  3280. ids->push_back(npc_id);
  3281. i++;
  3282. }
  3283. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3284. if (quest_step && icon > 0)
  3285. quest_step->SetIcon(icon);
  3286. if (quest->GetPlayer()) {
  3287. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3288. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3289. }
  3290. }
  3291. return 0;
  3292. }
  3293. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3294. if (!lua_interface)
  3295. return 0;
  3296. Quest* quest = lua_interface->GetQuest(state);
  3297. if (quest) {
  3298. int32 step = lua_interface->GetInt32Value(state, 2);
  3299. string description = lua_interface->GetStringValue(state, 3);
  3300. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3301. float percentage = lua_interface->GetFloatValue(state, 5);
  3302. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3303. int16 icon = lua_interface->GetInt16Value(state, 7);
  3304. const char* taskgroup = 0;
  3305. if (str_taskgroup.length() > 0)
  3306. taskgroup = str_taskgroup.c_str();
  3307. int32 item_id = 0;
  3308. vector<int32>* ids = 0;
  3309. int i = 0;
  3310. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3311. if (ids == 0)
  3312. ids = new vector<int32>;
  3313. ids->push_back(item_id);
  3314. i++;
  3315. }
  3316. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3317. if (quest_step && icon > 0 && quantity > 0)
  3318. quest_step->SetIcon(icon);
  3319. if (quest->GetPlayer()) {
  3320. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3321. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3322. }
  3323. }
  3324. return 0;
  3325. }
  3326. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3327. if (!lua_interface)
  3328. return 0;
  3329. Quest* quest = lua_interface->GetQuest(state);
  3330. if (quest) {
  3331. int32 step = lua_interface->GetInt32Value(state, 2);
  3332. string description = lua_interface->GetStringValue(state, 3);
  3333. float max_variation = lua_interface->GetFloatValue(state, 4);
  3334. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3335. int16 icon = lua_interface->GetInt16Value(state, 6);
  3336. const char* taskgroup = 0;
  3337. if (str_taskgroup.length() > 0)
  3338. taskgroup = str_taskgroup.c_str();
  3339. vector<Location>* locations = 0;
  3340. int i = 7;
  3341. while (true) {
  3342. Location loc;
  3343. loc.x = lua_interface->GetFloatValue(state, i);
  3344. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3345. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3346. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3347. break;
  3348. if (locations == 0)
  3349. locations = new vector<Location>;
  3350. locations->push_back(loc);
  3351. i += 3;
  3352. }
  3353. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3354. if (quest_step && icon > 0)
  3355. quest_step->SetIcon(icon);
  3356. if (quest->GetPlayer()) {
  3357. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3358. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3359. }
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. if (quest) {
  3368. int32 step = lua_interface->GetInt32Value(state, 2);
  3369. string description = lua_interface->GetStringValue(state, 3);
  3370. float max_variation = lua_interface->GetFloatValue(state, 4);
  3371. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3372. int16 icon = lua_interface->GetInt16Value(state, 6);
  3373. const char* taskgroup = 0;
  3374. if (str_taskgroup.length() > 0)
  3375. taskgroup = str_taskgroup.c_str();
  3376. vector<Location>* locations = 0;
  3377. int i = 7;
  3378. while (true) {
  3379. Location loc;
  3380. loc.x = lua_interface->GetFloatValue(state, i);
  3381. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3382. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3383. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3384. break;
  3385. if (locations == 0)
  3386. locations = new vector<Location>;
  3387. locations->push_back(loc);
  3388. i += 3;
  3389. }
  3390. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3391. if (quest_step && icon > 0)
  3392. quest_step->SetIcon(icon);
  3393. if (quest->GetPlayer()) {
  3394. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3395. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3396. }
  3397. }
  3398. return 0;
  3399. }
  3400. int EQ2Emu_lua_AddQuestStepSpell(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. const char* taskgroup = 0;
  3410. if (str_taskgroup.length() > 0)
  3411. taskgroup = str_taskgroup.c_str();
  3412. int32 spell_id = 0;
  3413. vector<int32>* ids = 0;
  3414. int i = 0;
  3415. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3416. if (ids == 0)
  3417. ids = new vector<int32>;
  3418. ids->push_back(spell_id);
  3419. i++;
  3420. }
  3421. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3422. if (quest_step && icon > 0 && quantity > 0)
  3423. quest_step->SetIcon(icon);
  3424. if (quest->GetPlayer()) {
  3425. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3426. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3427. }
  3428. }
  3429. return 0;
  3430. }
  3431. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3432. if (!lua_interface)
  3433. return 0;
  3434. Quest* quest = lua_interface->GetQuest(state);
  3435. if (quest) {
  3436. int32 step = lua_interface->GetInt32Value(state, 2);
  3437. string description = lua_interface->GetStringValue(state, 3);
  3438. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3439. float percentage = lua_interface->GetFloatValue(state, 5);
  3440. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3441. int16 icon = lua_interface->GetInt16Value(state, 7);
  3442. const char* taskgroup = 0;
  3443. if (str_taskgroup.length() > 0)
  3444. taskgroup = str_taskgroup.c_str();
  3445. int32 item_id = 0;
  3446. vector<int32>* ids = 0;
  3447. int i = 0;
  3448. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3449. if (ids == 0)
  3450. ids = new vector<int32>;
  3451. ids->push_back(item_id);
  3452. i++;
  3453. }
  3454. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3455. if (quest_step && icon > 0 && quantity > 0)
  3456. quest_step->SetIcon(icon);
  3457. if (quest->GetPlayer()) {
  3458. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3459. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3460. }
  3461. }
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3465. if (!lua_interface)
  3466. return 0;
  3467. Quest* quest = lua_interface->GetQuest(state);
  3468. if (quest) {
  3469. int32 step = lua_interface->GetInt32Value(state, 2);
  3470. string description = lua_interface->GetStringValue(state, 3);
  3471. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3472. float percentage = lua_interface->GetFloatValue(state, 5);
  3473. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3474. int16 icon = lua_interface->GetInt16Value(state, 7);
  3475. const char* taskgroup = 0;
  3476. if (str_taskgroup.length() > 0)
  3477. taskgroup = str_taskgroup.c_str();
  3478. int32 item_id = 0;
  3479. vector<int32>* ids = 0;
  3480. int i = 0;
  3481. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3482. if (ids == 0)
  3483. ids = new vector<int32>;
  3484. ids->push_back(item_id);
  3485. i++;
  3486. }
  3487. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3488. if (quest_step && icon > 0 && quantity > 0)
  3489. quest_step->SetIcon(icon);
  3490. if (quest->GetPlayer()) {
  3491. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3492. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3493. }
  3494. }
  3495. return 0;
  3496. }
  3497. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3498. if (!lua_interface)
  3499. return 0;
  3500. Quest* quest = lua_interface->GetQuest(state);
  3501. if (quest) {
  3502. string action = lua_interface->GetStringValue(state, 2);
  3503. if (action.length() > 0)
  3504. quest->SetCompleteAction(action);
  3505. }
  3506. return 0;
  3507. }
  3508. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3509. if (!lua_interface)
  3510. return 0;
  3511. Quest* quest = lua_interface->GetQuest(state);
  3512. if (quest) {
  3513. int32 step = lua_interface->GetInt32Value(state, 2);
  3514. string action = lua_interface->GetStringValue(state, 3);
  3515. if (step > 0 && action.length() > 0)
  3516. quest->AddCompleteAction(step, action);
  3517. }
  3518. return 0;
  3519. }
  3520. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3521. if (!lua_interface)
  3522. return 0;
  3523. Quest* quest = lua_interface->GetQuest(state);
  3524. if (quest) {
  3525. int32 step = lua_interface->GetInt32Value(state, 2);
  3526. string action = lua_interface->GetStringValue(state, 3);
  3527. if (step > 0 && action.length() > 0)
  3528. quest->AddProgressAction(step, action);
  3529. }
  3530. return 0;
  3531. }
  3532. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3533. if (!lua_interface)
  3534. return 0;
  3535. Quest* quest = lua_interface->GetQuest(state);
  3536. string description = lua_interface->GetStringValue(state, 2);
  3537. if (quest && description.length() > 0)
  3538. quest->SetDescription(description);
  3539. return 0;
  3540. }
  3541. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3542. if (!lua_interface)
  3543. return 0;
  3544. Quest* quest = lua_interface->GetQuest(state);
  3545. string description = lua_interface->GetStringValue(state, 2);
  3546. if (quest && description.length() > 0)
  3547. quest->SetCompletedDescription(description);
  3548. return 0;
  3549. }
  3550. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3551. if (!lua_interface)
  3552. return 0;
  3553. Quest* quest = lua_interface->GetQuest(state);
  3554. int32 step = lua_interface->GetInt32Value(state, 2);
  3555. string description = lua_interface->GetStringValue(state, 3);
  3556. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3557. if (quest && step > 0 && description.length() > 0) {
  3558. quest->SetTaskGroupDescription(step, description, display_bullets);
  3559. if (quest->GetPlayer()) {
  3560. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3561. if (client)
  3562. client->SendQuestUpdateStep(quest, step, false);
  3563. }
  3564. }
  3565. return 0;
  3566. }
  3567. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3568. if (!lua_interface)
  3569. return 0;
  3570. Quest* quest = lua_interface->GetQuest(state);
  3571. int32 step = lua_interface->GetInt32Value(state, 2);
  3572. string description = lua_interface->GetStringValue(state, 3);
  3573. if (quest && step > 0 && description.length() > 0) {
  3574. quest->SetStepDescription(step, description);
  3575. if (quest->GetPlayer()) {
  3576. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3577. if (client)
  3578. client->SendQuestUpdateStepImmediately(quest, step);
  3579. }
  3580. }
  3581. return 0;
  3582. }
  3583. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3584. Quest* quest = lua_interface->GetQuest(state);
  3585. string zone = lua_interface->GetStringValue(state, 2);
  3586. if (quest && zone.length() > 0)
  3587. quest->SetZone(zone);
  3588. return 0;
  3589. }
  3590. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3591. if (!lua_interface)
  3592. return 0;
  3593. Quest* quest = lua_interface->GetQuest(state);
  3594. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3595. int32 coin = lua_interface->GetInt32Value(state, 3);
  3596. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3597. string rewards_str = lua_interface->GetStringValue(state, 5);
  3598. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3599. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3600. string text = lua_interface->GetStringValue(state, 8);
  3601. int32 source_id = 0;
  3602. if (playerSpawn && playerSpawn->IsPlayer()) {
  3603. Player* player = (Player*)playerSpawn;
  3604. Client* client = player->GetZone()->GetClientBySpawn(player);
  3605. if (client) {
  3606. vector<Item*> reward_items;
  3607. vector<Item*> selectable_reward_items;
  3608. if (rewards_str.length() > 0) {
  3609. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3610. map<unsigned int, unsigned short>::iterator itr;
  3611. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3612. if (itr->first > 0) {
  3613. Item* item = new Item(master_item_list.GetItem(itr->first));
  3614. if (item) {
  3615. if (itr->second > 0)
  3616. item->details.count = itr->second;
  3617. reward_items.push_back(item);
  3618. }
  3619. }
  3620. }
  3621. }
  3622. if (select_rewards_str.length() > 0) {
  3623. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3624. map<unsigned int, unsigned short>::iterator itr;
  3625. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3626. if (itr->first > 0) {
  3627. Item* item = new Item(master_item_list.GetItem(itr->first));
  3628. if (item) {
  3629. if (itr->second > 0)
  3630. item->stack_count = itr->second;
  3631. selectable_reward_items.push_back(item);
  3632. }
  3633. }
  3634. }
  3635. }
  3636. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3637. const char* reward_type = "Quest Reward!";
  3638. if (!quest)
  3639. reward_type = "Reward!";
  3640. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3641. }
  3642. }
  3643. return 0;
  3644. }
  3645. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3646. if (!lua_interface)
  3647. return 0;
  3648. Quest* quest = lua_interface->GetQuest(state);
  3649. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3650. if (quest && spawn) {
  3651. if (spawn->IsPlayer()) {
  3652. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3653. if (client)
  3654. client->AddPendingQuestReward(quest);
  3655. }
  3656. }
  3657. return 0;
  3658. }
  3659. int EQ2Emu_lua_Harvest(lua_State* state) {
  3660. if (!lua_interface)
  3661. return 0;
  3662. Spawn* player = lua_interface->GetSpawn(state);
  3663. Spawn* node = lua_interface->GetSpawn(state, 2);
  3664. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3665. Client* client = player->GetZone()->GetClientBySpawn(player);
  3666. if (client) {
  3667. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3668. ((GroundSpawn*)node)->ProcessHarvest(client);
  3669. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3670. player->GetZone()->RemoveSpawn(node, true);
  3671. }
  3672. }
  3673. else if (player && player->IsPlayer()) {
  3674. Client* client = player->GetZone()->GetClientBySpawn(player);
  3675. if (client)
  3676. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3677. }
  3678. return 0;
  3679. }
  3680. int EQ2Emu_lua_Bind(lua_State* state) {
  3681. if (!lua_interface)
  3682. return 0;
  3683. Spawn* spawn = lua_interface->GetSpawn(state);
  3684. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3685. float x = lua_interface->GetFloatValue(state, 3);
  3686. float y = lua_interface->GetFloatValue(state, 4);
  3687. float z = lua_interface->GetFloatValue(state, 5);
  3688. float h = lua_interface->GetFloatValue(state, 6);
  3689. if (!spawn) {
  3690. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3691. return 0;
  3692. }
  3693. if (!spawn->IsPlayer()) {
  3694. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3695. return 0;
  3696. }
  3697. if (zone_id == 0) {
  3698. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3699. if (!client) {
  3700. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3701. return 0;
  3702. }
  3703. if (!client->Bind())
  3704. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3705. }
  3706. else {
  3707. Player* player = (Player*)spawn;
  3708. player->GetPlayerInfo()->SetBindZone(zone_id);
  3709. player->GetPlayerInfo()->SetBindX(x);
  3710. player->GetPlayerInfo()->SetBindY(y);
  3711. player->GetPlayerInfo()->SetBindZ(z);
  3712. player->GetPlayerInfo()->SetBindHeading(h);
  3713. }
  3714. return 0;
  3715. }
  3716. int EQ2Emu_lua_Gate(lua_State* state) {
  3717. if (!lua_interface)
  3718. return 0;
  3719. Spawn* spawn = lua_interface->GetSpawn(state);
  3720. if (spawn) {
  3721. if (spawn->IsPlayer()) {
  3722. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3723. if (client) {
  3724. if (!client->Gate())
  3725. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3726. }
  3727. }
  3728. }
  3729. return 0;
  3730. }
  3731. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3732. if (!lua_interface)
  3733. return 0;
  3734. bool ret = false;
  3735. Spawn* spawn = lua_interface->GetSpawn(state);
  3736. if (spawn) {
  3737. if (spawn->IsPlayer()) {
  3738. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3739. if (client)
  3740. ret = client->BindAllowed();
  3741. }
  3742. }
  3743. lua_interface->SetBooleanValue(state, ret);
  3744. return 1;
  3745. }
  3746. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3747. if (!lua_interface)
  3748. return 0;
  3749. bool ret = false;
  3750. Spawn* spawn = lua_interface->GetSpawn(state);
  3751. if (spawn) {
  3752. if (spawn->IsPlayer()) {
  3753. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3754. if (client)
  3755. ret = client->GateAllowed();
  3756. }
  3757. }
  3758. lua_interface->SetBooleanValue(state, ret);
  3759. return 1;
  3760. }
  3761. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3762. Spawn* spawn = lua_interface->GetSpawn(state);
  3763. if (spawn) {
  3764. lua_interface->SetBooleanValue(state, spawn->Alive());
  3765. return 1;
  3766. }
  3767. return 0;
  3768. }
  3769. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3770. if (!lua_interface)
  3771. return 0;
  3772. Spawn* spawn = lua_interface->GetSpawn(state);
  3773. if (spawn && spawn->IsEntity()) {
  3774. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3775. return 1;
  3776. }
  3777. return 0;
  3778. }
  3779. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3780. Spawn* spawn = lua_interface->GetSpawn(state);
  3781. string message = lua_interface->GetStringValue(state, 2);
  3782. string color_str = lua_interface->GetStringValue(state, 3);
  3783. int8 color = CHANNEL_NARRATIVE;
  3784. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3785. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3786. if (client) {
  3787. if (color_str.length() > 0) {
  3788. // leave for backwards compat, but all future should just use the number
  3789. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3790. color = CHANNEL_COLOR_RED;
  3791. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3792. color = CHANNEL_COLOR_YELLOW;
  3793. else
  3794. {
  3795. // use a number to specify the channel as per Commands/Commands.h defines
  3796. color = (int8)atoul(color_str.c_str());
  3797. }
  3798. }
  3799. client->SimpleMessage(color, message.c_str());
  3800. }
  3801. }
  3802. return 0;
  3803. }
  3804. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3805. Spawn* spawn = lua_interface->GetSpawn(state);
  3806. string message = lua_interface->GetStringValue(state, 2);
  3807. int8 red = lua_interface->GetInt8Value(state, 3);
  3808. int8 green = lua_interface->GetInt8Value(state, 4);
  3809. int8 blue = lua_interface->GetInt8Value(state, 5);
  3810. if (!spawn) {
  3811. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3812. return 0;
  3813. }
  3814. int32 words = ::CountWordsInString(message.c_str());
  3815. if (words < 5)
  3816. words = 5;
  3817. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3818. if (client)
  3819. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3820. return 0;
  3821. }
  3822. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3823. Spawn* spawn = lua_interface->GetSpawn(state);
  3824. int8 param = lua_interface->GetInt8Value(state, 2);
  3825. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3826. int8 value = lua_interface->GetInt8Value(state, 4);
  3827. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3828. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3829. if (client) {
  3830. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3831. switch (param) {
  3832. case 1: {
  3833. packet->setDataByName("parameter1", param_value);
  3834. break;
  3835. }
  3836. case 2: {
  3837. packet->setDataByName("parameter2", param_value);
  3838. break;
  3839. }
  3840. case 3: {
  3841. packet->setDataByName("parameter3", param_value);
  3842. break;
  3843. }
  3844. case 4: {
  3845. packet->setDataByName("parameter4", param_value);
  3846. break;
  3847. }
  3848. case 5: {
  3849. packet->setDataByName("parameter5", param_value);
  3850. break;
  3851. }
  3852. }
  3853. packet->setDataByName("value", value);
  3854. client->QueuePacket(packet->serialize());
  3855. safe_delete(packet);
  3856. }
  3857. }
  3858. return 0;
  3859. }
  3860. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3861. Spawn* spawn = lua_interface->GetSpawn(state);
  3862. if (spawn && spawn->IsPlayer()) {
  3863. if (((Player*)spawn)->GetIsTracking())
  3864. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3865. else
  3866. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3867. }
  3868. return 0;
  3869. }
  3870. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3871. Spawn* player = lua_interface->GetSpawn(state);
  3872. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3873. string name = lua_interface->GetStringValue(state, 3);
  3874. float distance = lua_interface->GetFloatValue(state, 4);
  3875. string command = lua_interface->GetStringValue(state, 5);
  3876. string error_text = lua_interface->GetStringValue(state, 6);
  3877. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3878. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3879. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3880. if (spawn) {
  3881. if (distance == 0)
  3882. distance = 10.0f;
  3883. if (command.length() == 0)
  3884. command = name;
  3885. if (command.length() < 1 && name.length() < 1)
  3886. {
  3887. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3888. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3889. spawn->RemovePrimaryCommands();
  3890. }
  3891. else
  3892. {
  3893. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3894. }
  3895. }
  3896. return 0;
  3897. }
  3898. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3899. if (!lua_interface)
  3900. return 0;
  3901. Spawn* player = lua_interface->GetSpawn(state);
  3902. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3903. int16 tier = lua_interface->GetInt16Value(state, 3);
  3904. if (player && player->IsPlayer()) {
  3905. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  3906. return 1;
  3907. }
  3908. return 0;
  3909. }
  3910. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3911. if (!lua_interface)
  3912. return 0;
  3913. Spawn* player = lua_interface->GetSpawn(state);
  3914. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3915. int16 tier = lua_interface->GetInt16Value(state, 3);
  3916. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3917. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  3918. bool add_to_hotbar = true;
  3919. if (num_args > 4) {
  3920. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  3921. }
  3922. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3923. if (player && spell && player->IsPlayer()) {
  3924. Client* client = player->GetClient();
  3925. if (client) {
  3926. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3927. {
  3928. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3929. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3930. client->GetPlayer()->UnlockSpell(spell);
  3931. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3932. }
  3933. else
  3934. {
  3935. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3936. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3937. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3938. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3939. client->GetPlayer()->UnlockSpell(spell);
  3940. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3941. }
  3942. //if (client ) {
  3943. // ((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);
  3944. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3945. if (outapp)
  3946. client->QueuePacket(outapp);
  3947. }
  3948. }
  3949. return 0;
  3950. }
  3951. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3952. if (!lua_interface)
  3953. return 0;
  3954. Spawn* player = lua_interface->GetSpawn(state);
  3955. if (player && player->IsPlayer()) {
  3956. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3957. return 1;
  3958. }
  3959. return 0;
  3960. }
  3961. int EQ2Emu_lua_Attack(lua_State* state) {
  3962. if (lua_interface) {
  3963. Spawn* npc = lua_interface->GetSpawn(state);
  3964. Spawn* player = lua_interface->GetSpawn(state, 2);
  3965. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3966. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3967. }
  3968. return 0;
  3969. }
  3970. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3971. if (lua_interface) {
  3972. Spawn* target = lua_interface->GetSpawn(state);
  3973. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3974. if (target && target->GetZone())
  3975. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3976. }
  3977. return 0;
  3978. }
  3979. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3980. Spawn* player;
  3981. if (lua_interface) {
  3982. player = lua_interface->GetSpawn(state);
  3983. if (player && player->IsPlayer()) {
  3984. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3985. return 1;
  3986. }
  3987. }
  3988. return 0;
  3989. }
  3990. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3991. Spawn* player;
  3992. Client* client;
  3993. if (lua_interface) {
  3994. player = lua_interface->GetSpawn(state);
  3995. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3996. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3997. client->HandInCollections();
  3998. }
  3999. return 0;
  4000. }
  4001. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4002. Spawn* widget;
  4003. if (lua_interface) {
  4004. widget = lua_interface->GetSpawn(state);
  4005. if (widget && widget->IsWidget())
  4006. ((Widget*)widget)->HandleUse(NULL, "");
  4007. }
  4008. return 0;
  4009. }
  4010. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4011. Spawn* spawn = 0;
  4012. int32 primary_list = 0;
  4013. int32 secondary_list = 0;
  4014. if (lua_interface) {
  4015. spawn = lua_interface->GetSpawn(state);
  4016. primary_list = lua_interface->GetInt32Value(state, 2);
  4017. secondary_list = lua_interface->GetInt32Value(state, 3);
  4018. if (!spawn->IsNPC()) {
  4019. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4020. return 0;
  4021. }
  4022. NPC* npc = (NPC*)spawn;
  4023. npc->SetPrimarySpellList(primary_list);
  4024. npc->SetSecondarySpellList(secondary_list);
  4025. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4026. }
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_GetPet(lua_State* state) {
  4030. if (!lua_interface)
  4031. return 0;
  4032. Spawn* spawn = lua_interface->GetSpawn(state);
  4033. if (spawn) {
  4034. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4035. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4036. return 1;
  4037. }
  4038. }
  4039. return 0;
  4040. }
  4041. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4042. if (!lua_interface)
  4043. return 0;
  4044. Spawn* spawn = lua_interface->GetSpawn(state);
  4045. if (spawn) {
  4046. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4047. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4048. return 1;
  4049. }
  4050. }
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4054. if (!lua_interface)
  4055. return 0;
  4056. Spawn* spawn = lua_interface->GetSpawn(state);
  4057. if (spawn) {
  4058. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4059. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4060. return 1;
  4061. }
  4062. }
  4063. return 0;
  4064. }
  4065. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4066. if (!lua_interface)
  4067. return 0;
  4068. Spawn* spawn = lua_interface->GetSpawn(state);
  4069. if (spawn) {
  4070. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4071. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4072. return 1;
  4073. }
  4074. }
  4075. return 0;
  4076. }
  4077. int EQ2Emu_lua_Charm(lua_State* state) {
  4078. if (!lua_interface)
  4079. return 0;
  4080. Spawn* owner = lua_interface->GetSpawn(state);
  4081. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4082. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4083. if (!luaspell) {
  4084. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4085. return 0;
  4086. }
  4087. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4088. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4089. pet->SetPet(true);
  4090. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4091. ((NPC*)pet)->SetOwner((Entity*)owner);
  4092. // If owner is player and player does not have a summoned pet set the players charsheet
  4093. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4094. Player* player = (Player*)owner;
  4095. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4096. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4097. player->GetInfoStruct()->set_pet_movement(2);
  4098. player->GetInfoStruct()->set_pet_behavior(3);
  4099. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4100. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4101. // Make sure the values get sent to the client
  4102. player->SetCharSheetChanged(true);
  4103. }
  4104. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4105. pet->SetSpawnScript("");
  4106. // Set faction to the same as the owner
  4107. pet->SetFactionID(owner->GetFactionID());
  4108. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4109. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4110. // Clear hate list
  4111. ((NPC*)pet)->Brain()->ClearHate();
  4112. // Set the brain to a pet brain
  4113. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4114. }
  4115. return 0;
  4116. }
  4117. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4118. if (!lua_interface)
  4119. return 0;
  4120. Spawn* spawn = lua_interface->GetSpawn(state);
  4121. if (!spawn) {
  4122. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4123. return 0;
  4124. }
  4125. vector<Spawn*> groupMembers;
  4126. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4127. groupMembers = *spawn->GetSpawnGroup();
  4128. }
  4129. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4130. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4131. deque<GroupMemberInfo*>::iterator itr;
  4132. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4133. if (group)
  4134. {
  4135. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4136. deque<GroupMemberInfo*>* members = group->GetMembers();
  4137. GroupMemberInfo* info = 0;
  4138. for (itr = members->begin(); itr != members->end(); itr++) {
  4139. info = *itr;
  4140. if (info->client)
  4141. groupMembers.push_back(info->client->GetPlayer());
  4142. }
  4143. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4144. }
  4145. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4146. }
  4147. else
  4148. return 0;
  4149. lua_createtable(state, groupMembers.size(), 0);
  4150. int newTable = lua_gettop(state);
  4151. for (int32 i = 0; i < groupMembers.size(); i++) {
  4152. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4153. lua_rawseti(state, newTable, i + 1);
  4154. }
  4155. return 1;
  4156. }
  4157. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4161. lua_interface->SetOptionWindowValue(state, option_window);
  4162. return 1;
  4163. }
  4164. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4165. if (!lua_interface)
  4166. return 0;
  4167. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4168. if (option_window) {
  4169. OptionWindowOption option_window_option;
  4170. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4171. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4172. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4173. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4174. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4175. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4176. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4177. option_window->push_back(option_window_option);
  4178. }
  4179. return 0;
  4180. }
  4181. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4182. if (!lua_interface)
  4183. return 0;
  4184. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4185. Spawn* player = lua_interface->GetSpawn(state, 2);
  4186. string window_title = lua_interface->GetStringValue(state, 3);
  4187. string cancel_command = lua_interface->GetStringValue(state, 4);
  4188. Client* client = player->GetZone()->GetClientBySpawn(player);
  4189. if (option_window && window_title.length() > 0 && client) {
  4190. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4191. if (!packet)
  4192. return 0;
  4193. packet->setDataByName("title_text", window_title.c_str());
  4194. if (cancel_command.length() > 0)
  4195. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4196. packet->setArrayLengthByName("num_selections", option_window->size());
  4197. vector<OptionWindowOption>::iterator itr;
  4198. int8 i = 0;
  4199. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4200. OptionWindowOption opt = *itr;
  4201. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4202. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4203. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4204. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4205. if (opt.optionCommand.length() > 0)
  4206. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4207. if (opt.optionConfirmTitle.length() > 0)
  4208. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4209. i++;
  4210. }
  4211. client->QueuePacket(packet->serialize());
  4212. safe_delete(option_window);
  4213. safe_delete(packet);
  4214. }
  4215. return 0;
  4216. }
  4217. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4218. if (!lua_interface)
  4219. return 0;
  4220. Spawn* spawn = lua_interface->GetSpawn(state);
  4221. if (spawn) {
  4222. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4223. return 1;
  4224. }
  4225. else
  4226. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4227. return 0;
  4228. }
  4229. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4230. if (!lua_interface)
  4231. return 0;
  4232. Spawn* spawn = lua_interface->GetSpawn(state);
  4233. if (spawn) {
  4234. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4235. return 1;
  4236. }
  4237. else
  4238. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4239. return 0;
  4240. }
  4241. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4242. if (!lua_interface)
  4243. return 0;
  4244. Spawn* spawn = lua_interface->GetSpawn(state);
  4245. if (spawn) {
  4246. int8 class_id = spawn->GetTradeskillClass();
  4247. // Need to add 42 for the offset in the array
  4248. class_id += 44;
  4249. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4250. return 1;
  4251. }
  4252. else
  4253. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4254. return 0;
  4255. }
  4256. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4257. if (!lua_interface)
  4258. return 0;
  4259. Spawn* spawn = lua_interface->GetSpawn(state);
  4260. int16 level = lua_interface->GetInt8Value(state, 2);
  4261. if (spawn) {
  4262. if (spawn->IsPlayer())
  4263. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4264. else
  4265. spawn->SetTSLevel(level);
  4266. }
  4267. else
  4268. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4269. return 0;
  4270. }
  4271. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4272. if (!lua_interface)
  4273. return 0;
  4274. Spawn* spawn = lua_interface->GetSpawn(state);
  4275. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4276. if (spawn) {
  4277. spawn->SetAttackable(attackable);
  4278. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4279. }
  4280. return 0;
  4281. }
  4282. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4283. // Check to see if we have a valid lua_interface
  4284. if (!lua_interface)
  4285. return 0;
  4286. // Get the spawn that is getting the pet
  4287. Spawn* spawn = lua_interface->GetSpawn(state);
  4288. // Get the DB ID of the pet
  4289. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4290. // The max level the pet can gain
  4291. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4292. // Get the spell that this command was called from
  4293. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4294. // Check to make sure the spawn pointer is valid
  4295. if (!spawn) {
  4296. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4297. return 0;
  4298. }
  4299. // Check to make sure the spawn is an entity
  4300. if (!spawn->IsEntity()) {
  4301. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4302. return 0;
  4303. }
  4304. // Check to make sure the spawn doesn't already have a pet of this type
  4305. if (((Entity*)spawn)->GetPet()) {
  4306. if (spawn->IsPlayer()) {
  4307. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4308. if (client)
  4309. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4310. }
  4311. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4312. return 0;
  4313. }
  4314. // Check to see if the DB ID for the pet is set
  4315. if (pet_id == 0) {
  4316. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4317. return 0;
  4318. }
  4319. // Check to see if the pointer to the spell is valid
  4320. if (!luaspell) {
  4321. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4322. return 0;
  4323. }
  4324. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4325. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4326. if (!pet) {
  4327. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4328. return 0;
  4329. }
  4330. // Check to make sure the pet is an npc
  4331. if (!pet->IsNPC()) {
  4332. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4333. return 0;
  4334. }
  4335. // Spawn the pet at the same location as the owner
  4336. pet->SetX(spawn->GetX());
  4337. pet->SetY(spawn->GetY());
  4338. pet->SetZ(spawn->GetZ());
  4339. pet->SetLocation(spawn->GetLocation());
  4340. pet->SetHeading(spawn->GetHeading());
  4341. spawn->GetZone()->AddSpawn(pet);
  4342. /*
  4343. const char* spawn_script = world.GetSpawnScript(pet_id);
  4344. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4345. spawn->SetSpawnScript(string(spawn_script));
  4346. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4347. }*/
  4348. // Get a random pet name
  4349. string random_pet_name;
  4350. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4351. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4352. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4353. // If player set various values for the char sheet (pet window)
  4354. if (spawn->IsPlayer()) {
  4355. Player* player = (Player*)spawn;
  4356. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4357. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4358. player->GetInfoStruct()->set_pet_movement(2);
  4359. player->GetInfoStruct()->set_pet_behavior(3);
  4360. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4361. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4362. // Make sure the values get sent to the client
  4363. player->SetCharSheetChanged(true);
  4364. }
  4365. // Set the pets name
  4366. pet->SetName(random_pet_name.c_str());
  4367. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4368. if (max_level > 0)
  4369. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4370. else
  4371. pet->SetLevel(spawn->GetLevel());
  4372. // Set the max level this pet can reach
  4373. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4374. // Set the faction of the pet to the same faction as the owner
  4375. pet->SetFactionID(spawn->GetFactionID());
  4376. // Set the spawn as a pet
  4377. pet->SetPet(true);
  4378. // Give a pointer of the owner to the pet
  4379. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4380. // Give a pointer of the pet to the owner
  4381. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4382. // Set the pet type
  4383. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4384. // Set the spell id used to create this pet
  4385. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4386. // Set the spell tier used to create this pet
  4387. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4388. // Set the pets spawn type to 6
  4389. pet->SetSpawnType(6);
  4390. // Set the pets brain
  4391. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4392. // Check to see if the pet has a subtitle
  4393. if (strlen(pet->GetSubTitle()) > 0) {
  4394. // Add the players name to the front of the sub title
  4395. string pet_subtitle;
  4396. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4397. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4398. // Set the pets subtitle to the new one
  4399. pet->SetSubTitle(pet_subtitle.c_str());
  4400. }
  4401. // Add the "Pet Options" entity command to the pet
  4402. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4403. // Set the pet as the return value for this function
  4404. lua_interface->SetSpawnValue(state, pet);
  4405. return 1;
  4406. }
  4407. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4408. if (!lua_interface)
  4409. return 0;
  4410. Spawn* spawn = lua_interface->GetSpawn(state);
  4411. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4412. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4413. if (!spawn) {
  4414. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4415. return 0;
  4416. }
  4417. if (!spawn->IsEntity()) {
  4418. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4419. return 0;
  4420. }
  4421. if (((Entity*)spawn)->GetDeityPet()) {
  4422. if (spawn->IsPlayer()) {
  4423. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4424. if (client)
  4425. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4426. }
  4427. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4428. return 0;
  4429. }
  4430. if (pet_id == 0) {
  4431. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4432. return 0;
  4433. }
  4434. if (!luaspell) {
  4435. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4436. return 0;
  4437. }
  4438. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4439. if (!pet) {
  4440. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4441. return 0;
  4442. }
  4443. if (!pet->IsNPC()) {
  4444. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4445. return 0;
  4446. }
  4447. pet->SetX(spawn->GetX());
  4448. pet->SetY(spawn->GetY());
  4449. pet->SetZ(spawn->GetZ());
  4450. pet->SetLocation(spawn->GetLocation());
  4451. pet->SetHeading(spawn->GetHeading());
  4452. spawn->GetZone()->AddSpawn(pet);
  4453. string random_pet_name;
  4454. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4455. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4456. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4457. pet->SetName(random_pet_name.c_str());
  4458. pet->SetLevel(spawn->GetLevel());
  4459. pet->SetFactionID(spawn->GetFactionID());
  4460. pet->SetPet(true);
  4461. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4462. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4463. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4464. pet->SetSpawnType(6);
  4465. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4466. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4467. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4468. if (strlen(pet->GetSubTitle()) > 0) {
  4469. string pet_subtitle;
  4470. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4471. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4472. pet->SetSubTitle(pet_subtitle.c_str());
  4473. }
  4474. // deity and cosmetic pets are not attackable
  4475. pet->SetAttackable(false);
  4476. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4477. lua_interface->SetSpawnValue(state, pet);
  4478. return 1;
  4479. }
  4480. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4481. if (!lua_interface)
  4482. return 0;
  4483. Spawn* spawn = lua_interface->GetSpawn(state);
  4484. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4485. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4486. if (!spawn) {
  4487. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4488. return 0;
  4489. }
  4490. if (!spawn->IsEntity()) {
  4491. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4492. return 0;
  4493. }
  4494. if (((Entity*)spawn)->GetCosmeticPet()) {
  4495. if (spawn->IsPlayer()) {
  4496. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4497. if (client)
  4498. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4499. }
  4500. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4501. return 0;
  4502. }
  4503. if (pet_id == 0) {
  4504. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4505. return 0;
  4506. }
  4507. if (!luaspell) {
  4508. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4509. return 0;
  4510. }
  4511. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4512. if (!pet) {
  4513. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4514. return 0;
  4515. }
  4516. if (!pet->IsNPC()) {
  4517. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4518. return 0;
  4519. }
  4520. pet->SetX(spawn->GetX());
  4521. pet->SetY(spawn->GetY());
  4522. pet->SetZ(spawn->GetZ());
  4523. pet->SetLocation(spawn->GetLocation());
  4524. pet->SetHeading(spawn->GetHeading());
  4525. spawn->GetZone()->AddSpawn(pet);
  4526. string random_pet_name;
  4527. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4528. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4529. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4530. pet->SetName(random_pet_name.c_str());
  4531. pet->SetLevel(spawn->GetLevel());
  4532. pet->SetFactionID(spawn->GetFactionID());
  4533. pet->SetPet(true);
  4534. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4535. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4536. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4537. pet->SetSpawnType(6);
  4538. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4539. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4540. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4541. if (strlen(pet->GetSubTitle()) > 0) {
  4542. string pet_subtitle;
  4543. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4544. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4545. pet->SetSubTitle(pet_subtitle.c_str());
  4546. }
  4547. pet->SetAttackable(false);
  4548. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4549. lua_interface->SetSpawnValue(state, pet);
  4550. return 1;
  4551. }
  4552. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4553. if (!lua_interface)
  4554. return 0;
  4555. Spawn* spawn = lua_interface->GetSpawn(state);
  4556. if (!spawn) {
  4557. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4558. return 0;
  4559. }
  4560. if (!spawn->IsPet()) {
  4561. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4562. return 0;
  4563. }
  4564. if (!((NPC*)spawn)->IsDismissing())
  4565. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4566. return 0;
  4567. }
  4568. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4569. if (!lua_interface)
  4570. return 0;
  4571. Quest* quest = lua_interface->GetQuest(state);
  4572. if (!quest) {
  4573. 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));
  4574. return 0;
  4575. }
  4576. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4577. if (feather_color > 0)
  4578. quest->SetFeatherColor(feather_color);
  4579. return 0;
  4580. }
  4581. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4582. if (!lua_interface)
  4583. return 0;
  4584. Spawn* spawn = lua_interface->GetSpawn(state);
  4585. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4586. if (!spawn) {
  4587. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4588. return 0;
  4589. }
  4590. if (!spawn2) {
  4591. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4592. return 0;
  4593. }
  4594. spawn->RemoveSpawnAccess(spawn2);
  4595. return 0;
  4596. }
  4597. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4598. if (!lua_interface)
  4599. return 0;
  4600. ZoneServer* zone = lua_interface->GetZone(state);
  4601. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4602. if (!zone) {
  4603. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4604. return 0;
  4605. }
  4606. if (location_id == 0) {
  4607. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4608. return 0;
  4609. }
  4610. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4611. if (!location) {
  4612. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4613. return 0;
  4614. }
  4615. Spawn* spawn = 0;
  4616. if (location->entities[0]) {
  4617. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4618. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4619. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4620. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4621. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4622. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4623. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4624. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4625. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4626. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4627. if (spawn) {
  4628. const char* script = 0;
  4629. for (int x = 0; x < 3; x++) {
  4630. switch (x) {
  4631. case 0:
  4632. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4633. break;
  4634. case 1:
  4635. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4636. break;
  4637. case 2:
  4638. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4639. break;
  4640. }
  4641. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4642. spawn->SetSpawnScript(string(script));
  4643. break;
  4644. }
  4645. }
  4646. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4647. lua_interface->SetSpawnValue(state, spawn);
  4648. return 1;
  4649. }
  4650. else {
  4651. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4652. safe_delete(spawn);
  4653. }
  4654. }
  4655. return 0;
  4656. }
  4657. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4658. if (!lua_interface)
  4659. return 0;
  4660. Spawn* caster = lua_interface->GetSpawn(state);
  4661. Spawn* target = lua_interface->GetSpawn(state, 2);
  4662. int32 id = lua_interface->GetInt32Value(state, 3);
  4663. string command = lua_interface->GetStringValue(state, 4);
  4664. if (!caster) {
  4665. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4666. return 0;
  4667. }
  4668. if (!target) {
  4669. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4670. return 0;
  4671. }
  4672. if (!caster->IsPlayer()) {
  4673. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4674. return 0;
  4675. }
  4676. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4677. if (!entity_command) {
  4678. 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());
  4679. return 0;
  4680. }
  4681. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4682. if (!client) {
  4683. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4684. return 0;
  4685. }
  4686. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4687. return 0;
  4688. }
  4689. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4690. if (!lua_interface)
  4691. return 0;
  4692. Spawn* spawn = lua_interface->GetSpawn(state);
  4693. if (!spawn) {
  4694. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4695. return 0;
  4696. }
  4697. if (!spawn->IsNPC()) {
  4698. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4699. return 0;
  4700. }
  4701. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4702. return 0;
  4703. }
  4704. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4705. if (!lua_interface)
  4706. return 0;
  4707. Spawn* spawn = lua_interface->GetSpawn(state);
  4708. int16 tick = lua_interface->GetInt16Value(state, 2);
  4709. if (!spawn) {
  4710. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4711. return 0;
  4712. }
  4713. if (!spawn->IsNPC()) {
  4714. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4715. return 0;
  4716. }
  4717. if (tick < 20) {
  4718. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4719. return 0;
  4720. }
  4721. ((NPC*)spawn)->Brain()->SetTick(tick);
  4722. return 0;
  4723. }
  4724. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4725. if (!lua_interface)
  4726. return 0;
  4727. Spawn* spawn = lua_interface->GetSpawn(state);
  4728. Spawn* target = lua_interface->GetSpawn(state, 2);
  4729. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4730. if (!spawn) {
  4731. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4735. spawn->SetFollowTarget(target, follow_distance);
  4736. return 0;
  4737. }
  4738. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4739. if (!lua_interface)
  4740. return 0;
  4741. Spawn* spawn = lua_interface->GetSpawn(state);
  4742. if (!spawn) {
  4743. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4744. return 0;
  4745. }
  4746. Spawn* target = spawn->GetFollowTarget();
  4747. if (target) {
  4748. lua_interface->SetSpawnValue(state, target);
  4749. return 1;
  4750. }
  4751. return 0;
  4752. }
  4753. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4754. if (!lua_interface)
  4755. return 0;
  4756. Spawn* spawn = lua_interface->GetSpawn(state);
  4757. if (!spawn) {
  4758. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4759. return 0;
  4760. }
  4761. if (spawn->following)
  4762. spawn->following = false;
  4763. else
  4764. spawn->following = true;
  4765. return 0;
  4766. }
  4767. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4768. if (!lua_interface)
  4769. return 0;
  4770. Spawn* spawn = lua_interface->GetSpawn(state);
  4771. if (!spawn) {
  4772. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4773. return 0;
  4774. }
  4775. lua_interface->SetBooleanValue(state, spawn->following);
  4776. return 1;
  4777. }
  4778. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4779. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4780. // I will attempt to explain how this function works for future refrence
  4781. // Fist lets make sure lua_interface is valid, if not return out
  4782. if (!lua_interface)
  4783. return 0;
  4784. // Next we grab the first 2 params same as we usually would
  4785. Spawn* spawn = lua_interface->GetSpawn(state);
  4786. string var = lua_interface->GetStringValue(state, 2);
  4787. // 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
  4788. // 1 = Spawn
  4789. // 2 = Zone
  4790. // 3 = Item
  4791. // 4 = Quest
  4792. // 5 = String
  4793. // 6 = nil (null)
  4794. int8 dataType = 0;
  4795. // Define pointers for each potential type
  4796. Spawn* spawnVal = 0;
  4797. ZoneServer* zone = 0;
  4798. Item* item = 0;
  4799. Quest* quest = 0;
  4800. string val;
  4801. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4802. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4803. // options window are also light user data be we do not handle those.
  4804. // We check with lua_islightuserdata(lua_State*, index)
  4805. if (lua_islightuserdata(state, 3)) {
  4806. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4807. // and convert it to LUAUserData*
  4808. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4809. // Check to make sure the data we got is valid, if not give an error
  4810. if (!data || !data->IsCorrectlyInitialized()) {
  4811. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4812. }
  4813. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4814. else if (data->IsSpawn()) {
  4815. spawnVal = data->spawn;
  4816. dataType = 1;
  4817. }
  4818. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4819. else if (data->IsZone()) {
  4820. zone = data->zone;
  4821. dataType = 2;
  4822. }
  4823. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4824. else if (data->IsItem()) {
  4825. item = data->item;
  4826. dataType = 3;
  4827. }
  4828. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4829. else if (data->IsQuest()) {
  4830. quest = data->quest;
  4831. dataType = 4;
  4832. }
  4833. }
  4834. // Wasn't light user data, check if it is nil(null)
  4835. else if (lua_isnil(state, 3)) {
  4836. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4837. dataType = 6;
  4838. }
  4839. // Wasn't light user data or nil (null), must be a string
  4840. else {
  4841. // Set the string and dataType variable
  4842. val = lua_interface->GetStringValue(state, 3);
  4843. dataType = 5;
  4844. }
  4845. // We now have all the params, lets check to make sure they are valid
  4846. if (!spawn) {
  4847. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (var.length() == 0) {
  4851. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4852. return 0;
  4853. }
  4854. if (dataType == 0) {
  4855. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4856. return 0;
  4857. }
  4858. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4859. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4860. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4861. switch (dataType) {
  4862. case 1:
  4863. // 1 = Spawn
  4864. spawn->AddTempVariable(var, spawnVal);
  4865. break;
  4866. case 2:
  4867. // 2 = Zone
  4868. spawn->AddTempVariable(var, zone);
  4869. break;
  4870. case 3:
  4871. // 3 = Item
  4872. spawn->AddTempVariable(var, item);
  4873. break;
  4874. case 4:
  4875. // 4 = Quest
  4876. spawn->AddTempVariable(var, quest);
  4877. break;
  4878. case 5:
  4879. // 5 = String
  4880. spawn->AddTempVariable(var, val);
  4881. break;
  4882. case 6:
  4883. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4884. spawn->DeleteTempVariable(var);
  4885. break;
  4886. }
  4887. // And we are done so return out
  4888. return 0;
  4889. }
  4890. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4891. if (!lua_interface)
  4892. return 0;
  4893. Spawn* spawn = lua_interface->GetSpawn(state);
  4894. string var = lua_interface->GetStringValue(state, 2);
  4895. if (!spawn) {
  4896. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4897. return 0;
  4898. }
  4899. if (var.length() == 0) {
  4900. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4901. return 0;
  4902. }
  4903. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4904. int8 type = spawn->GetTempVariableType(var);
  4905. Spawn* spawn2 = 0;
  4906. ZoneServer* zone = 0;
  4907. Item* item = 0;
  4908. Quest* quest = 0;
  4909. // Set the lua function return value based on the type of data the variable contains
  4910. switch (type) {
  4911. case 1:
  4912. spawn2 = spawn->GetTempVariableSpawn(var);
  4913. if (!spawn2)
  4914. return 0;
  4915. lua_interface->SetSpawnValue(state, spawn2);
  4916. break;
  4917. case 2:
  4918. zone = spawn->GetTempVariableZone(var);
  4919. if (!zone)
  4920. return 0;
  4921. lua_interface->SetZoneValue(state, zone);
  4922. break;
  4923. case 3:
  4924. item = spawn->GetTempVariableItem(var);
  4925. if (!item)
  4926. return 0;
  4927. lua_interface->SetItemValue(state, item);
  4928. break;
  4929. case 4:
  4930. quest = spawn->GetTempVariableQuest(var);
  4931. if (!quest)
  4932. return 0;
  4933. lua_interface->SetQuestValue(state, quest);
  4934. break;
  4935. case 5:
  4936. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4937. break;
  4938. default:
  4939. // Not a valid type then the variable was not set so return out
  4940. return 0;
  4941. }
  4942. // Return value was set so return out
  4943. return 1;
  4944. }
  4945. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4946. {
  4947. if (!lua_interface)
  4948. return 0;
  4949. Quest* quest = lua_interface->GetQuest(state);
  4950. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4951. string description = lua_interface->GetStringValue(state, 3);
  4952. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4953. if (!quest) {
  4954. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4955. lua_interface->SetBooleanValue(state, false);
  4956. return 1;
  4957. }
  4958. if (!spawn) {
  4959. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4960. lua_interface->SetBooleanValue(state, false);
  4961. return 1;
  4962. }
  4963. if (!spawn->IsPlayer()) {
  4964. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4965. lua_interface->SetBooleanValue(state, false);
  4966. return 1;
  4967. }
  4968. if (item_id == 0) {
  4969. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4970. lua_interface->SetBooleanValue(state, false);
  4971. return 1;
  4972. }
  4973. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4974. if (!client) {
  4975. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4976. lua_interface->SetBooleanValue(state, false);
  4977. return 1;
  4978. }
  4979. Item* item = master_item_list.GetItem(item_id);
  4980. if (!item) {
  4981. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4982. lua_interface->SetBooleanValue(state, false);
  4983. return 1;
  4984. }
  4985. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4986. if (packet) {
  4987. packet->setDataByName("title", "Quest Reward!");
  4988. packet->setDataByName("name", quest->GetName());
  4989. packet->setDataByName("description", description.c_str());
  4990. packet->setDataByName("level", quest->GetLevel());
  4991. packet->setArrayLengthByName("num_rewards", 1);
  4992. packet->setArrayDataByName("reward_id", item->details.item_id);
  4993. if (client->GetVersion() < 860)
  4994. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4995. else if (client->GetVersion() < 1193)
  4996. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4997. else
  4998. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4999. client->QueuePacket(packet->serialize());
  5000. safe_delete(packet);
  5001. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5002. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5003. return 1;
  5004. }
  5005. lua_interface->SetBooleanValue(state, false);
  5006. return 1;
  5007. }
  5008. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5009. if (!lua_interface)
  5010. return 0;
  5011. Quest* quest = lua_interface->GetQuest(state);
  5012. if (!quest) {
  5013. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. quest->SetRepeatable(true);
  5017. return 0;
  5018. }
  5019. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5020. if (!lua_interface)
  5021. return 0;
  5022. Spawn* spawn = lua_interface->GetSpawn(state);
  5023. if (!spawn) {
  5024. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5025. return 0;
  5026. }
  5027. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5028. string ret = classes.GetClassNameCase(base_class);
  5029. if (ret.length() > 0) {
  5030. lua_interface->SetStringValue(state, ret.c_str());
  5031. return 1;
  5032. }
  5033. return 0;
  5034. }
  5035. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5036. if (!lua_interface)
  5037. return 0;
  5038. Spawn* player = lua_interface->GetSpawn(state);
  5039. if (player && player->IsPlayer()) {
  5040. Client* client = player->GetClient();
  5041. if (client)
  5042. client->SendWaypoints();
  5043. }
  5044. return 0;
  5045. }
  5046. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5047. if (!lua_interface)
  5048. return 0;
  5049. Spawn* player = lua_interface->GetSpawn(state);
  5050. string name = lua_interface->GetStringValue(state, 2);
  5051. int32 type = lua_interface->GetInt32Value(state, 3);
  5052. if (type == 0)
  5053. type = 2;
  5054. if (name.length() > 0) {
  5055. if (player && player->IsPlayer()) {
  5056. Client* client = player->GetClient();
  5057. if (client)
  5058. client->AddWaypoint(name, type);
  5059. }
  5060. }
  5061. return 0;
  5062. }
  5063. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5064. if (!lua_interface)
  5065. return 0;
  5066. Spawn* player = lua_interface->GetSpawn(state);
  5067. string name = lua_interface->GetStringValue(state, 2);
  5068. if (name.length() > 0) {
  5069. if (player && player->IsPlayer()) {
  5070. Client* client = player->GetClient();
  5071. if (client)
  5072. client->RemoveWaypoint(name);
  5073. }
  5074. }
  5075. return 0;
  5076. }
  5077. int EQ2Emu_lua_AddWard(lua_State* state) {
  5078. if (!lua_interface)
  5079. return 0;
  5080. int32 damage = lua_interface->GetInt32Value(state);
  5081. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5082. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5083. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5084. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5085. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5086. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5087. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5088. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5089. bool ward_was_added = false;
  5090. ZoneServer* zone = spell->caster->GetZone();
  5091. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5092. for (int32 i = 0; i < spell->targets.size(); i++) {
  5093. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5094. if (!target)
  5095. continue;
  5096. if (target->IsEntity()) {
  5097. // If the ward is already active remove it
  5098. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5099. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5100. // Create new ward info
  5101. WardInfo* ward = new WardInfo;
  5102. ward->Spell = spell;
  5103. ward->BaseDamage = damage;
  5104. ward->DamageLeft = damage;
  5105. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5106. ward->keepWard = keepWard;
  5107. ward->WardType = wardType;
  5108. if (damageAbsorptionPercent > 100)
  5109. damageAbsorptionPercent = 100;
  5110. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5111. if (damageAbsorptionMaxHealthPercent > 100)
  5112. damageAbsorptionMaxHealthPercent = 100;
  5113. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5114. ward->RedirectDamagePercent = redirectDamagePercent;
  5115. ward->LastRedirectDamage = 0;
  5116. ward->LastAbsorbedDamage = 0;
  5117. ward->HitCount = 0;
  5118. spell->num_triggers = maxHitCount;
  5119. spell->had_triggers = true;
  5120. spell->cancel_after_all_triggers = false;
  5121. ward->MaxHitCount = maxHitCount;
  5122. if (wardType == WARD_TYPE_MAGICAL)
  5123. ward->DamageType = damageTypes;
  5124. // Add the ward to the entity
  5125. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5126. ward_was_added = true;
  5127. }
  5128. }
  5129. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5130. if (ward_was_added && spell->caster->IsPlayer()) {
  5131. spell->had_dmg_remaining = true;
  5132. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5133. }
  5134. return 0;
  5135. }
  5136. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5137. if (!lua_interface)
  5138. return 0;
  5139. int32 amount = lua_interface->GetInt32Value(state);
  5140. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5141. WardInfo* ward = 0;
  5142. ZoneServer* zone = spell->caster->GetZone();
  5143. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5144. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5145. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5146. ward = target->GetWard(spell->spell->GetSpellID());
  5147. if (ward) {
  5148. ward->DamageLeft += amount;
  5149. if (ward->DamageLeft > ward->BaseDamage)
  5150. ward->DamageLeft = ward->BaseDamage;
  5151. for (int32 i = 0; i < spell->targets.size(); i++) {
  5152. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5153. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5154. }
  5155. }
  5156. }
  5157. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5158. if (ward && spell->caster->IsPlayer())
  5159. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5160. return 0;
  5161. }
  5162. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5163. if (!lua_interface)
  5164. return 0;
  5165. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5166. if (!spell) {
  5167. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5168. return 0;
  5169. }
  5170. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5171. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5172. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5173. if (ward) {
  5174. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5175. return 1;
  5176. }
  5177. }
  5178. return 0;
  5179. }
  5180. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5181. if (!lua_interface)
  5182. return 0;
  5183. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5184. if (!spell) {
  5185. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. string type = lua_interface->GetStringValue(state, 2);
  5189. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5190. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5191. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5192. if (ward) {
  5193. if (boost::iequals(type, "damageleft"))
  5194. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5195. else if (boost::iequals(type, "basedamage"))
  5196. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5197. else if (boost::iequals(type, "keepward"))
  5198. lua_interface->SetBooleanValue(state, ward->keepWard);
  5199. else if (boost::iequals(type, "wardtype"))
  5200. lua_interface->SetInt32Value(state, ward->WardType);
  5201. else if (boost::iequals(type, "dmgabsorptionpct"))
  5202. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5203. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5204. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5205. else if (boost::iequals(type, "redirectdamagepercent"))
  5206. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5207. else if (boost::iequals(type, "lastredirectdamage"))
  5208. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5209. else if (boost::iequals(type, "lastabsorbeddamage"))
  5210. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5211. else if (boost::iequals(type, "hitcount"))
  5212. lua_interface->SetInt32Value(state, ward->HitCount);
  5213. else if (boost::iequals(type, "maxhitcount"))
  5214. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5215. else
  5216. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5217. return 1;
  5218. }
  5219. }
  5220. return 0;
  5221. }
  5222. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5223. if (!lua_interface)
  5224. return 0;
  5225. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5226. ZoneServer* zone = spell->caster->GetZone();
  5227. Spawn* target = 0;
  5228. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5229. for (int32 i = 0; i < spell->targets.size(); i++) {
  5230. target = zone->GetSpawnByID(spell->targets.at(i));
  5231. if (target && target->IsEntity()) {
  5232. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5233. }
  5234. }
  5235. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5236. return 0;
  5237. }
  5238. int EQ2Emu_lua_Interrupt(lua_State* state)
  5239. {
  5240. if (!lua_interface)
  5241. return 0;
  5242. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5243. Spawn* target = lua_interface->GetSpawn(state, 2);
  5244. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5245. if (!caster)
  5246. {
  5247. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5248. return 0;
  5249. }
  5250. if (!target)
  5251. {
  5252. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5253. return 0;
  5254. }
  5255. if (!spell) {
  5256. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5257. return 0;
  5258. }
  5259. if (!target->IsEntity() && !spell)
  5260. {
  5261. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5262. return 0;
  5263. }
  5264. if (!target && spell) {
  5265. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5266. for (int8 i = 0; i < spell->targets.size(); i++) {
  5267. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5268. if (!target || !target->IsEntity())
  5269. continue;
  5270. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5271. }
  5272. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5273. }
  5274. else
  5275. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5276. return 0;
  5277. }
  5278. int EQ2Emu_lua_Stealth(lua_State* state) {
  5279. if (!lua_interface)
  5280. return 0;
  5281. int8 type = lua_interface->GetInt8Value(state);
  5282. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5283. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5284. if (!spell) {
  5285. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5286. return 0;
  5287. }
  5288. ZoneServer* zone = spell->caster->GetZone();
  5289. if (spawn) {
  5290. if (spawn->IsEntity()) {
  5291. if (type == 1) {
  5292. ((Entity*)spawn)->AddStealthSpell(spell);
  5293. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5294. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5295. }
  5296. else if (type == 2) {
  5297. ((Entity*)spawn)->AddInvisSpell(spell);
  5298. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5299. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5300. }
  5301. return 0;
  5302. }
  5303. else {
  5304. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5305. return 0;
  5306. }
  5307. }
  5308. else {
  5309. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5310. for (int32 i = 0; i < spell->targets.size(); i++) {
  5311. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5312. if (!spawn || !spawn->IsEntity())
  5313. continue;
  5314. if (type == 1) {
  5315. ((Entity*)spawn)->AddStealthSpell(spell);
  5316. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5317. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5318. }
  5319. else if (type == 2) {
  5320. ((Entity*)spawn)->AddInvisSpell(spell);
  5321. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5322. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5323. }
  5324. else {
  5325. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5326. break;
  5327. }
  5328. }
  5329. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5330. }
  5331. return 0;
  5332. }
  5333. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. Spawn* spawn = lua_interface->GetSpawn(state);
  5337. if (!spawn) {
  5338. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5339. return 0;
  5340. }
  5341. if (spawn->IsEntity()) {
  5342. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5343. return 1;
  5344. }
  5345. else
  5346. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5347. return 0;
  5348. }
  5349. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5350. if (!lua_interface)
  5351. return 0;
  5352. Spawn* spawn = lua_interface->GetSpawn(state);
  5353. if (!spawn) {
  5354. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5355. return 0;
  5356. }
  5357. if (spawn->IsEntity()) {
  5358. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5359. return 1;
  5360. }
  5361. else
  5362. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5363. return 0;
  5364. }
  5365. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5366. if (!lua_interface)
  5367. return 0;
  5368. Spawn* player = lua_interface->GetSpawn(state);
  5369. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5370. if (!player->IsPlayer()) {
  5371. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5372. return 0;
  5373. }
  5374. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5375. return 1;
  5376. }
  5377. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5378. if (!lua_interface)
  5379. return 0;
  5380. Spawn* player = lua_interface->GetSpawn(state);
  5381. int8 slot = lua_interface->GetInt8Value(state, 2);
  5382. if (!player) {
  5383. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5384. return 0;
  5385. }
  5386. if (!player->IsPlayer()) {
  5387. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5388. return 0;
  5389. }
  5390. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5391. if (!item) {
  5392. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5393. return 0;
  5394. }
  5395. lua_interface->SetItemValue(state, item);
  5396. return 1;
  5397. }
  5398. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5399. if (!lua_interface)
  5400. return 0;
  5401. Spawn* player = lua_interface->GetSpawn(state);
  5402. int32 id = lua_interface->GetInt32Value(state, 2);
  5403. if (!player) {
  5404. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5405. return 0;
  5406. }
  5407. if (!player->IsPlayer()) {
  5408. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5409. return 0;
  5410. }
  5411. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5412. if (!item) {
  5413. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5414. return 0;
  5415. }
  5416. lua_interface->SetItemValue(state, item);
  5417. return 1;
  5418. }
  5419. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5420. if (!lua_interface)
  5421. return 0;
  5422. Spawn* player = lua_interface->GetSpawn(state);
  5423. int32 id = lua_interface->GetInt32Value(state, 2);
  5424. int8 count = lua_interface->GetInt8Value(state, 3);
  5425. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5426. if (!player) {
  5427. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. if (!player->IsPlayer()) {
  5431. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5432. return 0;
  5433. }
  5434. if (!count)
  5435. count = 1;
  5436. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5437. if (!item) {
  5438. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5439. return 0;
  5440. }
  5441. lua_interface->SetItemValue(state, item);
  5442. return 1;
  5443. }
  5444. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5445. if (!lua_interface)
  5446. return 0;
  5447. Spawn* spawn = lua_interface->GetSpawn(state);
  5448. int32 anim = lua_interface->GetInt32Value(state, 2);
  5449. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5450. int8 type = lua_interface->GetInt8Value(state, 4);
  5451. if (!spawn) {
  5452. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. if (spawn2) {
  5456. if (spawn2->IsPlayer()) {
  5457. if (type != 1 && type != 2)
  5458. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5459. else
  5460. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5461. return 0;
  5462. }
  5463. else {
  5464. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5465. return 0;
  5466. }
  5467. }
  5468. else
  5469. spawn->GetZone()->PlayAnimation(spawn, anim);
  5470. return 0;
  5471. }
  5472. int EQ2Emu_lua_IsPet(lua_State* state) {
  5473. if (!lua_interface)
  5474. return 0;
  5475. Spawn* spawn = lua_interface->GetSpawn(state);
  5476. if (!spawn) {
  5477. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5481. return 1;
  5482. }
  5483. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* spawn = lua_interface->GetSpawn(state);
  5487. if (!spawn) {
  5488. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (!spawn->IsNPC()) {
  5492. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5493. return 0;
  5494. }
  5495. if (((NPC*)spawn)->GetOwner()) {
  5496. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5497. return 1;
  5498. }
  5499. return 0;
  5500. }
  5501. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5502. if (!lua_interface)
  5503. return 0;
  5504. Spawn* spawn = lua_interface->GetSpawn(state);
  5505. Spawn* target = lua_interface->GetSpawn(state, 2);
  5506. if (!spawn) {
  5507. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. if (!spawn) {
  5511. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. spawn->SetTarget(target);
  5515. return 0;
  5516. }
  5517. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5518. if (!lua_interface)
  5519. return 0;
  5520. Spawn* spawn = lua_interface->GetSpawn(state);
  5521. bool val = lua_interface->GetBooleanValue(state, 2);
  5522. if (!spawn) {
  5523. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. if (!spawn->IsEntity()) {
  5527. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5528. return 0;
  5529. }
  5530. ((Entity*)spawn)->InCombat(val);
  5531. if (val) {
  5532. spawn->ClearRunningLocations();
  5533. spawn->CalculateRunningLocation(true);
  5534. }
  5535. return 0;
  5536. }
  5537. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5538. if (!lua_interface)
  5539. return 0;
  5540. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5541. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5542. if (!spawn1) {
  5543. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. if (!spawn2) {
  5547. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5548. return 0;
  5549. }
  5550. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5551. return 1;
  5552. }
  5553. int EQ2Emu_lua_Runback(lua_State* state) {
  5554. if (!lua_interface)
  5555. return 0;
  5556. Spawn* spawn = lua_interface->GetSpawn(state);
  5557. if (!spawn) {
  5558. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. if (!spawn->IsNPC()) {
  5562. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5563. return 0;
  5564. }
  5565. ((NPC*)spawn)->Runback();
  5566. return 0;
  5567. }
  5568. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5569. if (!lua_interface)
  5570. return 0;
  5571. Spawn* spawn = lua_interface->GetSpawn(state);
  5572. if (!spawn) {
  5573. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. if (!spawn->IsNPC()) {
  5577. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5578. return 0;
  5579. }
  5580. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5581. return 1;
  5582. }
  5583. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5584. if (!lua_interface)
  5585. return 0;
  5586. Spawn* spawn = lua_interface->GetSpawn(state);
  5587. if (!spawn) {
  5588. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5589. return 0;
  5590. }
  5591. if (!spawn->IsEntity()) {
  5592. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5593. return 0;
  5594. }
  5595. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5596. return 1;
  5597. }
  5598. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5599. if (!lua_interface)
  5600. return 0;
  5601. Spawn* spawn = lua_interface->GetSpawn(state);
  5602. if (!spawn) {
  5603. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5604. return 0;
  5605. }
  5606. if (!spawn->IsEntity()) {
  5607. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5608. return 0;
  5609. }
  5610. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5611. return 1;
  5612. }
  5613. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5614. if (!lua_interface)
  5615. return 0;
  5616. Spawn* spawn = lua_interface->GetSpawn(state);
  5617. if (!spawn) {
  5618. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5619. return 0;
  5620. }
  5621. if (!spawn->IsEntity()) {
  5622. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5623. return 0;
  5624. }
  5625. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5626. return 1;
  5627. }
  5628. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5629. if (!lua_interface)
  5630. return 0;
  5631. Spawn* spawn = lua_interface->GetSpawn(state);
  5632. if (!spawn) {
  5633. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. if (!spawn->IsEntity()) {
  5637. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5638. return 0;
  5639. }
  5640. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5641. return 1;
  5642. }
  5643. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5644. if (!lua_interface)
  5645. return 0;
  5646. Spawn* spawn = lua_interface->GetSpawn(state);
  5647. Spawn* target = lua_interface->GetSpawn(state, 2);
  5648. float distance = lua_interface->GetFloatValue(state, 3);
  5649. if (!spawn) {
  5650. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5651. return 0;
  5652. }
  5653. if (!target) {
  5654. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5655. return 0;
  5656. }
  5657. if (!spawn->IsNPC()) {
  5658. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5659. return 0;
  5660. }
  5661. if (!target->IsEntity()) {
  5662. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5663. return 0;
  5664. }
  5665. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5666. return 1;
  5667. }
  5668. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5669. if (!lua_interface)
  5670. return 0;
  5671. Spawn* spawn = lua_interface->GetSpawn(state);
  5672. Spawn* target = lua_interface->GetSpawn(state, 2);
  5673. float distance = lua_interface->GetFloatValue(state, 3);
  5674. if (!spawn) {
  5675. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!target) {
  5679. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5680. return 0;
  5681. }
  5682. if (!spawn->IsNPC()) {
  5683. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5684. return 0;
  5685. }
  5686. if (!target->IsEntity()) {
  5687. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5688. return 0;
  5689. }
  5690. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5691. return 0;
  5692. }
  5693. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5694. if (!lua_interface)
  5695. return 0;
  5696. Spawn* spawn = lua_interface->GetSpawn(state);
  5697. if (!spawn) {
  5698. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5699. return 0;
  5700. }
  5701. if (!spawn->IsNPC()) {
  5702. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5703. return 0;
  5704. }
  5705. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5706. return 1;
  5707. }
  5708. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5709. if (!lua_interface)
  5710. return 0;
  5711. Spawn* spawn = lua_interface->GetSpawn(state);
  5712. if (!spawn) {
  5713. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5714. return 0;
  5715. }
  5716. if (!spawn->IsNPC()) {
  5717. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5718. return 0;
  5719. }
  5720. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5721. return 1;
  5722. }
  5723. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5724. if (!lua_interface)
  5725. return 0;
  5726. Spawn* spawn = lua_interface->GetSpawn(state);
  5727. if (!spawn) {
  5728. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. if (!spawn->IsNPC()) {
  5732. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5733. return 0;
  5734. }
  5735. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5736. if (hated) {
  5737. lua_interface->SetSpawnValue(state, hated);
  5738. return 1;
  5739. }
  5740. return 0;
  5741. }
  5742. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5743. if (!lua_interface)
  5744. return 0;
  5745. Spawn* spawn = lua_interface->GetSpawn(state);
  5746. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5747. if (!spawn) {
  5748. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5749. return 0;
  5750. }
  5751. if (!spawn->IsNPC()) {
  5752. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5753. return 0;
  5754. }
  5755. if (!hated) {
  5756. ((NPC*)spawn)->Brain()->ClearHate();
  5757. return 0;
  5758. }
  5759. else
  5760. {
  5761. if (!hated->IsEntity()) {
  5762. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5763. return 0;
  5764. }
  5765. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5766. return 0;
  5767. }
  5768. return 0;
  5769. }
  5770. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5771. if (!lua_interface)
  5772. return 0;
  5773. Spawn* spawn = lua_interface->GetSpawn(state);
  5774. if (!spawn) {
  5775. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5776. return 0;
  5777. }
  5778. if (!spawn->IsNPC()) {
  5779. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5780. return 0;
  5781. }
  5782. ((NPC*)spawn)->Brain()->ClearEncounter();
  5783. return 0;
  5784. }
  5785. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5786. if (!lua_interface)
  5787. return 0;
  5788. Spawn* spawn = lua_interface->GetSpawn(state);
  5789. if (!spawn) {
  5790. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5791. return 0;
  5792. }
  5793. if (!spawn->IsNPC()) {
  5794. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5795. return 0;
  5796. }
  5797. // Temp list to store hate list
  5798. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5799. if (encounterList->size() == 0) {
  5800. safe_delete(encounterList);
  5801. return 0;
  5802. }
  5803. lua_createtable(state, encounterList->size(), 0);
  5804. int newTable = lua_gettop(state);
  5805. for (int32 i = 0; i < encounterList->size(); i++) {
  5806. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5807. if (temp)
  5808. lua_interface->SetSpawnValue(state, temp);
  5809. lua_rawseti(state, newTable, i + 1);
  5810. }
  5811. safe_delete(encounterList);
  5812. return 1;
  5813. }
  5814. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5815. if (!lua_interface)
  5816. return 0;
  5817. Spawn* spawn = lua_interface->GetSpawn(state);
  5818. if (!spawn) {
  5819. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. if (!spawn->IsNPC()) {
  5823. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5824. return 0;
  5825. }
  5826. // Temp list to store hate list
  5827. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5828. if (hateList->size() == 0) {
  5829. safe_delete(hateList);
  5830. return 0;
  5831. }
  5832. lua_createtable(state, hateList->size(), 0);
  5833. int newTable = lua_gettop(state);
  5834. for (int32 i = 0; i < hateList->size(); i++) {
  5835. lua_interface->SetSpawnValue(state, hateList->at(i));
  5836. lua_rawseti(state, newTable, i + 1);
  5837. }
  5838. safe_delete(hateList);
  5839. return 1;
  5840. }
  5841. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5842. if (!lua_interface)
  5843. return 0;
  5844. Spawn* spawn = lua_interface->GetSpawn(state);
  5845. if (!spawn) {
  5846. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5847. return 0;
  5848. }
  5849. if (spawn->IsPlayer()) {
  5850. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5851. lua_interface->SetBooleanValue(state, true);
  5852. else
  5853. lua_interface->SetBooleanValue(state, false);
  5854. return 1;
  5855. }
  5856. else {
  5857. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5858. return 1;
  5859. }
  5860. }
  5861. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. Quest* quest = lua_interface->GetQuest(state);
  5865. if (!quest) {
  5866. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. quest->SetCompletedFlag(true);
  5870. return 0;
  5871. }
  5872. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5873. if (!lua_interface)
  5874. return 0;
  5875. Spawn* spawn = lua_interface->GetSpawn(state);
  5876. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5877. int8 tier = lua_interface->GetInt8Value(state, 3);
  5878. if (!spawn) {
  5879. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5880. return 0;
  5881. }
  5882. if (!spawn->IsEntity()) {
  5883. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. if (spellID == 0) {
  5887. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5891. if (effect) {
  5892. if (tier > 0) {
  5893. // If a tier was passed chec to see if it is the same as the effect
  5894. if (tier == effect->tier)
  5895. lua_interface->SetBooleanValue(state, true);
  5896. else
  5897. lua_interface->SetBooleanValue(state, false);
  5898. return 1;
  5899. }
  5900. else {
  5901. // Have an effect but no tier was passed so return true
  5902. lua_interface->SetBooleanValue(state, true);
  5903. }
  5904. return 1;
  5905. }
  5906. // no effect so return false
  5907. lua_interface->SetBooleanValue(state, false);
  5908. return 1;
  5909. }
  5910. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5911. if (!lua_interface)
  5912. return 0;
  5913. Spawn* spawn = lua_interface->GetSpawn(state);
  5914. int32 id = lua_interface->GetInt32Value(state, 2);
  5915. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5916. Spawn* spawn2 = 0;
  5917. vector<Spawn*> list;
  5918. if (!spawn) {
  5919. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. //If zone not provided, use spawn's zone
  5923. if (!zone)
  5924. zone = spawn->GetZone();
  5925. list = zone->GetSpawnsByID(id);
  5926. if (list.size() == 0) {
  5927. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. vector<Spawn*>::iterator itr = list.begin();
  5931. for (int8 i = 0; i < list.size(); i++) {
  5932. spawn2 = itr[i];
  5933. if (spawn2)
  5934. spawn2->AddAllowAccessSpawn(spawn);
  5935. }
  5936. return 0;
  5937. }
  5938. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5939. if (!lua_interface)
  5940. return 0;
  5941. Spawn* spawn = lua_interface->GetSpawn(state);
  5942. int32 id = lua_interface->GetInt32Value(state, 2);
  5943. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5944. Spawn* spawn2 = 0;
  5945. if (!spawn) {
  5946. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5947. return 0;
  5948. }
  5949. //If zone not provided, use spawn's zone
  5950. if (!zone)
  5951. zone = spawn->GetZone();
  5952. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5953. vector<Spawn*>::iterator itr = list.begin();
  5954. if (list.size() == 0) {
  5955. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5956. return 0;
  5957. }
  5958. for (int8 i = 0; i < list.size(); i++) {
  5959. spawn2 = itr[i];
  5960. if (spawn2)
  5961. spawn2->RemoveSpawnAccess(spawn);
  5962. }
  5963. return 0;
  5964. }
  5965. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5966. if (!lua_interface)
  5967. return 0;
  5968. Quest* quest = lua_interface->GetQuest(state);
  5969. if (!quest) {
  5970. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5971. return 0;
  5972. }
  5973. quest->SetYellowName(true);
  5974. return 0;
  5975. }
  5976. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5977. if (!lua_interface)
  5978. return 0;
  5979. Spawn* spawn = lua_interface->GetSpawn(state);
  5980. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5981. if (!spawn) {
  5982. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. if (!spawn->IsPlayer()) {
  5986. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5987. return 0;
  5988. }
  5989. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5990. return 1;
  5991. }
  5992. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. if (!spawn) {
  5997. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. if (!spawn->IsPlayer()) {
  6001. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6002. return 0;
  6003. }
  6004. ZoneServer* zone = spawn->GetZone();
  6005. if (!zone) {
  6006. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. Instance_Type iType = zone->GetInstanceType();
  6010. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6011. iType == GROUP_LOCKOUT_INSTANCE ||
  6012. iType == RAID_LOCKOUT_INSTANCE ||
  6013. iType == SOLO_PERSIST_INSTANCE ||
  6014. iType == GROUP_PERSIST_INSTANCE ||
  6015. iType == RAID_PERSIST_INSTANCE) {
  6016. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6017. if (data) {
  6018. // Check to see if the timer has already been set, if it has return out.
  6019. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6020. return 0;
  6021. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6022. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6023. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6024. if (client) {
  6025. string time_msg = "";
  6026. int32 time = data->success_lockout_time;
  6027. int16 hour;
  6028. int8 min;
  6029. int8 sec;
  6030. hour = time / 3600;
  6031. time = time % 3600;
  6032. min = time / 60;
  6033. time = time % 60;
  6034. sec = time;
  6035. if (hour > 0) {
  6036. char temp[10];
  6037. sprintf(temp, " %i", hour);
  6038. time_msg.append(temp);
  6039. time_msg.append(" hour");
  6040. time_msg.append((hour > 1) ? "s" : "");
  6041. }
  6042. if (min > 0) {
  6043. char temp[5];
  6044. sprintf(temp, " %i", min);
  6045. time_msg.append(temp);
  6046. time_msg.append(" minute");
  6047. time_msg.append((min > 1) ? "s" : "");
  6048. }
  6049. // Only add seconds if minutes and hours are 0
  6050. if (hour == 0 && min == 0 && sec > 0) {
  6051. char temp[5];
  6052. sprintf(temp, " %i", sec);
  6053. time_msg.append(temp);
  6054. time_msg.append(" second");
  6055. time_msg.append((sec > 1) ? "s" : "");
  6056. }
  6057. 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());
  6058. }
  6059. }
  6060. else
  6061. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6062. }
  6063. else
  6064. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6068. if (!lua_interface)
  6069. return 0;
  6070. Spawn* spawn = lua_interface->GetSpawn(state);
  6071. if (!spawn) {
  6072. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. if (!spawn->IsPlayer()) {
  6076. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6077. return 0;
  6078. }
  6079. ZoneServer* zone = spawn->GetZone();
  6080. if (!zone) {
  6081. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6082. return 0;
  6083. }
  6084. Instance_Type iType = zone->GetInstanceType();
  6085. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6086. iType == GROUP_LOCKOUT_INSTANCE ||
  6087. iType == RAID_LOCKOUT_INSTANCE ||
  6088. iType == SOLO_PERSIST_INSTANCE ||
  6089. iType == GROUP_PERSIST_INSTANCE ||
  6090. iType == RAID_PERSIST_INSTANCE) {
  6091. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6092. if (data) {
  6093. // Check to see if the timer has already been set, if it has return out.
  6094. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6095. return 0;
  6096. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6097. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6098. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6099. if (client) {
  6100. string time_msg = "";
  6101. int32 time = data->failure_lockout_time;
  6102. int16 hour;
  6103. int8 min;
  6104. int8 sec;
  6105. hour = time / 3600;
  6106. time = time % 3600;
  6107. min = time / 60;
  6108. time = time % 60;
  6109. sec = time;
  6110. if (hour > 0) {
  6111. char temp[10];
  6112. sprintf(temp, " %i", hour);
  6113. time_msg.append(temp);
  6114. time_msg.append(" hour");
  6115. time_msg.append((hour > 1) ? "s" : "");
  6116. }
  6117. if (min > 0) {
  6118. char temp[5];
  6119. sprintf(temp, " %i", min);
  6120. time_msg.append(temp);
  6121. time_msg.append(" minute");
  6122. time_msg.append((min > 1) ? "s" : "");
  6123. }
  6124. // Only add seconds if minutes and hours are 0
  6125. if (hour == 0 && min == 0 && sec > 0) {
  6126. char temp[5];
  6127. sprintf(temp, " %i", sec);
  6128. time_msg.append(temp);
  6129. time_msg.append(" second");
  6130. time_msg.append((sec > 1) ? "s" : "");
  6131. }
  6132. 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());
  6133. }
  6134. }
  6135. else
  6136. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6137. }
  6138. else
  6139. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6140. return 0;
  6141. }
  6142. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6143. if (!lua_interface)
  6144. return 0;
  6145. Spawn* spawn = lua_interface->GetSpawn(state);
  6146. if (!spawn) {
  6147. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6148. return 0;
  6149. }
  6150. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6151. return 1;
  6152. }
  6153. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6154. if (!lua_interface)
  6155. return 0;
  6156. Spawn* player = lua_interface->GetSpawn(state);
  6157. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6158. if (!player) {
  6159. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if (!player->IsPlayer()) {
  6163. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. if (!ground) {
  6167. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6168. return 0;
  6169. }
  6170. if (!ground->IsGroundSpawn()) {
  6171. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6172. return 0;
  6173. }
  6174. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6175. if (!groundspawn_entries) {
  6176. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6177. return 0;
  6178. }
  6179. Skill* skill = 0;
  6180. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6181. if (collection_skill == "Collecting")
  6182. skill = ((Player*)player)->GetSkillByName("Gathering");
  6183. else
  6184. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6185. if (!skill) {
  6186. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6187. return 0;
  6188. }
  6189. vector<GroundSpawnEntry*>::iterator itr;
  6190. GroundSpawnEntry* entry = 0;
  6191. bool can_harvest = false;
  6192. sint32 min_skill = -1;
  6193. // first, iterate through groundspawn_entries, discard tables player cannot use
  6194. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6195. {
  6196. entry = *itr;
  6197. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6198. min_skill = entry->min_skill_level;
  6199. // if player lacks skill, skip table
  6200. if (entry->min_skill_level > skill->current_val)
  6201. continue;
  6202. // if bonus, but player lacks level, skip table
  6203. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6204. continue;
  6205. can_harvest = true;
  6206. break;
  6207. }
  6208. lua_interface->SetBooleanValue(state, can_harvest);
  6209. // If false, send the message to the client
  6210. if (!can_harvest) {
  6211. Client* client = player->GetZone()->GetClientBySpawn(player);
  6212. if (client) {
  6213. string msg = "You do not have enough skill to ";
  6214. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6215. msg.append("gather");
  6216. else if (collection_skill == "Mining")
  6217. msg.append("mine");
  6218. else if (collection_skill == "Trapping")
  6219. msg.append("trap");
  6220. else if (collection_skill == "Foresting")
  6221. msg.append("forest");
  6222. else if (collection_skill == "Fishing")
  6223. msg.append("catch");
  6224. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6225. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6226. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6227. }
  6228. }
  6229. return 1;
  6230. }
  6231. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6232. if (!lua_interface)
  6233. return 0;
  6234. Spawn* player = lua_interface->GetSpawn(state);
  6235. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6236. if (!player) {
  6237. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. if (!player->IsPlayer()) {
  6241. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6242. return 0;
  6243. }
  6244. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6245. lua_interface->SetBooleanValue(state, ret);
  6246. return 1;
  6247. }
  6248. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6249. // Check to see if we have a valid lua_interface
  6250. if (!lua_interface)
  6251. return 0;
  6252. // Get the spawn that is getting the pet
  6253. Spawn* spawn = lua_interface->GetSpawn(state);
  6254. Spawn* target = lua_interface->GetSpawn(state, 2);
  6255. // Get the DB ID of the pet
  6256. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6257. float x = lua_interface->GetFloatValue(state, 4);
  6258. float y = lua_interface->GetFloatValue(state, 5);
  6259. float z = lua_interface->GetFloatValue(state, 6);
  6260. // Get the spell that this command was called from
  6261. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6262. // Check to make sure the spawn pointer is valid
  6263. if (!spawn) {
  6264. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6265. return 0;
  6266. }
  6267. // Check to make sure the spawn is an entity
  6268. if (!spawn->IsEntity()) {
  6269. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!target) {
  6273. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. if (!target->IsEntity()) {
  6277. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6278. return 0;
  6279. }
  6280. // Check to see if the DB ID for the pet is set
  6281. if (pet_id == 0) {
  6282. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. // Check to see if the pointer to the spell is valid
  6286. if (!luaspell) {
  6287. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6288. return 0;
  6289. }
  6290. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6291. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6292. if (!pet) {
  6293. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6294. return 0;
  6295. }
  6296. // Check to make sure the pet is an npc
  6297. if (!pet->IsNPC()) {
  6298. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6299. return 0;
  6300. }
  6301. if (x == 0)
  6302. x = spawn->GetX();
  6303. if (y == 0)
  6304. y = spawn->GetY();
  6305. if (z == 0)
  6306. z = spawn->GetZ();
  6307. // Spawn the pet at the same location as the owner
  6308. pet->SetX(x);
  6309. pet->SetY(y);
  6310. pet->SetZ(z);
  6311. pet->SetLocation(spawn->GetLocation());
  6312. pet->SetHeading(spawn->GetHeading());
  6313. spawn->GetZone()->AddSpawn(pet);
  6314. /*
  6315. const char* spawn_script = world.GetSpawnScript(pet_id);
  6316. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6317. spawn->SetSpawnScript(string(spawn_script));
  6318. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6319. }*/
  6320. // Get a random pet name
  6321. string random_pet_name;
  6322. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6323. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6324. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6325. // Set the pets name
  6326. pet->SetName(random_pet_name.c_str());
  6327. // Set the level of the pet to the owners level
  6328. pet->SetLevel(spawn->GetLevel());
  6329. // Set the faction of the pet to the same faction as the owner
  6330. pet->SetFactionID(spawn->GetFactionID());
  6331. // Set the spawn as a pet
  6332. pet->SetPet(true);
  6333. // Give a pointer of the owner to the pet
  6334. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6335. // Set the pet type
  6336. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6337. // Set the spell id used to create this pet
  6338. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6339. // Set the spell tier used to create this pet
  6340. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6341. // Set the pets spawn type to 6
  6342. pet->SetSpawnType(6);
  6343. // Set the pets brain
  6344. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6345. // Check to see if the pet has a subtitle
  6346. if (strlen(pet->GetSubTitle()) > 0) {
  6347. // Add the players name to the front of the sub title
  6348. string pet_subtitle;
  6349. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6350. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6351. // Set the pets subtitle to the new one
  6352. pet->SetSubTitle(pet_subtitle.c_str());
  6353. }
  6354. // Set the pet as the return value for this function
  6355. lua_interface->SetSpawnValue(state, pet);
  6356. return 1;
  6357. }
  6358. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6359. if (!lua_interface)
  6360. return 0;
  6361. Spawn* spawn = lua_interface->GetSpawn(state);
  6362. Spawn* player = lua_interface->GetSpawn(state, 2);
  6363. float max_distance = lua_interface->GetFloatValue(state, 3);
  6364. string type = lua_interface->GetStringValue(state, 4);
  6365. if (!spawn || (spawn && spawn->IsPlayer())) {
  6366. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. if (!player || (player && !player->IsPlayer())) {
  6370. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6371. return 0;
  6372. }
  6373. Client* client = 0;
  6374. if (player->GetZone())
  6375. client = player->GetZone()->GetClientBySpawn(player);
  6376. if (!client) {
  6377. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6378. return 0;
  6379. }
  6380. //Set max_distance to default if not set or not proper value
  6381. if (max_distance <= 0)
  6382. max_distance = 500;
  6383. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6384. if (packet) {
  6385. float unknown2_3 = 0;
  6386. int8 placement_mode = 0;
  6387. if (type == "wall") {
  6388. placement_mode = 2;
  6389. unknown2_3 = 150;
  6390. }
  6391. else if (type == "ceiling")
  6392. placement_mode = 1;
  6393. packet->setDataByName("placement_mode", placement_mode);
  6394. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6395. packet->setDataByName("model_type", spawn->GetModelType());
  6396. packet->setDataByName("unknown", 1); //size
  6397. packet->setDataByName("unknown2", 1); //size 2
  6398. packet->setDataByName("unknown2", .5, 1); //size 3
  6399. packet->setDataByName("unknown2", 3, 2);
  6400. packet->setDataByName("unknown2", unknown2_3, 3);
  6401. packet->setDataByName("max_distance", max_distance);
  6402. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6403. client->QueuePacket(packet->serialize());
  6404. safe_delete(packet);
  6405. }
  6406. return 0;
  6407. }
  6408. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6409. if (!lua_interface)
  6410. return 0;
  6411. Item* item = lua_interface->GetItem(state);
  6412. if (!item) {
  6413. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6414. return 0;
  6415. }
  6416. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6417. return 1;
  6418. }
  6419. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6420. if (!lua_interface)
  6421. return 0;
  6422. Spawn* spawn = lua_interface->GetSpawn(state);
  6423. if (!spawn) {
  6424. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6425. return 0;
  6426. }
  6427. if (spawn->GetZone())
  6428. spawn->GetZone()->AddTransportSpawn(spawn);
  6429. return 0;
  6430. }
  6431. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6432. if (!lua_interface)
  6433. return 0;
  6434. Skill* skill = lua_interface->GetSkill(state);
  6435. if (!skill) {
  6436. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. lua_interface->SetInt32Value(state, skill->current_val);
  6440. return 1;
  6441. }
  6442. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6443. if (!lua_interface)
  6444. return 0;
  6445. Skill* skill = lua_interface->GetSkill(state);
  6446. if (!skill) {
  6447. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6448. return 0;
  6449. }
  6450. lua_interface->SetInt32Value(state, skill->max_val);
  6451. return 1;
  6452. }
  6453. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6454. if (!lua_interface)
  6455. return 0;
  6456. Skill* skill = lua_interface->GetSkill(state);
  6457. if (!skill) {
  6458. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6462. return 1;
  6463. }
  6464. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6465. if (!lua_interface)
  6466. return 0;
  6467. Skill* skill = lua_interface->GetSkill(state);
  6468. int16 value = lua_interface->GetInt16Value(state, 2);
  6469. if (!skill) {
  6470. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. skill->max_val = value;
  6474. if (skill->max_val < skill->current_val)
  6475. skill->current_val = skill->max_val;
  6476. return 0;
  6477. }
  6478. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6479. if (!lua_interface)
  6480. return 0;
  6481. Skill* skill = lua_interface->GetSkill(state);
  6482. int16 value = lua_interface->GetInt16Value(state, 2);
  6483. if (!skill) {
  6484. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6485. return 0;
  6486. }
  6487. if (value > skill->max_val)
  6488. skill->current_val = skill->max_val;
  6489. else
  6490. skill->current_val = value;
  6491. return 0;
  6492. }
  6493. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6494. if (!lua_interface)
  6495. return 0;
  6496. Spawn* player = lua_interface->GetSpawn(state);
  6497. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6498. if (skill_id > 0 && player && player->IsPlayer()) {
  6499. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6500. return 1;
  6501. }
  6502. return 0;
  6503. }
  6504. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6505. if (!lua_interface)
  6506. return 0;
  6507. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6508. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6509. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6510. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6511. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6512. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6513. if (player_spawn && player_spawn->IsPlayer()) {
  6514. Player* player = (Player*)player_spawn;
  6515. bool added = false;
  6516. if (!player->skill_list.HasSkill(skill_id)) {
  6517. player->AddSkill(skill_id, current_val, max_val, true);
  6518. added = true;
  6519. }
  6520. 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
  6521. Client* client = player->GetClient();
  6522. if (client) {
  6523. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6524. if (packet)
  6525. client->QueuePacket(packet);
  6526. }
  6527. }
  6528. if (added) {
  6529. lua_interface->SetBooleanValue(state, true);
  6530. return 1;
  6531. }
  6532. }
  6533. else {
  6534. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6535. }
  6536. }
  6537. else {
  6538. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6539. }
  6540. lua_interface->SetBooleanValue(state, false);
  6541. return 1;
  6542. }
  6543. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6544. if (!lua_interface)
  6545. return 0;
  6546. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6547. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6548. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6549. if (skill_id > 0) {
  6550. if (player_spawn && player_spawn->IsPlayer()) {
  6551. Player* player = (Player*)player_spawn;
  6552. if (player->skill_list.HasSkill(skill_id)) {
  6553. player->RemovePlayerSkill(skill_id);
  6554. if (!more_to_remove) {
  6555. Client* client = player->GetClient();
  6556. if (client) {
  6557. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6558. if (packet)
  6559. client->QueuePacket(packet);
  6560. }
  6561. }
  6562. }
  6563. }
  6564. else {
  6565. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6566. }
  6567. }
  6568. else {
  6569. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6570. }
  6571. return 0;
  6572. }
  6573. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6574. if (!lua_interface)
  6575. return 0;
  6576. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6577. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6578. int16 amount = lua_interface->GetInt8Value(state, 3);
  6579. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6580. if (amount > 0 && skill_type < 100) {
  6581. if (player_spawn && player_spawn->IsPlayer()) {
  6582. Player* player = (Player*)player_spawn;
  6583. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6584. if (!more_to_increase) {
  6585. Client* client = player->GetClient();
  6586. if (client) {
  6587. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6588. if (packet)
  6589. client->QueuePacket(packet);
  6590. }
  6591. }
  6592. }
  6593. else {
  6594. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6595. }
  6596. }
  6597. else {
  6598. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6599. }
  6600. return 0;
  6601. }
  6602. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6603. if (!lua_interface)
  6604. return 0;
  6605. Spawn* spawn = lua_interface->GetSpawn(state);
  6606. string name = lua_interface->GetStringValue(state, 2);
  6607. if (!spawn) {
  6608. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. if (!spawn->IsEntity()) {
  6612. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6616. if (skill) {
  6617. lua_interface->SetSkillValue(state, skill);
  6618. return 1;
  6619. }
  6620. return 0;
  6621. }
  6622. int EQ2Emu_lua_AddProc(lua_State* state) {
  6623. if (!lua_interface)
  6624. return 0;
  6625. Spawn* spawn = lua_interface->GetSpawn(state);
  6626. int8 type = lua_interface->GetInt8Value(state, 2);
  6627. float chance = lua_interface->GetFloatValue(state, 3);
  6628. Item* item = lua_interface->GetItem(state, 4);
  6629. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6630. LuaSpell* spell = 0;
  6631. if (!spawn && (!spell || !use_all_spelltargets)) {
  6632. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6636. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6637. return 0;
  6638. }
  6639. if (!item)
  6640. spell = lua_interface->GetCurrentSpell(state);
  6641. if (!item && !spell) {
  6642. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6643. return 0;
  6644. }
  6645. if (spell && use_all_spelltargets) {
  6646. Spawn* target;
  6647. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6648. for (int8 i = 0; i < spell->targets.size(); i++) {
  6649. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6650. if (!target || !target->IsEntity())
  6651. continue;
  6652. ((Entity*)target)->AddProc(type, chance, item, spell);
  6653. }
  6654. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6655. }
  6656. else
  6657. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6658. return 0;
  6659. }
  6660. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6661. if (!lua_interface)
  6662. return 0;
  6663. Spawn* spawn = lua_interface->GetSpawn(state);
  6664. Item* item = lua_interface->GetItem(state, 2);
  6665. LuaSpell* spell = 0;
  6666. if (!spawn) {
  6667. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (!spawn->IsEntity()) {
  6671. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. if (!item)
  6675. spell = lua_interface->GetCurrentSpell(state);
  6676. if (!item && !spell) {
  6677. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6678. return 0;
  6679. }
  6680. if (spell) {
  6681. Spawn* target;
  6682. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6683. for (int8 i = 0; i < spell->targets.size(); i++) {
  6684. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6685. if (!target || !target->IsEntity())
  6686. continue;
  6687. ((Entity*)target)->RemoveProc(item, spell);
  6688. }
  6689. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6690. spell->caster->RemoveProc(item, spell);
  6691. }
  6692. else
  6693. ((Entity*)spawn)->RemoveProc(item, spell);
  6694. return 0;
  6695. }
  6696. int EQ2Emu_lua_Knockback(lua_State* state) {
  6697. if (!lua_interface)
  6698. return 0;
  6699. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6700. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6701. int32 duration = lua_interface->GetInt32Value(state, 3);
  6702. float vertical = lua_interface->GetFloatValue(state, 4);
  6703. float horizontal = lua_interface->GetFloatValue(state, 5);
  6704. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6705. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6706. if (!target_spawn) {
  6707. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. if (!spawn) {
  6711. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6712. return 0;
  6713. }
  6714. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6715. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6716. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6717. if (packet) {
  6718. packet->setDataByName("target_x", target_spawn->GetX());
  6719. packet->setDataByName("target_y", target_spawn->GetY());
  6720. packet->setDataByName("target_z", target_spawn->GetZ());
  6721. packet->setDataByName("vertical_movement", vertical);
  6722. packet->setDataByName("horizontal_movement", horizontal);
  6723. if (use_heading)
  6724. packet->setDataByName("use_player_heading", 1);
  6725. client->QueuePacket(packet->serialize());
  6726. }
  6727. safe_delete(packet);
  6728. }
  6729. return 0;
  6730. }
  6731. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6732. if (!lua_interface)
  6733. return 0;
  6734. Spawn* spawn = lua_interface->GetSpawn(state);
  6735. if (!spawn) {
  6736. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6740. return 1;
  6741. }
  6742. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6743. if (!lua_interface)
  6744. return 0;
  6745. Spawn* caster = lua_interface->GetSpawn(state);
  6746. Spawn* target = lua_interface->GetSpawn(state, 2);
  6747. string name = lua_interface->GetStringValue(state, 3);
  6748. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6749. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6750. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6751. string success_msg = lua_interface->GetStringValue(state, 7);
  6752. string effect_msg = lua_interface->GetStringValue(state, 8);
  6753. if (!caster) {
  6754. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. if (!caster->IsEntity()) {
  6758. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6759. return 0;
  6760. }
  6761. if (!target) {
  6762. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. if (!target->IsEntity()) {
  6766. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. if (name.length() == 0) {
  6770. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6774. return 0;
  6775. }
  6776. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6777. if (!lua_interface)
  6778. return 0;
  6779. string name = lua_interface->GetStringValue(state);
  6780. if (name.length() == 0) {
  6781. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6782. return 0;
  6783. }
  6784. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6785. if (!skill) {
  6786. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6787. return 0;
  6788. }
  6789. lua_interface->SetInt32Value(state, skill->skill_id);
  6790. return 1;
  6791. }
  6792. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6793. if (!lua_interface)
  6794. return 0;
  6795. Spawn* spawn = lua_interface->GetSpawn(state);
  6796. if (!spawn) {
  6797. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6798. return 0;
  6799. }
  6800. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6801. return 1;
  6802. }
  6803. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6804. if (!lua_interface)
  6805. return 0;
  6806. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6807. if (!luaspell) {
  6808. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6809. return 0;
  6810. }
  6811. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6812. return 1;
  6813. }
  6814. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6815. if (!lua_interface)
  6816. return 0;
  6817. Spawn* spawn = lua_interface->GetSpawn(state);
  6818. Spawn* target = lua_interface->GetSpawn(state, 2);
  6819. if (!spawn) {
  6820. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6821. return 0;
  6822. }
  6823. if (!spawn->IsEntity()) {
  6824. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. if (!target) {
  6828. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6832. return 1;
  6833. }
  6834. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6835. if (!lua_interface)
  6836. return 0;
  6837. Spawn* spawn = lua_interface->GetSpawn(state);
  6838. Spawn* target = lua_interface->GetSpawn(state, 2);
  6839. if (!spawn) {
  6840. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6841. return 0;
  6842. }
  6843. if (!spawn->IsEntity()) {
  6844. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. if (!target) {
  6848. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6852. return 1;
  6853. }
  6854. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6855. if (!lua_interface)
  6856. return 0;
  6857. Item* item = lua_interface->GetItem(state);
  6858. if (!item) {
  6859. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6860. return 0;
  6861. }
  6862. lua_interface->SetInt32Value(state, item->details.count);
  6863. return 1;
  6864. }
  6865. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6866. if (!lua_interface)
  6867. return 0;
  6868. Item* item = lua_interface->GetItem(state);
  6869. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6870. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6871. if (!item) {
  6872. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6873. return 0;
  6874. }
  6875. if (!owner) {
  6876. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6877. return 0;
  6878. }
  6879. if (!owner->IsPlayer()) {
  6880. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6881. return 0;
  6882. }
  6883. if (item->stack_count < new_count) {
  6884. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6885. return 0;
  6886. }
  6887. if (new_count > 0) {
  6888. item->details.count = new_count;
  6889. item->save_needed = true;
  6890. }
  6891. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6892. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6893. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6894. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6895. else
  6896. {
  6897. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6898. return 0;
  6899. }
  6900. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6901. if (!client)
  6902. return 0;
  6903. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6904. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6905. if (app)
  6906. client->QueuePacket(app);
  6907. return 0;
  6908. }
  6909. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6910. if (!lua_interface)
  6911. return 0;
  6912. int32 time = lua_interface->GetInt32Value(state);
  6913. string function = lua_interface->GetStringValue(state, 2);
  6914. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6915. Spawn* target = lua_interface->GetSpawn(state, 4);
  6916. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6917. if (time == 0) {
  6918. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6919. return 0;
  6920. }
  6921. if (function.length() == 0) {
  6922. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6923. return 0;
  6924. }
  6925. if (!spell) {
  6926. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6927. return 0;
  6928. }
  6929. SpellScriptTimer* timer = new SpellScriptTimer;
  6930. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6931. #ifdef WIN32
  6932. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6933. #else
  6934. bzero(timer, sizeof(SpellScriptTimer));
  6935. #endif*/
  6936. timer->caster = 0;
  6937. timer->deleteWhenDone = false;
  6938. timer->target = 0;
  6939. timer->time = Timer::GetCurrentTime2() + time;
  6940. timer->customFunction = function;
  6941. timer->spell = spell;
  6942. if (caster)
  6943. timer->caster = caster->GetID();
  6944. if (target)
  6945. timer->target = target->GetID();
  6946. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6947. return 0;
  6948. }
  6949. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6950. if (!lua_interface)
  6951. return 0;
  6952. float hp_perc = lua_interface->GetFloatValue(state);
  6953. float power_perc = lua_interface->GetFloatValue(state, 2);
  6954. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6955. Spawn* target = lua_interface->GetSpawn(state, 4);
  6956. string heal_name = lua_interface->GetStringValue(state, 5);
  6957. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6958. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6959. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6960. if (!spell) {
  6961. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6962. return 0;
  6963. }
  6964. Entity* caster = spell->caster;
  6965. if (!caster) {
  6966. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6967. return 0;
  6968. }
  6969. Client* client = 0;
  6970. PendingResurrection* rez = 0;
  6971. ZoneServer* zone = spell->caster->GetZone();
  6972. if (!target) {
  6973. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6974. if (spell->targets.size() > 0) {
  6975. vector<int32> spell_targets = spell->targets;
  6976. for (int8 i = 0; i < spell_targets.size(); i++) {
  6977. target = zone->GetSpawnByID(spell_targets.at(i));
  6978. if (!target)
  6979. continue;
  6980. if (!target->IsPlayer())
  6981. continue;
  6982. client = target->GetZone()->GetClientBySpawn(target);
  6983. if (!client)
  6984. continue;
  6985. rez = client->GetCurrentRez();
  6986. if (rez->active)
  6987. continue;
  6988. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6989. rez->active = true;
  6990. rez->caster = caster;
  6991. rez->expire_timer = new Timer;
  6992. int32 duration = spell->spell->GetSpellDuration();
  6993. rez->expire_timer->Start(duration * 100);
  6994. rez->hp_perc = hp_perc;
  6995. rez->mp_perc = power_perc;
  6996. rez->range = spell->spell->GetSpellData()->range;
  6997. rez->spell_name = spell->spell->GetName();
  6998. if (heal_name.length() > 0)
  6999. rez->heal_name = heal_name;
  7000. else
  7001. rez->heal_name = rez->spell_name;
  7002. rez->no_calcs = no_calcs;
  7003. rez->crit_mod = crit_mod;
  7004. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7005. if (send_window)
  7006. client->SendResurrectionWindow();
  7007. else {
  7008. target->GetZone()->ResurrectSpawn(target, client);
  7009. rez->should_delete = true;
  7010. }
  7011. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7012. }
  7013. }
  7014. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7015. }
  7016. else {
  7017. client = target->GetZone()->GetClientBySpawn(target);
  7018. if (!client)
  7019. return 0;
  7020. rez = client->GetCurrentRez();
  7021. if (rez->active)
  7022. return 0;
  7023. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7024. rez->active = true;
  7025. rez->caster = caster;
  7026. rez->expire_timer = new Timer;
  7027. int32 duration = spell->spell->GetSpellDuration();
  7028. rez->expire_timer->Start(duration * 100);
  7029. rez->hp_perc = hp_perc;
  7030. rez->mp_perc = power_perc;
  7031. rez->range = spell->spell->GetSpellData()->range;
  7032. rez->spell_name = spell->spell->GetName();
  7033. if (heal_name.length() > 0)
  7034. rez->heal_name = heal_name;
  7035. else
  7036. rez->heal_name = rez->spell_name;
  7037. rez->no_calcs = no_calcs;
  7038. rez->crit_mod = crit_mod;
  7039. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7040. if (send_window)
  7041. client->SendResurrectionWindow();
  7042. else {
  7043. target->GetZone()->ResurrectSpawn(target, client);
  7044. rez->should_delete = true;
  7045. }
  7046. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7047. }
  7048. return 0;
  7049. }
  7050. int EQ2Emu_lua_SetVision(lua_State* state) {
  7051. if (!lua_interface)
  7052. return 0;
  7053. Spawn* spawn = lua_interface->GetSpawn(state);
  7054. int8 vision = lua_interface->GetInt8Value(state, 2);
  7055. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7056. if (!spawn) {
  7057. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7058. return 0;
  7059. }
  7060. if (!spawn->IsEntity()) {
  7061. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7062. return 0;
  7063. }
  7064. if (spell && spell->targets.size() > 0) {
  7065. ZoneServer* zone = spell->caster->GetZone();
  7066. for (int8 i = 0; i < spell->targets.size(); i++) {
  7067. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7068. if (target->IsEntity()) {
  7069. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7070. if (target->IsPlayer())
  7071. ((Player*)target)->SetCharSheetChanged(true);
  7072. }
  7073. }
  7074. }
  7075. else {
  7076. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7077. if (spawn->IsPlayer())
  7078. ((Player*)spawn)->SetCharSheetChanged(true);
  7079. }
  7080. return 0;
  7081. }
  7082. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7083. if (!lua_interface)
  7084. return 0;
  7085. Spawn* spawn = lua_interface->GetSpawn(state);
  7086. float intensity = lua_interface->GetFloatValue(state, 2);
  7087. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7088. if (!spawn) {
  7089. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7090. return 0;
  7091. }
  7092. if (!spawn->IsEntity()) {
  7093. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7094. return 0;
  7095. }
  7096. if (spell && spell->targets.size() > 0) {
  7097. ZoneServer* zone = spell->caster->GetZone();
  7098. for (int8 i = 0; i < spell->targets.size(); i++) {
  7099. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7100. if (target && target->IsEntity()) {
  7101. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7102. if (target->IsPlayer())
  7103. ((Player*)target)->SetCharSheetChanged(true);
  7104. }
  7105. }
  7106. }
  7107. else {
  7108. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7109. if (spawn->IsPlayer())
  7110. ((Player*)spawn)->SetCharSheetChanged(true);
  7111. }
  7112. return 0;
  7113. }
  7114. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7115. if (!lua_interface)
  7116. return 0;
  7117. Spawn* spawn = lua_interface->GetSpawn(state);
  7118. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7119. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7120. if (!spawn) {
  7121. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (!spawn->IsEntity()) {
  7125. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. if (spell && spell->targets.size() > 0) {
  7129. ZoneServer* zone = spell->caster->GetZone();
  7130. for (int8 i = 0; i < spell->targets.size(); i++) {
  7131. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7132. if (target->IsEntity()) {
  7133. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7134. if (target->IsPlayer())
  7135. ((Player*)target)->SetCharSheetChanged(true);
  7136. }
  7137. }
  7138. }
  7139. else {
  7140. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7141. if (spawn->IsPlayer())
  7142. ((Player*)spawn)->SetCharSheetChanged(true);
  7143. }
  7144. return 0;
  7145. }
  7146. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7147. if (!lua_interface)
  7148. return 0;
  7149. Item* item = lua_interface->GetItem(state);
  7150. int8 type = lua_interface->GetInt32Value(state, 2);
  7151. if (!item) {
  7152. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if (type == 1)
  7156. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7157. else if (type == 2)
  7158. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7159. return 1;
  7160. }
  7161. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7162. if (!lua_interface)
  7163. return 0;
  7164. Spawn* target = lua_interface->GetSpawn(state);
  7165. float val = lua_interface->GetFloatValue(state, 2);
  7166. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7167. // Added from Gangrenous post
  7168. if (spell && spell->resisted)
  7169. return 0;
  7170. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7171. if (val > 1.0f)
  7172. val = 1.0f - (val / 100.0f);
  7173. if (spell && spell->spell && spell->targets.size() > 0) {
  7174. ZoneServer* zone = spell->caster->GetZone();
  7175. for (int32 i = 0; i != spell->targets.size(); i++) {
  7176. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7177. if (spawn && spawn->IsEntity()) {
  7178. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7179. if (spawn->IsPlayer())
  7180. ((Player*)spawn)->SetCharSheetChanged(true);
  7181. }
  7182. }
  7183. }
  7184. else {
  7185. if (target && target->IsEntity()) {
  7186. ((Entity*)target)->SetSpeedMultiplier(val);
  7187. if (target->IsPlayer())
  7188. ((Player*)target)->SetCharSheetChanged(true);
  7189. }
  7190. }
  7191. return 0;
  7192. }
  7193. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7194. if (!lua_interface)
  7195. return 0;
  7196. Spawn* spawn = lua_interface->GetSpawn(state);
  7197. int16 model = lua_interface->GetInt16Value(state, 2);
  7198. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7199. if (spell && spell->spell && spell->targets.size() > 0) {
  7200. ZoneServer* zone = spell->caster->GetZone();
  7201. for (int32 i = 0; i < spell->targets.size(); i++) {
  7202. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7203. if (target)
  7204. target->SetIllusionModel(model);
  7205. }
  7206. }
  7207. else {
  7208. if (!spawn) {
  7209. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7210. return 0;
  7211. }
  7212. spawn->SetIllusionModel(model);
  7213. }
  7214. return 0;
  7215. }
  7216. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7217. if (!lua_interface)
  7218. return 0;
  7219. Spawn* spawn = lua_interface->GetSpawn(state);
  7220. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7221. if (spell && spell->spell && spell->targets.size() > 0) {
  7222. ZoneServer* zone = spell->caster->GetZone();
  7223. for (int32 i = 0; i < spell->targets.size(); i++) {
  7224. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7225. if (target)
  7226. target->SetIllusionModel(0);
  7227. }
  7228. }
  7229. else {
  7230. if (!spawn) {
  7231. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7232. return 0;
  7233. }
  7234. spawn->SetIllusionModel(0);
  7235. }
  7236. return 0;
  7237. }
  7238. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7239. if (!lua_interface)
  7240. return 0;
  7241. Spawn* caster = lua_interface->GetSpawn(state);
  7242. Spawn* target = lua_interface->GetSpawn(state, 2);
  7243. float chance = lua_interface->GetFloatValue(state, 3);
  7244. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7245. if (!caster) {
  7246. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. if (!caster->IsEntity()) {
  7250. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!target) {
  7254. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (!target->IsEntity()) {
  7258. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. if (chance <= 0) {
  7262. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. if (!spell) {
  7266. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7267. return 0;
  7268. }
  7269. if (((Entity*)caster)->GetThreatTransfer()) {
  7270. return 0;
  7271. }
  7272. ThreatTransfer* transfer = new ThreatTransfer;
  7273. transfer->Target = target->GetID();
  7274. transfer->Amount = chance;
  7275. transfer->Spell = spell;
  7276. ((Entity*)caster)->SetThreatTransfer(transfer);
  7277. return 0;
  7278. }
  7279. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7280. if (!lua_interface)
  7281. return 0;
  7282. Spawn* spawn = lua_interface->GetSpawn(state);
  7283. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7284. if (!spawn) {
  7285. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7286. return 0;
  7287. }
  7288. if (!spell) {
  7289. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7290. return 0;
  7291. }
  7292. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7293. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7294. ((Entity*)spawn)->SetThreatTransfer(0);
  7295. safe_delete(transfer);
  7296. }
  7297. return 0;
  7298. }
  7299. int EQ2Emu_lua_CureByType(lua_State* state) {
  7300. if (!lua_interface)
  7301. return 0;
  7302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7303. if (!spell) {
  7304. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7305. return 0;
  7306. }
  7307. int8 cure_count = lua_interface->GetInt8Value(state);
  7308. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7309. string cure_name = lua_interface->GetStringValue(state, 3);
  7310. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7311. Spawn* target = lua_interface->GetSpawn(state, 5);
  7312. if (target) {
  7313. if (!target->IsEntity()) {
  7314. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7318. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7319. }
  7320. else {
  7321. ZoneServer* zone = spell->caster->GetZone();
  7322. vector<int32> targets = spell->targets;
  7323. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7324. for (int8 i = 0; i < targets.size(); i++) {
  7325. target = zone->GetSpawnByID(targets.at(i));
  7326. if (!target || !target->IsEntity())
  7327. continue;
  7328. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7329. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7330. }
  7331. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7332. }
  7333. return 0;
  7334. }
  7335. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7336. if (!lua_interface)
  7337. return 0;
  7338. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7339. if (!spell) {
  7340. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7341. return 0;
  7342. }
  7343. int8 cure_count = lua_interface->GetInt8Value(state);
  7344. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7345. string cure_name = lua_interface->GetStringValue(state, 3);
  7346. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7347. Spawn* target = lua_interface->GetSpawn(state, 5);
  7348. if (target) {
  7349. if (!target->IsEntity()) {
  7350. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7351. return 0;
  7352. }
  7353. if (((Entity*)target)->GetDetCount() > 0)
  7354. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7355. }
  7356. else {
  7357. ZoneServer* zone = spell->caster->GetZone();
  7358. vector<int32> targets = spell->targets;
  7359. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7360. for (int8 i = 0; i < targets.size(); i++) {
  7361. target = zone->GetSpawnByID(targets.at(i));
  7362. if (!target || !target->IsEntity())
  7363. continue;
  7364. if (((Entity*)target)->GetDetCount() > 0)
  7365. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7366. }
  7367. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7368. }
  7369. return 0;
  7370. }
  7371. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7372. if (!lua_interface)
  7373. return 0;
  7374. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7375. if (!spell) {
  7376. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7377. return 0;
  7378. }
  7379. if (!spell->caster) {
  7380. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7381. return 0;
  7382. }
  7383. if (!spell->caster->GetZone()) {
  7384. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7385. return 0;
  7386. }
  7387. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7388. return 0;
  7389. }
  7390. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7391. if (!lua_interface)
  7392. return 0;
  7393. Spawn* spawn = lua_interface->GetSpawn(state);
  7394. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7395. if (!spell) {
  7396. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7397. return 0;
  7398. }
  7399. if (spawn && spawn->IsEntity())
  7400. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7401. else {
  7402. ZoneServer* zone = spell->caster->GetZone();
  7403. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7404. for (int32 i = 0; i < spell->targets.size(); i++) {
  7405. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7406. if (!spawn || !spawn->IsEntity())
  7407. continue;
  7408. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7409. }
  7410. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7411. }
  7412. return 0;
  7413. }
  7414. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7415. if (!lua_interface)
  7416. return 0;
  7417. Spawn* spawn = lua_interface->GetSpawn(state);
  7418. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7419. if (!spell) {
  7420. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7421. return 0;
  7422. }
  7423. if (spawn && spawn->IsEntity())
  7424. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7425. else {
  7426. ZoneServer* zone = spell->caster->GetZone();
  7427. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7428. for (int32 i = 0; i < spell->targets.size(); i++) {
  7429. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7430. if (!spawn || !spawn->IsEntity())
  7431. continue;
  7432. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7433. }
  7434. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7435. }
  7436. return 0;
  7437. }
  7438. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7439. if (!lua_interface)
  7440. return 0;
  7441. Spawn* caster = lua_interface->GetSpawn(state);
  7442. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7443. if (!caster) {
  7444. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. if (!caster->IsPlayer()) {
  7448. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7449. return 0;
  7450. }
  7451. Spawn* target = caster->GetTarget();
  7452. if (!target) {
  7453. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7454. return 0;
  7455. }
  7456. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7457. if (!client) {
  7458. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7459. return 0;
  7460. }
  7461. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7462. if (ho) {
  7463. ho->SetTarget(target->GetID());
  7464. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7465. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7466. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7467. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7468. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7469. deque<GroupMemberInfo*>::iterator itr;
  7470. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7471. if (group)
  7472. {
  7473. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7474. deque<GroupMemberInfo*>* members = group->GetMembers();
  7475. for (itr = members->begin(); itr != members->end(); itr++) {
  7476. if ((*itr)->client)
  7477. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7478. }
  7479. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7480. }
  7481. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7482. }
  7483. else
  7484. safe_delete(ho);
  7485. }
  7486. else {
  7487. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7488. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7489. }
  7490. else
  7491. safe_delete(ho);
  7492. }
  7493. }
  7494. return 0;
  7495. }
  7496. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7497. if (!lua_interface)
  7498. return 0;
  7499. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7500. if (!spell) {
  7501. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7502. return 0;
  7503. }
  7504. int16 triggerCount = lua_interface->GetInt16Value(state);
  7505. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7506. if (!triggerCount) {
  7507. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7508. return 0;
  7509. }
  7510. spell->num_triggers = triggerCount;
  7511. spell->had_triggers = true;
  7512. spell->cancel_after_all_triggers = cancel_after_triggers;
  7513. return 0;
  7514. }
  7515. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7519. if (!spell) {
  7520. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7521. return 0;
  7522. }
  7523. lua_interface->SetInt32Value(state, spell->num_triggers);
  7524. return 1;
  7525. }
  7526. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7527. if (!lua_interface)
  7528. return 0;
  7529. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7530. if (!spell) {
  7531. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7532. return 0;
  7533. }
  7534. int16 remove_count = lua_interface->GetInt16Value(state);
  7535. if (!remove_count)
  7536. remove_count = 1;
  7537. if (remove_count >= spell->num_triggers) {
  7538. spell->num_triggers = 0;
  7539. if (spell->cancel_after_all_triggers)
  7540. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7541. }
  7542. else {
  7543. spell->num_triggers -= remove_count;
  7544. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7545. }
  7546. return 0;
  7547. }
  7548. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7549. if (!lua_interface)
  7550. return 0;
  7551. Spawn* spawn = lua_interface->GetSpawn(state);
  7552. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7553. if (!spawn) {
  7554. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. if (!copy_spawn) {
  7558. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7559. return 0;
  7560. }
  7561. spawn->CopySpawnAppearance(copy_spawn);
  7562. return 0;
  7563. }
  7564. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7565. if (!lua_interface)
  7566. return 0;
  7567. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7568. int8 type = lua_interface->GetInt8Value(state);
  7569. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7570. if (!spell) {
  7571. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7572. return 0;
  7573. }
  7574. if (spawn) {
  7575. if (!spawn->IsEntity()) {
  7576. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7577. return 0;
  7578. }
  7579. Entity* entity = ((Entity*)spawn);
  7580. switch (type) {
  7581. case IMMUNITY_TYPE_AOE:
  7582. entity->AddAOEImmunity(spell);
  7583. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7584. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7585. break;
  7586. case IMMUNITY_TYPE_STUN:
  7587. entity->AddStunImmunity(spell);
  7588. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7589. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7590. break;
  7591. case IMMUNITY_TYPE_ROOT:
  7592. entity->AddRootImmunity(spell);
  7593. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7594. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7595. break;
  7596. case IMMUNITY_TYPE_DAZE:
  7597. entity->AddDazeImmunity(spell);
  7598. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7599. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7600. break;
  7601. case IMMUNITY_TYPE_FEAR:
  7602. entity->AddFearImmunity(spell);
  7603. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7604. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7605. break;
  7606. case IMMUNITY_TYPE_MEZ:
  7607. entity->AddMezImmunity(spell);
  7608. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7609. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7610. break;
  7611. case IMMUNITY_TYPE_STIFLE:
  7612. entity->AddStifleImmunity(spell);
  7613. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7614. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7615. break;
  7616. default:
  7617. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7618. }
  7619. }
  7620. else {
  7621. bool should_break = false;
  7622. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7623. for (int8 i = 0; i < spell->targets.size(); i++) {
  7624. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7625. if (!spawn || !spawn->IsEntity())
  7626. continue;
  7627. Entity* entity = ((Entity*)spawn);
  7628. switch (type) {
  7629. case IMMUNITY_TYPE_AOE:
  7630. entity->AddAOEImmunity(spell);
  7631. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7632. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7633. break;
  7634. case IMMUNITY_TYPE_STUN:
  7635. entity->AddStunImmunity(spell);
  7636. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7637. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7638. break;
  7639. case IMMUNITY_TYPE_ROOT:
  7640. entity->AddRootImmunity(spell);
  7641. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7642. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7643. break;
  7644. case IMMUNITY_TYPE_DAZE:
  7645. entity->AddDazeImmunity(spell);
  7646. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7647. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7648. break;
  7649. case IMMUNITY_TYPE_FEAR:
  7650. entity->AddFearImmunity(spell);
  7651. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7652. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7653. break;
  7654. case IMMUNITY_TYPE_MEZ:
  7655. entity->AddMezImmunity(spell);
  7656. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7657. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7658. break;
  7659. case IMMUNITY_TYPE_STIFLE:
  7660. entity->AddStifleImmunity(spell);
  7661. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7662. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7663. break;
  7664. default:
  7665. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7666. should_break = true;
  7667. }
  7668. if (should_break)
  7669. break;
  7670. }
  7671. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7672. }
  7673. return 0;
  7674. }
  7675. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7676. if (!lua_interface)
  7677. return 0;
  7678. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7679. int8 type = lua_interface->GetInt8Value(state);
  7680. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7681. if (!spell) {
  7682. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7683. return 0;
  7684. }
  7685. if (spawn) {
  7686. if (!spawn->IsEntity()) {
  7687. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7688. return 0;
  7689. }
  7690. Entity* entity = ((Entity*)spawn);
  7691. switch (type) {
  7692. case IMMUNITY_TYPE_AOE:
  7693. entity->RemoveAOEImmunity(spell);
  7694. break;
  7695. case IMMUNITY_TYPE_STUN:
  7696. entity->RemoveStunImmunity(spell);
  7697. break;
  7698. case IMMUNITY_TYPE_ROOT:
  7699. entity->RemoveRootImmunity(spell);
  7700. break;
  7701. case IMMUNITY_TYPE_DAZE:
  7702. entity->RemoveDazeImmunity(spell);
  7703. break;
  7704. case IMMUNITY_TYPE_FEAR:
  7705. entity->RemoveFearImmunity(spell);
  7706. break;
  7707. case IMMUNITY_TYPE_MEZ:
  7708. entity->RemoveMezImmunity(spell);
  7709. break;
  7710. case IMMUNITY_TYPE_STIFLE:
  7711. entity->RemoveStifleImmunity(spell);
  7712. break;
  7713. default:
  7714. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7715. }
  7716. }
  7717. else {
  7718. bool should_break = false;
  7719. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7720. for (int8 i = 0; i < spell->targets.size(); i++) {
  7721. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7722. if (!spawn || !spawn->IsEntity())
  7723. continue;
  7724. Entity* entity = ((Entity*)spawn);
  7725. switch (type) {
  7726. case IMMUNITY_TYPE_AOE:
  7727. entity->RemoveAOEImmunity(spell);
  7728. break;
  7729. case IMMUNITY_TYPE_STUN:
  7730. entity->RemoveStunImmunity(spell);
  7731. break;
  7732. case IMMUNITY_TYPE_ROOT:
  7733. entity->RemoveRootImmunity(spell);
  7734. break;
  7735. case IMMUNITY_TYPE_DAZE:
  7736. entity->RemoveDazeImmunity(spell);
  7737. break;
  7738. case IMMUNITY_TYPE_FEAR:
  7739. entity->RemoveFearImmunity(spell);
  7740. break;
  7741. case IMMUNITY_TYPE_MEZ:
  7742. entity->RemoveMezImmunity(spell);
  7743. break;
  7744. case IMMUNITY_TYPE_STIFLE:
  7745. entity->RemoveStifleImmunity(spell);
  7746. break;
  7747. default:
  7748. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7749. should_break = true;
  7750. }
  7751. if (should_break)
  7752. break;
  7753. }
  7754. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7755. }
  7756. return 0;
  7757. }
  7758. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7759. if (!lua_interface)
  7760. return 0;
  7761. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7762. if (!spell) {
  7763. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7764. return 0;
  7765. }
  7766. float snare = lua_interface->GetFloatValue(state);
  7767. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7768. // convert the val to the speed multipler value (100 - val)
  7769. float val = 100.0 - snare;
  7770. val /= 100.0;
  7771. if (spawn) {
  7772. if (!spawn->IsEntity()) {
  7773. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7774. return 0;
  7775. }
  7776. ((Entity*)spawn)->SetSnareValue(spell, val);
  7777. }
  7778. else {
  7779. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7780. for (int8 i = 0; i < spell->targets.size(); i++) {
  7781. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7782. if (!spawn || !spawn->IsEntity())
  7783. continue;
  7784. ((Entity*)spawn)->SetSnareValue(spell, val);
  7785. }
  7786. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7787. }
  7788. return 0;
  7789. }
  7790. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7791. if (!lua_interface)
  7792. return 0;
  7793. Spawn* spawn = lua_interface->GetSpawn(state);
  7794. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7795. if (!spawn) {
  7796. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. if (race_id == 0) {
  7800. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7801. return 0;
  7802. }
  7803. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7804. return 1;
  7805. }
  7806. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7807. if (!lua_interface)
  7808. return 0;
  7809. Spawn* spawn = lua_interface->GetSpawn(state);
  7810. if (!spawn) {
  7811. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7812. return 0;
  7813. }
  7814. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7815. return 1;
  7816. }
  7817. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7818. if (!lua_interface)
  7819. return 0;
  7820. Spawn* spawn = lua_interface->GetSpawn(state);
  7821. if (!spawn) {
  7822. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7826. return 1;
  7827. }
  7828. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7829. if (!lua_interface)
  7830. return 0;
  7831. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7832. if (!spell) {
  7833. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7834. return 0;
  7835. }
  7836. lua_interface->SetStringValue(state, spell->spell->GetName());
  7837. return 1;
  7838. }
  7839. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7840. if (!lua_interface)
  7841. return 0;
  7842. Quest* quest = lua_interface->GetQuest(state);
  7843. if (!quest) {
  7844. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7845. return 0;
  7846. }
  7847. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7848. return 1;
  7849. }
  7850. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7851. if (!lua_interface)
  7852. return 0;
  7853. Quest* quest = lua_interface->GetQuest(state);
  7854. int32 flags = lua_interface->GetInt32Value(state, 2);
  7855. if (!quest) {
  7856. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7857. return 0;
  7858. }
  7859. quest->SetQuestFlags(flags);
  7860. return 0;
  7861. }
  7862. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7863. if (!lua_interface)
  7864. return 0;
  7865. Quest* quest = lua_interface->GetQuest(state);
  7866. Spawn* player = lua_interface->GetSpawn(state, 2);
  7867. int32 step = lua_interface->GetInt32Value(state, 3);
  7868. int32 duration = lua_interface->GetInt32Value(state, 4);
  7869. string action = lua_interface->GetStringValue(state, 5);
  7870. if (!quest) {
  7871. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7872. return 0;
  7873. }
  7874. if (!player) {
  7875. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. if (!player->IsPlayer()) {
  7879. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. if (step == 0) {
  7883. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. if (duration == 0) {
  7887. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. if (action.length() == 0) {
  7891. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7892. return 0;
  7893. }
  7894. Client* client = player->GetZone()->GetClientBySpawn(player);
  7895. if (!client) {
  7896. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. quest->SetTimerStep(step);
  7900. quest->AddFailedAction(step, action);
  7901. quest->SetStepTimer(duration);
  7902. client->AddQuestTimer(quest->GetQuestID());
  7903. return 0;
  7904. }
  7905. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7906. if (!lua_interface)
  7907. return 0;
  7908. Quest* quest = lua_interface->GetQuest(state);
  7909. Spawn* player = lua_interface->GetSpawn(state, 2);
  7910. if (!quest) {
  7911. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7912. return 0;
  7913. }
  7914. if (!player) {
  7915. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7916. return 0;
  7917. }
  7918. if (!player->IsPlayer()) {
  7919. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7920. return 0;
  7921. }
  7922. Client* client = player->GetZone()->GetClientBySpawn(player);
  7923. if (!client) {
  7924. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7925. return 0;
  7926. }
  7927. quest->SetTimerStep(0);
  7928. quest->SetStepTimer(0);
  7929. client->RemoveQuestTimer(quest->GetQuestID());
  7930. return 0;
  7931. }
  7932. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7933. if (!lua_interface)
  7934. return 0;
  7935. Spawn* player = lua_interface->GetSpawn(state);
  7936. Quest* quest = lua_interface->GetQuest(state, 2);
  7937. int32 step = lua_interface->GetInt32Value(state, 3);
  7938. if (!player) {
  7939. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. if (!player->IsPlayer()) {
  7943. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. if (!quest) {
  7947. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7948. return 0;
  7949. }
  7950. if (step == 0) {
  7951. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7952. return 0;
  7953. }
  7954. Client* client = player->GetZone()->GetClientBySpawn(player);
  7955. if (!client) {
  7956. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. if (quest->RemoveQuestStep(step, client)) {
  7960. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7961. client->GetCurrentZone()->SendQuestUpdates(client);
  7962. }
  7963. else
  7964. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7965. return 0;
  7966. }
  7967. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7968. if (!lua_interface)
  7969. return 0;
  7970. Quest* quest = lua_interface->GetQuest(state, 1);
  7971. int32 step = lua_interface->GetInt32Value(state, 2);
  7972. string desc = lua_interface->GetStringValue(state, 3);
  7973. string task_group = lua_interface->GetStringValue(state, 4);
  7974. if (!quest) {
  7975. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7976. return 0;
  7977. }
  7978. if (step == 0) {
  7979. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7980. return 0;
  7981. }
  7982. QuestStep* quest_step = quest->GetQuestStep(step);
  7983. if (!quest_step) {
  7984. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7985. return 0;
  7986. }
  7987. quest_step->SetStepProgress(0);
  7988. quest_step->SetTaskGroup(task_group);
  7989. quest_step->SetDescription(desc);
  7990. return 0;
  7991. }
  7992. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7993. if (!lua_interface)
  7994. return 0;
  7995. Quest* quest = lua_interface->GetQuest(state);
  7996. int32 step = lua_interface->GetInt32Value(state, 2);
  7997. string action = lua_interface->GetStringValue(state, 3);
  7998. if (!quest) {
  7999. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8000. return 0;
  8001. }
  8002. if (step == 0) {
  8003. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8004. return 0;
  8005. }
  8006. if (action.length() == 0) {
  8007. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8008. return 0;
  8009. }
  8010. quest->AddFailedAction(step, action);
  8011. return 0;
  8012. }
  8013. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8014. if (!lua_interface)
  8015. return 0;
  8016. Spawn* player = lua_interface->GetSpawn(state);
  8017. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8018. int32 step = lua_interface->GetInt32Value(state, 3);
  8019. if (!player) {
  8020. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. if (!player->IsPlayer()) {
  8024. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (quest_id == 0) {
  8028. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. if (step == 0) {
  8032. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8033. return 0;
  8034. }
  8035. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8036. if (!quest) {
  8037. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8038. return 0;
  8039. }
  8040. quest->StepFailed(step);
  8041. return 0;
  8042. }
  8043. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8044. if (!lua_interface)
  8045. return 0;
  8046. Spawn* player = lua_interface->GetSpawn(state);
  8047. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8048. if (!player) {
  8049. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. if (!player->IsPlayer()) {
  8053. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8054. return 0;
  8055. }
  8056. if (quest_id == 0) {
  8057. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8058. return 0;
  8059. }
  8060. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8061. if (!quest) {
  8062. lua_interface->SetInt32Value(state, 0);
  8063. return 1;
  8064. }
  8065. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8066. return 1;
  8067. }
  8068. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8069. if (!lua_interface)
  8070. return 0;
  8071. string name = lua_interface->GetStringValue(state);
  8072. string value = lua_interface->GetStringValue(state, 2);
  8073. string comment = lua_interface->GetStringValue(state, 3);
  8074. if (name.length() == 0) {
  8075. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. if (value.length() == 0) {
  8079. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8080. return 0;
  8081. }
  8082. string varname = string("lua_").append(name);
  8083. Variable* var = variables.FindVariable(varname);
  8084. if (var)
  8085. var->SetValue(value.c_str());
  8086. else {
  8087. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8088. variables.AddVariable(var);
  8089. }
  8090. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8091. return 0;
  8092. }
  8093. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8094. if (!lua_interface)
  8095. return 0;
  8096. string name = lua_interface->GetStringValue(state);
  8097. if (name.length() == 0) {
  8098. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8099. return 0;
  8100. }
  8101. string varname = string("lua_").append(name);
  8102. Variable* var = variables.FindVariable(varname);
  8103. if (var)
  8104. lua_interface->SetStringValue(state, var->GetValue());
  8105. else
  8106. lua_interface->SetStringValue(state, "NULL");
  8107. return 1;
  8108. }
  8109. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8110. if (!lua_interface)
  8111. return 0;
  8112. Spawn* player = lua_interface->GetSpawn(state);
  8113. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8114. if (!player) {
  8115. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. if (!player->IsPlayer()) {
  8119. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8120. return 0;
  8121. }
  8122. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8123. return 1;
  8124. }
  8125. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8126. if (!lua_interface)
  8127. return 0;
  8128. Spawn* player = lua_interface->GetSpawn(state);
  8129. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8130. if (!player) {
  8131. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. if (!player->IsPlayer()) {
  8135. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8136. return 0;
  8137. }
  8138. Language* language = master_languages_list.GetLanguage(language_id);
  8139. if (language)
  8140. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8141. return 0;
  8142. }
  8143. int EQ2Emu_lua_IsNight(lua_State* state) {
  8144. if (!lua_interface)
  8145. return 0;
  8146. ZoneServer* zone = lua_interface->GetZone(state);
  8147. if (!zone) {
  8148. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8149. return 0;
  8150. }
  8151. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8152. return 1;
  8153. }
  8154. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8155. if (!lua_interface)
  8156. return 0;
  8157. Spawn* spawn = lua_interface->GetSpawn(state);
  8158. if (!spawn) {
  8159. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. if (!spawn->IsWidget()) {
  8163. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8164. return 0;
  8165. }
  8166. ((Widget*)spawn)->SetMultiFloorLift(true);
  8167. if (spawn->GetZone())
  8168. spawn->GetZone()->AddTransportSpawn(spawn);
  8169. return 0;
  8170. }
  8171. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8172. if (!lua_interface)
  8173. return 0;
  8174. Spawn* player = lua_interface->GetSpawn(state);
  8175. int32 path = lua_interface->GetInt32Value(state, 2);
  8176. if (!player) {
  8177. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8178. return 0;
  8179. }
  8180. if (!player->IsPlayer()) {
  8181. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. if (path == 0) {
  8185. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8186. return 0;
  8187. }
  8188. Client* client = player->GetZone()->GetClientBySpawn(player);
  8189. if (!client) {
  8190. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. client->SendFlightAutoMount(path);
  8194. return 0;
  8195. }
  8196. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8197. if (!lua_interface)
  8198. return 0;
  8199. Spawn* player = lua_interface->GetSpawn(state);
  8200. if (!player) {
  8201. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8202. return 0;
  8203. }
  8204. if (!player->IsPlayer()) {
  8205. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8206. return 0;
  8207. }
  8208. Client* client = player->GetZone()->GetClientBySpawn(player);
  8209. if (!client) {
  8210. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8211. return 0;
  8212. }
  8213. client->EndAutoMount();
  8214. return 0;
  8215. }
  8216. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8217. if (!lua_interface)
  8218. return 0;
  8219. Spawn* player = lua_interface->GetSpawn(state);
  8220. if (!player) {
  8221. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8222. return 0;
  8223. }
  8224. if (!player->IsPlayer()) {
  8225. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8226. return 0;
  8227. }
  8228. Client* client = player->GetZone()->GetClientBySpawn(player);
  8229. if (!client) {
  8230. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8231. return 0;
  8232. }
  8233. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8234. return 1;
  8235. }
  8236. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8237. if (!lua_interface)
  8238. return 0;
  8239. Spawn* player = lua_interface->GetSpawn(state);
  8240. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8241. int32 value = lua_interface->GetInt32Value(state, 3);
  8242. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8243. if (!player) {
  8244. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. if (!player->IsPlayer()) {
  8248. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8249. return 0;
  8250. }
  8251. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8252. return 0;
  8253. }
  8254. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8255. if (!lua_interface)
  8256. return 0;
  8257. Spawn* player = lua_interface->GetSpawn(state);
  8258. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8259. if (!player) {
  8260. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8261. return 0;
  8262. }
  8263. if (!player->IsPlayer()) {
  8264. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8265. return 0;
  8266. }
  8267. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8268. if (!hd)
  8269. return 0;
  8270. lua_interface->SetInt32Value(state, hd->Value);
  8271. lua_interface->SetInt32Value(state, hd->Value2);
  8272. return 2;
  8273. }
  8274. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8275. if (!lua_interface)
  8276. return 0;
  8277. Spawn* spawn = lua_interface->GetSpawn(state);
  8278. int32 grid = lua_interface->GetInt32Value(state, 2);
  8279. if (!spawn) {
  8280. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8281. return 0;
  8282. }
  8283. if (grid == 0) {
  8284. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8285. return 0;
  8286. }
  8287. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8288. return 0;
  8289. }
  8290. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8291. if (!lua_interface)
  8292. return 0;
  8293. Spawn* spawn = lua_interface->GetSpawn(state);
  8294. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8295. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8296. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8297. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8298. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8299. if (!spawn) {
  8300. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8301. return 0;
  8302. }
  8303. //Add this quest to the list of required quests for this spawn
  8304. spawn->SetRequiredHistory(event_id, value1, value2);
  8305. //If private spawn value set
  8306. if (private_spawn) {
  8307. //Set the spawn to be private when not granted access via history
  8308. spawn->AddAllowAccessSpawn(spawn);
  8309. spawn->SetPrivateQuestSpawn(true);
  8310. }
  8311. //This value will override vis_flags in the vis packet
  8312. if (flag_override > 0)
  8313. spawn->SetQuestsRequiredOverride(flag_override);
  8314. return 0;
  8315. }
  8316. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8317. if (!lua_interface)
  8318. return 0;
  8319. Spawn* player = lua_interface->GetSpawn(state);
  8320. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8321. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8322. if (!player) {
  8323. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8324. return 0;
  8325. }
  8326. if (!player->IsPlayer()) {
  8327. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8328. return 0;
  8329. }
  8330. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8331. return 1;
  8332. }
  8333. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8334. if (!lua_interface)
  8335. return 0;
  8336. Spawn* player = lua_interface->GetSpawn(state);
  8337. int8 level = lua_interface->GetInt8Value(state, 2);
  8338. if (!player) {
  8339. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. if (!player->IsPlayer()) {
  8343. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. if (level == 0) {
  8347. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8348. return 0;
  8349. }
  8350. Client* client = player->GetZone()->GetClientBySpawn(player);
  8351. if (!client) {
  8352. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8356. return 0;
  8357. }
  8358. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8359. if (!lua_interface)
  8360. return 0;
  8361. Spawn* player = lua_interface->GetSpawn(state);
  8362. int32 amount = lua_interface->GetInt32Value(state, 2);
  8363. if (!player) {
  8364. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. if (!player->IsPlayer()) {
  8368. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8369. return 0;
  8370. }
  8371. if (amount == 0) {
  8372. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8373. return 0;
  8374. }
  8375. ((Player*)player)->AddCoins(amount);
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. Spawn* player = lua_interface->GetSpawn(state);
  8382. int32 amount = lua_interface->GetInt32Value(state, 2);
  8383. if (!player) {
  8384. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. if (!player->IsPlayer()) {
  8388. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. if (amount == 0) {
  8392. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8396. return 1;
  8397. }
  8398. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8399. if (!lua_interface)
  8400. return 0;
  8401. ZoneServer* zone = lua_interface->GetZone(state);
  8402. if (!zone) {
  8403. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. vector<Entity*> players = zone->GetPlayers();
  8407. if (players.size() == 0)
  8408. return 0;
  8409. lua_createtable(state, players.size(), 0);
  8410. int newTable = lua_gettop(state);
  8411. for (int32 i = 0; i < players.size(); i++) {
  8412. lua_interface->SetSpawnValue(state, players.at(i));
  8413. lua_rawseti(state, newTable, i + 1);
  8414. }
  8415. return 1;
  8416. }
  8417. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8418. if (!lua_interface)
  8419. return 0;
  8420. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8421. if (!zone) {
  8422. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8426. //Map of <placement_id, location_id>
  8427. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8428. map<int32, int32>::iterator itr;
  8429. vector<Spawn*> group;
  8430. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8431. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8432. if (!location) {
  8433. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8434. return 0;
  8435. }
  8436. Spawn* spawn = 0;
  8437. if (location->entities[0]) {
  8438. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8439. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8440. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8441. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8442. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8443. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8444. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8445. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8446. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8447. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8448. if (spawn) {
  8449. const char* script = 0;
  8450. for (int x = 0; x < 3; x++) {
  8451. switch (x) {
  8452. case 0:
  8453. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8454. break;
  8455. case 1:
  8456. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8457. break;
  8458. case 2:
  8459. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8460. break;
  8461. }
  8462. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8463. spawn->SetSpawnScript(string(script));
  8464. break;
  8465. }
  8466. }
  8467. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8468. lua_interface->SetSpawnValue(state, spawn);
  8469. group.push_back(spawn);
  8470. }
  8471. else {
  8472. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8473. safe_delete(spawn);
  8474. }
  8475. }
  8476. }
  8477. if (!group.empty()) {
  8478. lua_createtable(state, group.size(), 0);
  8479. int newTable = lua_gettop(state);
  8480. for (int32 i = 0; i < group.size(); i++) {
  8481. lua_interface->SetSpawnValue(state, group[i]);
  8482. lua_rawseti(state, newTable, i + 1);
  8483. }
  8484. }
  8485. else
  8486. lua_pushnil(state);
  8487. return 1;
  8488. }
  8489. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8490. if (!lua_interface)
  8491. return 0;
  8492. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8493. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8494. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8495. if (!spawn) {
  8496. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8497. return 0;
  8498. }
  8499. if (anim_id == 0) {
  8500. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. if (leeway == 0)
  8504. leeway = 5000;
  8505. spawn->SetSpawnAnim(anim_id);
  8506. spawn->SetSpawnAnimLeeway(leeway);
  8507. return 0;
  8508. }
  8509. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8510. if (!lua_interface)
  8511. return 0;
  8512. Spawn* player = lua_interface->GetSpawn(state);
  8513. if (!player) {
  8514. return 0;
  8515. }
  8516. Client* client = player->GetZone()->GetClientBySpawn(player);
  8517. if (!client) {
  8518. return 0;
  8519. }
  8520. lua_interface->SetInt32Value(state, client->GetVersion());
  8521. return 1;
  8522. }
  8523. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8524. if (!lua_interface)
  8525. return 0;
  8526. Item* item = lua_interface->GetItem(state);
  8527. if (!item) {
  8528. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8529. return 0;
  8530. }
  8531. lua_interface->SetInt32Value(state, item->details.item_id);
  8532. return 1;
  8533. }
  8534. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8535. if (!lua_interface)
  8536. return 0;
  8537. Spawn* spawn = lua_interface->GetSpawn(state);
  8538. if (!spawn) {
  8539. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8540. return 0;
  8541. }
  8542. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8543. return 1;
  8544. }
  8545. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8546. if (!lua_interface)
  8547. return 0;
  8548. Spawn* spawn = lua_interface->GetSpawn(state);
  8549. if (!spawn) {
  8550. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8554. return 1;
  8555. }
  8556. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8557. if (!lua_interface)
  8558. return 0;
  8559. Spawn* spawn = lua_interface->GetSpawn(state);
  8560. if (!spawn) {
  8561. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8565. return 1;
  8566. }
  8567. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8568. if (!lua_interface)
  8569. return 0;
  8570. Spawn* spawn = lua_interface->GetSpawn(state);
  8571. if (!spawn) {
  8572. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8573. return 0;
  8574. }
  8575. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8576. return 1;
  8577. }
  8578. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8579. if (!lua_interface)
  8580. return 0;
  8581. Spawn* spawn = lua_interface->GetSpawn(state);
  8582. float pct = lua_interface->GetFloatValue(state, 2);
  8583. if (!spawn) {
  8584. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8585. return 0;
  8586. }
  8587. if (pct == 0) {
  8588. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8589. return 0;
  8590. }
  8591. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8592. lua_interface->SetInt32Value(state, amount);
  8593. return 1;
  8594. }
  8595. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8596. if (!lua_interface)
  8597. return 0;
  8598. Spawn* spawn = lua_interface->GetSpawn(state);
  8599. float pct = lua_interface->GetFloatValue(state, 2);
  8600. if (!spawn) {
  8601. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. if (pct == 0) {
  8605. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8606. return 0;
  8607. }
  8608. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8609. lua_interface->SetInt32Value(state, amount);
  8610. return 1;
  8611. }
  8612. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8613. if (!lua_interface)
  8614. return 0;
  8615. Spawn* spawn = lua_interface->GetSpawn(state);
  8616. if (!spawn) {
  8617. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8618. return 0;
  8619. }
  8620. if (!spawn->IsPlayer()) {
  8621. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8622. return 0;
  8623. }
  8624. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8625. return 1;
  8626. }
  8627. int EQ2Emu_lua_Evac(lua_State* state) {
  8628. if (!lua_interface)
  8629. return 0;
  8630. Spawn* target = lua_interface->GetSpawn(state);
  8631. if (target) {
  8632. float x = target->GetZone()->GetSafeX();
  8633. float y = target->GetZone()->GetSafeY();
  8634. float z = target->GetZone()->GetSafeZ();
  8635. float h = target->GetZone()->GetSafeHeading();
  8636. target->SetX(x);
  8637. target->SetY(y);
  8638. target->SetZ(z);
  8639. target->SetHeading(h);
  8640. target->SetSpawnOrigX(target->GetX());
  8641. target->SetSpawnOrigY(target->GetY());
  8642. target->SetSpawnOrigZ(target->GetZ());
  8643. target->SetSpawnOrigHeading(target->GetHeading());
  8644. if (target->IsPlayer()) {
  8645. Client* client = target->GetZone()->GetClientBySpawn(target);
  8646. if (client) {
  8647. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8648. if (packet)
  8649. {
  8650. packet->setDataByName("x", x);
  8651. packet->setDataByName("y", y);
  8652. packet->setDataByName("z", z);
  8653. client->QueuePacket(packet->serialize());
  8654. safe_delete(packet);
  8655. }
  8656. }
  8657. }
  8658. }
  8659. else {
  8660. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8661. ZoneServer* zone = spell->caster->GetZone();
  8662. float x = spell->caster->GetZone()->GetSafeX();
  8663. float y = spell->caster->GetZone()->GetSafeY();
  8664. float z = spell->caster->GetZone()->GetSafeZ();
  8665. float h = spell->caster->GetZone()->GetSafeHeading();
  8666. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8667. for (int32 i = 0; i < spell->targets.size(); i++) {
  8668. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8669. if (!target2)
  8670. continue;
  8671. target2->SetX(x);
  8672. target2->SetY(y);
  8673. target2->SetZ(z);
  8674. target2->SetHeading(h);
  8675. target2->SetSpawnOrigX(target2->GetX());
  8676. target2->SetSpawnOrigY(target2->GetY());
  8677. target2->SetSpawnOrigZ(target2->GetZ());
  8678. target2->SetSpawnOrigHeading(target2->GetHeading());
  8679. if (target2->IsPlayer()) {
  8680. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8681. if (client) {
  8682. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8683. if (packet)
  8684. {
  8685. packet->setDataByName("x", x);
  8686. packet->setDataByName("y", y);
  8687. packet->setDataByName("z", z);
  8688. client->QueuePacket(packet->serialize());
  8689. safe_delete(packet);
  8690. }
  8691. }
  8692. }
  8693. }
  8694. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8695. }
  8696. return 0;
  8697. }
  8698. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8699. if (!lua_interface)
  8700. return 0;
  8701. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8702. if (!luaspell) {
  8703. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8704. return 0;
  8705. }
  8706. int8 tier = luaspell->spell->GetSpellTier();
  8707. lua_interface->SetInt32Value(state, tier);
  8708. return 1;
  8709. }
  8710. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8711. if (!lua_interface)
  8712. return 0;
  8713. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8714. if (!luaspell) {
  8715. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8716. return 0;
  8717. }
  8718. int32 spell_id = luaspell->spell->GetSpellID();
  8719. lua_interface->SetInt32Value(state, spell_id);
  8720. return 1;
  8721. }
  8722. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8723. if (!lua_interface)
  8724. return 0;
  8725. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8726. if (!spawn) {
  8727. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. if (!spawn->IsPlayer()) {
  8731. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8732. return 0;
  8733. }
  8734. ZoneServer* zone = spawn->GetZone();
  8735. if (!zone) {
  8736. return 0;
  8737. }
  8738. Client* client = zone->GetClientBySpawn(spawn);
  8739. if (!client) {
  8740. return 0;
  8741. }
  8742. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8743. return 0;
  8744. }
  8745. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8746. if (!lua_interface)
  8747. return 0;
  8748. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8749. if (!spawn) {
  8750. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. if (!spawn->IsPlayer()) {
  8754. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8755. return 0;
  8756. }
  8757. ZoneServer* zone = spawn->GetZone();
  8758. if (!zone) {
  8759. return 0;
  8760. }
  8761. Client* client = zone->GetClientBySpawn(spawn);
  8762. if (!client) {
  8763. return 0;
  8764. }
  8765. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8766. return 0;
  8767. }
  8768. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8769. if (!lua_interface)
  8770. return 0;
  8771. Spawn* caster = lua_interface->GetSpawn(state);
  8772. Spawn* target = lua_interface->GetSpawn(state, 2);
  8773. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8774. string spell_name = lua_interface->GetStringValue(state, 4);
  8775. if (!caster) {
  8776. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. if (!caster->IsEntity()) {
  8780. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. if (!target) {
  8784. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. if (!target->IsEntity()) {
  8788. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8789. return 0;
  8790. }
  8791. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8792. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8793. return 0;
  8794. }
  8795. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8796. if (!lua_interface)
  8797. return 0;
  8798. Spawn* object = lua_interface->GetSpawn(state);
  8799. Spawn* player = lua_interface->GetSpawn(state, 2);
  8800. if (object && player && player->IsPlayer()) {
  8801. int32 coins = lua_interface->GetInt32Value(state, 3);
  8802. vector<Item*>* items = 0;
  8803. int i = 0;
  8804. int32 item_id = 0;
  8805. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8806. if (items == 0)
  8807. items = new vector<Item*>;
  8808. if (master_item_list.GetItem(item_id))
  8809. items->push_back(master_item_list.GetItem(item_id));
  8810. i++;
  8811. }
  8812. Client* client = 0;
  8813. client = object->GetZone()->GetClientBySpawn(player);
  8814. if (client) {
  8815. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8816. }
  8817. safe_delete(items);
  8818. }
  8819. return 0;
  8820. }
  8821. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8822. if (!lua_interface)
  8823. return 0;
  8824. Spawn* player = lua_interface->GetSpawn(state);
  8825. int32 amount = lua_interface->GetInt32Value(state, 2);
  8826. if (player && player->IsPlayer() && amount > 0) {
  8827. ((Player*)player)->AddXP(amount);
  8828. ((Player*)player)->SetCharSheetChanged(true);
  8829. Client* client = player->GetZone()->GetClientBySpawn(player);
  8830. if (client) {
  8831. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8832. }
  8833. }
  8834. return 0;
  8835. }
  8836. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8837. if (!lua_interface)
  8838. return 0;
  8839. Spawn* player = lua_interface->GetSpawn(state);
  8840. int8 type = lua_interface->GetInt8Value(state, 2);
  8841. string text = lua_interface->GetStringValue(state, 3);
  8842. Client* client = 0;
  8843. if (player && player->IsPlayer())
  8844. client = player->GetZone()->GetClientBySpawn(player);
  8845. if (!client || text.length() == 0) {
  8846. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8847. return 0;
  8848. }
  8849. client->SimpleMessage(type, text.c_str());
  8850. return 0;
  8851. }
  8852. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8853. if (!lua_interface)
  8854. return 0;
  8855. Spawn* player = lua_interface->GetSpawn(state);
  8856. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8857. Client* client = 0;
  8858. if (player && player->IsPlayer())
  8859. client = player->GetZone()->GetClientBySpawn(player);
  8860. if (!client || !spawn) {
  8861. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8862. return 0;
  8863. }
  8864. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8865. if (!items) {
  8866. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8867. return 0;
  8868. }
  8869. client->Loot(spawn->GetLootCoins(), items, spawn);
  8870. return 0;
  8871. }
  8872. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. Spawn* spawnref = lua_interface->GetSpawn(state);
  8876. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8877. if (spawn_id > 0 && spawnref) {
  8878. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8879. if (spawns.size() == 0) {
  8880. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8881. return 0;
  8882. }
  8883. Spawn* spawn = 0;
  8884. int16 index = MakeRandomInt(0, spawns.size());
  8885. if (index >= spawns.size() || index < 0)
  8886. index = 0;
  8887. spawn = spawns[index];
  8888. lua_interface->SetSpawnValue(state, spawn);
  8889. return 1;
  8890. }
  8891. else {
  8892. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8893. }
  8894. return 0;
  8895. }
  8896. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8897. Spawn* player = lua_interface->GetSpawn(state);
  8898. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8899. string name = lua_interface->GetStringValue(state, 3);
  8900. float distance = lua_interface->GetFloatValue(state, 4);
  8901. string command = lua_interface->GetStringValue(state, 5);
  8902. string error_text = lua_interface->GetStringValue(state, 6);
  8903. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8904. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8905. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8906. if (distance == 0)
  8907. distance = 10.0f;
  8908. if (command.length() == 0)
  8909. command = name;
  8910. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8911. if (spawns.size() == 0) {
  8912. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8913. return 0;
  8914. }
  8915. Spawn* spawn = 0;
  8916. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8917. spawn = *itr;
  8918. if (spawn) {
  8919. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8920. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8921. }
  8922. }
  8923. }
  8924. return 0;
  8925. }
  8926. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8927. if (!lua_interface)
  8928. return 0;
  8929. Client* client = 0;
  8930. Spawn* player = lua_interface->GetSpawn(state);
  8931. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8932. if (player && player->IsPlayer() && player->GetZone())
  8933. client = player->GetZone()->GetClientBySpawn(player);
  8934. else{
  8935. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8936. return 0;
  8937. }
  8938. if (client) {
  8939. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8940. if (packet) {
  8941. packet->setDataByName("goal_num", goal_num);
  8942. client->QueuePacket(packet->serialize());
  8943. safe_delete(packet);
  8944. }
  8945. }
  8946. return 0;
  8947. }
  8948. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8949. if (!lua_interface)
  8950. return 0;
  8951. Client* client = 0;
  8952. Spawn* player = lua_interface->GetSpawn(state);
  8953. if (player && player->IsPlayer() && player->GetZone())
  8954. client = player->GetZone()->GetClientBySpawn(player);
  8955. else {
  8956. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8957. return 0;
  8958. }
  8959. if (client) {
  8960. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8961. }
  8962. return 0;
  8963. }
  8964. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8965. if (!lua_interface)
  8966. return 0;
  8967. Client* client = 0;
  8968. Spawn* player = lua_interface->GetSpawn(state);
  8969. float duration = lua_interface->GetFloatValue(state, 2);
  8970. string text = lua_interface->GetStringValue(state, 3);
  8971. string voice = lua_interface->GetStringValue(state, 4);
  8972. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8973. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8974. string signal = lua_interface->GetStringValue(state, 7);
  8975. string goal1 = lua_interface->GetStringValue(state, 8);
  8976. string task1 = lua_interface->GetStringValue(state, 9);
  8977. string goal2 = lua_interface->GetStringValue(state, 10);
  8978. string task2 = lua_interface->GetStringValue(state, 11);
  8979. string goal3 = lua_interface->GetStringValue(state, 12);
  8980. string task3 = lua_interface->GetStringValue(state, 13);
  8981. string goal4 = lua_interface->GetStringValue(state, 14);
  8982. string task4 = lua_interface->GetStringValue(state, 15);
  8983. if (!player) {
  8984. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8985. return 0;
  8986. }
  8987. if (!player->IsPlayer()) {
  8988. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8989. return 0;
  8990. }
  8991. else
  8992. client = ((Player*)player)->GetClient();
  8993. if (!client) {
  8994. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8995. return 0;
  8996. }
  8997. if (text.length() == 0) {
  8998. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8999. return 0;
  9000. }
  9001. if (duration >= 0 && duration < 2)
  9002. duration = 2;
  9003. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9004. if (packet) {
  9005. packet->setDataByName("open_seconds_max", duration);
  9006. packet->setDataByName("text", text.c_str());
  9007. packet->setDataByName("voice", voice.c_str());
  9008. int8 num_goals = 1;
  9009. if (task2.length() > 0)
  9010. num_goals++;
  9011. if (task3.length() > 0)
  9012. num_goals++;
  9013. if (task4.length() > 0)
  9014. num_goals++;
  9015. packet->setArrayLengthByName("num_goals", num_goals);
  9016. for (int8 i = 0; i < num_goals; i++) {
  9017. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9018. }
  9019. if (goal1.length() > 0)
  9020. packet->setArrayDataByName("goal_text", goal1.c_str());
  9021. if (goal2.length() > 0)
  9022. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9023. if (goal3.length() > 0)
  9024. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9025. if (goal4.length() > 0)
  9026. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9027. packet->setSubArrayDataByName("task_text", task1.c_str());
  9028. if (task2.length() > 0)
  9029. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9030. if (task3.length() > 0)
  9031. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9032. if (task4.length() > 0)
  9033. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9034. packet->setDataByName("complete_sound", "click");
  9035. packet->setDataByName("signal", signal.c_str());
  9036. packet->setDataByName("voice_key1", voice_key1);
  9037. packet->setDataByName("voice_key2", voice_key2);
  9038. client->QueuePacket(packet->serialize());
  9039. safe_delete(packet);
  9040. }
  9041. return 0;
  9042. }
  9043. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9044. if (!lua_interface)
  9045. return 0;
  9046. Client* client = 0;
  9047. Spawn* player = lua_interface->GetSpawn(state);
  9048. string window = lua_interface->GetStringValue(state, 2);
  9049. int8 show = lua_interface->GetInt8Value(state, 3);
  9050. if (!player) {
  9051. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9052. return 0;
  9053. }
  9054. if (!player->IsPlayer()) {
  9055. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9056. return 0;
  9057. }
  9058. else
  9059. client = ((Player*)player)->GetClient();
  9060. if (!client) {
  9061. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9062. return 0;
  9063. }
  9064. if (window.length() == 0) {
  9065. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9066. return 0;
  9067. }
  9068. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9069. if (packet) {
  9070. packet->setDataByName("window", window.c_str());
  9071. packet->setDataByName("show", show);
  9072. client->QueuePacket(packet->serialize());
  9073. safe_delete(packet);
  9074. }
  9075. return 0;
  9076. }
  9077. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9078. //See GameEvents.txt for options that can be used for this function
  9079. if (!lua_interface)
  9080. return 0;
  9081. Client* client = 0;
  9082. Spawn* player = lua_interface->GetSpawn(state);
  9083. string event_name = lua_interface->GetStringValue(state, 2);
  9084. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9085. if (!player || !player->IsPlayer()) {
  9086. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9087. return 0;
  9088. }
  9089. if (player->GetZone())
  9090. client = player->GetZone()->GetClientBySpawn(player);
  9091. if (!client) {
  9092. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9093. return 0;
  9094. }
  9095. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9096. if (packet) {
  9097. packet->setDataByName("event_name", event_name.c_str());
  9098. packet->setDataByName("enabled", enabled);
  9099. client->QueuePacket(packet->serialize());
  9100. safe_delete(packet);
  9101. }
  9102. return 0;
  9103. }
  9104. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9105. if (!lua_interface)
  9106. return 0;
  9107. Spawn* player = lua_interface->GetSpawn(state);
  9108. if (player && player->IsPlayer()) {
  9109. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9110. return 1;
  9111. }
  9112. return 0;
  9113. }
  9114. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9115. if (!lua_interface)
  9116. return 0;
  9117. Spawn* player = lua_interface->GetSpawn(state);
  9118. int8 step = lua_interface->GetInt8Value(state, 2);
  9119. if (player && player->IsPlayer() && step > 0) {
  9120. ((Player*)player)->SetTutorialStep(step);
  9121. }
  9122. return 0;
  9123. }
  9124. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9125. if (!lua_interface)
  9126. return 0;
  9127. Client* client = 0;
  9128. Spawn* player = lua_interface->GetSpawn(state);
  9129. string window = lua_interface->GetStringValue(state, 2);
  9130. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9131. if (!player) {
  9132. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9133. return 0;
  9134. }
  9135. if (!player->IsPlayer()) {
  9136. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9137. return 0;
  9138. }
  9139. else
  9140. client = ((Player*)player)->GetClient();
  9141. if (!client) {
  9142. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9143. return 0;
  9144. }
  9145. if (window.length() == 0) {
  9146. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9147. return 0;
  9148. }
  9149. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9150. if (packet) {
  9151. packet->setDataByName("window", window.c_str());
  9152. packet->setDataByName("flash_seconds", flash_seconds);
  9153. client->QueuePacket(packet->serialize());
  9154. safe_delete(packet);
  9155. }
  9156. return 0;
  9157. }
  9158. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9159. if (!lua_interface)
  9160. return 0;
  9161. Spawn* spawn = lua_interface->GetSpawn(state);
  9162. Spawn* target = lua_interface->GetSpawn(state, 2);
  9163. if (spawn && target)
  9164. return spawn->CheckLoS(target);
  9165. return 0;
  9166. }
  9167. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9168. if (!lua_interface)
  9169. return 0;
  9170. Spawn* spawn = lua_interface->GetSpawn(state);
  9171. float x = lua_interface->GetFloatValue(state, 2);
  9172. float y = lua_interface->GetFloatValue(state, 3);
  9173. float z = lua_interface->GetFloatValue(state, 4);
  9174. if (spawn)
  9175. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9176. return 0;
  9177. }
  9178. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9179. if (!lua_interface)
  9180. return 0;
  9181. ZoneServer* zone = lua_interface->GetZone(state);
  9182. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9183. if (zone)
  9184. zone->SetExpansionFlag(xpackFlag);
  9185. return 0;
  9186. }
  9187. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9188. if (!lua_interface)
  9189. return 0;
  9190. ZoneServer* zone = lua_interface->GetZone(state);
  9191. if (zone) {
  9192. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9193. return 1;
  9194. }
  9195. return 0;
  9196. }
  9197. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9198. if (!lua_interface)
  9199. return 0;
  9200. ZoneServer* zone = lua_interface->GetZone(state);
  9201. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9202. if (zone)
  9203. zone->SetHolidayFlag(holidayFlag);
  9204. return 0;
  9205. }
  9206. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9207. if (!lua_interface)
  9208. return 0;
  9209. ZoneServer* zone = lua_interface->GetZone(state);
  9210. if (zone) {
  9211. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9212. return 1;
  9213. }
  9214. return 0;
  9215. }
  9216. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9217. if (!lua_interface)
  9218. return 0;
  9219. Spawn* spawn = lua_interface->GetSpawn(state);
  9220. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9221. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9222. float distance = lua_interface->GetFloatValue(state, 4);
  9223. string in_range_function = lua_interface->GetStringValue(state, 5);
  9224. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9225. if (spawn && distance > 0 && in_range_function.length() > 0)
  9226. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9227. return 0;
  9228. }
  9229. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9230. if (!lua_interface)
  9231. return 0;
  9232. Spawn* spawn = lua_interface->GetSpawn(state);
  9233. Spawn* target = lua_interface->GetSpawn(state, 2);
  9234. if (spawn && target)
  9235. {
  9236. if (spawn->IsPlayer() && target->IsEntity())
  9237. {
  9238. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9239. return 1;
  9240. }
  9241. else if (spawn->IsEntity() && target->IsEntity())
  9242. {
  9243. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9244. return 1;
  9245. }
  9246. }
  9247. return 0;
  9248. }
  9249. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9250. if (!lua_interface)
  9251. return 0;
  9252. Spawn* spawn = lua_interface->GetSpawn(state);
  9253. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9254. if (spawn && spawn->IsEntity())
  9255. {
  9256. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9257. if (spawn->IsPlayer())
  9258. {
  9259. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9260. if (client)
  9261. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9262. }
  9263. }
  9264. return 0;
  9265. }
  9266. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9267. if (!lua_interface)
  9268. return 0;
  9269. Spawn* spawn = lua_interface->GetSpawn(state);
  9270. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9271. if (spawn && spawn->IsEntity())
  9272. {
  9273. ((Entity*)spawn)->SetSeeHideSpell(val);
  9274. if (spawn->IsPlayer())
  9275. {
  9276. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9277. if (client)
  9278. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9279. }
  9280. }
  9281. return 0;
  9282. }
  9283. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9284. {
  9285. if (!lua_interface)
  9286. return 0;
  9287. Spawn* player = lua_interface->GetSpawn(state);
  9288. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9289. string command = lua_interface->GetStringValue(state, 3);
  9290. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9291. if (spawn && player && player->IsPlayer())
  9292. {
  9293. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9294. bool res = false;
  9295. if (cmd)
  9296. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9297. lua_interface->SetBooleanValue(state, res);
  9298. return 1;
  9299. }
  9300. return 0;
  9301. }
  9302. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9303. {
  9304. if (!lua_interface)
  9305. return 0;
  9306. Spawn* spawn = lua_interface->GetSpawn(state);
  9307. string command = lua_interface->GetStringValue(state, 2);
  9308. if (spawn && command.length() > 0)
  9309. spawn->RemovePrimaryEntityCommand(command.c_str());
  9310. return 0;
  9311. }
  9312. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9313. if (!lua_interface)
  9314. return 0;
  9315. Spawn* spawn = lua_interface->GetSpawn(state);
  9316. float distance = lua_interface->GetFloatValue(state, 2);
  9317. string command = lua_interface->GetStringValue(state, 3);
  9318. Spawn* player = lua_interface->GetSpawn(state, 4);
  9319. if (spawn) {
  9320. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9321. }
  9322. return 0;
  9323. }
  9324. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9325. if (!lua_interface)
  9326. return 0;
  9327. Spawn* spawn = lua_interface->GetSpawn(state);
  9328. Spawn* player = lua_interface->GetSpawn(state, 2);
  9329. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9330. if (spawn && player && transport_id && player->IsPlayer()) {
  9331. Client* client = 0;
  9332. if (player && player->IsPlayer())
  9333. client = player->GetZone()->GetClientBySpawn(player);
  9334. if (!client)
  9335. return 0;
  9336. vector<TransportDestination*> destinations;
  9337. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9338. if (destinations.size())
  9339. {
  9340. client->SetTemporaryTransportID(transport_id);
  9341. client->ProcessTeleport(spawn, &destinations, transport_id);
  9342. }
  9343. else
  9344. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9345. }
  9346. return 0;
  9347. }
  9348. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9349. if (!lua_interface)
  9350. return 0;
  9351. Spawn* player = lua_interface->GetSpawn(state);
  9352. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9353. if (player && player->IsPlayer()) {
  9354. Client* client = 0;
  9355. if (player && player->IsPlayer())
  9356. client = player->GetZone()->GetClientBySpawn(player);
  9357. if (!client)
  9358. return 0;
  9359. client->SetTemporaryTransportID(transport_id);
  9360. }
  9361. return 0;
  9362. }
  9363. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9364. if (!lua_interface)
  9365. return 0;
  9366. Spawn* player = lua_interface->GetSpawn(state);
  9367. if (player && player->IsPlayer()) {
  9368. Client* client = 0;
  9369. if (player && player->IsPlayer())
  9370. client = player->GetZone()->GetClientBySpawn(player);
  9371. if (!client)
  9372. return 0;
  9373. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9374. return 1;
  9375. }
  9376. return 0;
  9377. }
  9378. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9379. if (!lua_interface)
  9380. return 0;
  9381. Spawn* spawn = lua_interface->GetSpawn(state);
  9382. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9383. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9384. if (!spawn) {
  9385. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. if (!spawn->IsEntity()) {
  9389. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9390. return 0;
  9391. }
  9392. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9393. {
  9394. 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);
  9395. return 0;
  9396. }
  9397. if (spell && spell->targets.size() > 0) {
  9398. ZoneServer* zone = spell->caster->GetZone();
  9399. for (int8 i = 0; i < spell->targets.size(); i++) {
  9400. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9401. if (target->IsEntity()) {
  9402. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9403. if (target->IsPlayer())
  9404. ((Player*)target)->SetCharSheetChanged(true);
  9405. }
  9406. }
  9407. }
  9408. else {
  9409. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9410. if (spawn->IsPlayer())
  9411. ((Player*)spawn)->SetCharSheetChanged(true);
  9412. }
  9413. return 0;
  9414. }
  9415. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9416. if (!lua_interface)
  9417. return 0;
  9418. Spawn* spawn = lua_interface->GetSpawn(state);
  9419. if (!spawn) {
  9420. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9421. return 0;
  9422. }
  9423. if (!spawn->IsEntity()) {
  9424. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9425. return 0;
  9426. }
  9427. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9428. return 1;
  9429. }
  9430. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9431. if (!lua_interface)
  9432. return 0;
  9433. int32 spell_id = lua_interface->GetInt32Value(state);
  9434. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9435. if (spell_id > 0) {
  9436. if (spell_tier == 0)
  9437. spell_tier = 1;
  9438. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9439. LuaSpell* lua_spell = 0;
  9440. if (lua_interface)
  9441. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9442. if (!lua_spell)
  9443. return 0;
  9444. lua_spell->spell = new Spell(spell);
  9445. lua_interface->AddCustomSpell(lua_spell);
  9446. lua_interface->SetSpellValue(state, lua_spell);
  9447. return 1;
  9448. }
  9449. return 0;
  9450. }
  9451. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9452. if (!lua_interface)
  9453. return 0;
  9454. LuaSpell* spell = lua_interface->GetSpell(state);
  9455. string field = lua_interface->GetStringValue(state, 2);
  9456. if (!spell) {
  9457. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9458. return 0;
  9459. }
  9460. if (!spell->spell || !spell->spell->GetSpellData()) {
  9461. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9462. return 0;
  9463. }
  9464. boost::to_lower(field);
  9465. return spell->spell->GetSpellData(state, field);
  9466. }
  9467. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9468. if (!lua_interface)
  9469. return 0;
  9470. LuaSpell* spell = lua_interface->GetSpell(state);
  9471. string field = lua_interface->GetStringValue(state, 2);
  9472. int8 fieldArg = 3; // field value after the initial set
  9473. if (!spell) {
  9474. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9475. return 0;
  9476. }
  9477. if (!spell->spell || !spell->spell->GetSpellData()) {
  9478. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9479. return 0;
  9480. }
  9481. boost::to_lower(field);
  9482. bool valSet = false;
  9483. spell->spell->SetSpellData(state, field, fieldArg);
  9484. return valSet;
  9485. }
  9486. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9487. if (!lua_interface)
  9488. return 0;
  9489. LuaSpell* spell = lua_interface->GetSpell(state);
  9490. int8 idx = lua_interface->GetInt32Value(state, 2);
  9491. if (!spell) {
  9492. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9493. return 0;
  9494. }
  9495. if (!spell->spell || !spell->spell->GetSpellData()) {
  9496. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9497. return 0;
  9498. }
  9499. if (spell->spell->lua_data.size() <= idx)
  9500. {
  9501. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9502. return 0;
  9503. }
  9504. bool setVal = true;
  9505. LUAData* data = spell->spell->lua_data[idx];
  9506. switch (data->type)
  9507. {
  9508. case 0:
  9509. {
  9510. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9511. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9512. data->int_value = value;
  9513. data->int_value2 = value2;
  9514. break;
  9515. }
  9516. case 1:
  9517. {
  9518. float value = lua_interface->GetFloatValue(state, 3);
  9519. float value2 = lua_interface->GetFloatValue(state, 4);
  9520. data->float_value = value;
  9521. data->float_value2 = value2;
  9522. break;
  9523. }
  9524. case 2:
  9525. {
  9526. bool value = lua_interface->GetBooleanValue(state, 3);
  9527. data->bool_value = value;
  9528. break;
  9529. }
  9530. case 3:
  9531. {
  9532. string value = lua_interface->GetStringValue(state, 3);
  9533. string value2 = lua_interface->GetStringValue(state, 4);
  9534. data->string_value = value;
  9535. data->string_value2 = value2;
  9536. break;
  9537. }
  9538. default:
  9539. setVal = false;
  9540. }
  9541. return setVal;
  9542. }
  9543. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9544. if (!lua_interface)
  9545. return 0;
  9546. LuaSpell* spell = lua_interface->GetSpell(state);
  9547. int8 idx = lua_interface->GetInt32Value(state, 2);
  9548. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9549. if (!spell) {
  9550. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9551. return 0;
  9552. }
  9553. if (!spell->spell || !spell->spell->GetSpellData()) {
  9554. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9555. return 0;
  9556. }
  9557. if (spell->spell->lua_data.size() <= idx)
  9558. {
  9559. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9560. return 0;
  9561. }
  9562. bool setVal = true;
  9563. LUAData* data = spell->spell->lua_data[idx];
  9564. switch (data->type)
  9565. {
  9566. case 0:
  9567. {
  9568. if(!secondfield)
  9569. lua_interface->SetSInt32Value(state, data->int_value);
  9570. else
  9571. lua_interface->SetSInt32Value(state, data->int_value2);
  9572. break;
  9573. }
  9574. case 1:
  9575. {
  9576. if (!secondfield)
  9577. lua_interface->SetFloatValue(state, data->float_value);
  9578. else
  9579. lua_interface->SetFloatValue(state, data->float_value2);
  9580. break;
  9581. }
  9582. case 2:
  9583. {
  9584. lua_interface->SetBooleanValue(state, data->bool_value);
  9585. break;
  9586. }
  9587. case 3:
  9588. {
  9589. if (!secondfield)
  9590. lua_interface->SetStringValue(state, data->string_value.c_str());
  9591. else
  9592. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9593. break;
  9594. }
  9595. default:
  9596. setVal = false;
  9597. }
  9598. return setVal;
  9599. }
  9600. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9601. if (!lua_interface)
  9602. return 0;
  9603. LuaSpell* spell = lua_interface->GetSpell(state);
  9604. int8 idx = lua_interface->GetInt32Value(state, 2);
  9605. string field = lua_interface->GetStringValue(state, 3);
  9606. boost::to_lower(field);
  9607. if (!spell) {
  9608. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9609. return 0;
  9610. }
  9611. if (!spell->spell || !spell->spell->GetSpellData()) {
  9612. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9613. return 0;
  9614. }
  9615. if (spell->spell->effects.size() <= idx)
  9616. {
  9617. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9618. return 0;
  9619. }
  9620. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9621. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9622. if (field == "description")
  9623. effect->description = string(lua_interface->GetStringValue(state, 4));
  9624. else if (field == "bullet")
  9625. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9626. else if (field == "percentage")
  9627. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9628. else // no match
  9629. return 0;
  9630. return 1;
  9631. }
  9632. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9633. if (!lua_interface)
  9634. return 0;
  9635. LuaSpell* spell = lua_interface->GetSpell(state);
  9636. int8 idx = lua_interface->GetInt32Value(state, 2);
  9637. string field = lua_interface->GetStringValue(state, 3);
  9638. boost::to_lower(field);
  9639. if (!spell) {
  9640. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9641. return 0;
  9642. }
  9643. if (!spell->spell || !spell->spell->GetSpellData()) {
  9644. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9645. return 0;
  9646. }
  9647. if (spell->spell->effects.size() <= idx)
  9648. {
  9649. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9650. return 0;
  9651. }
  9652. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9653. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9654. if (field == "description")
  9655. lua_interface->SetStringValue(state, effect->description.c_str());
  9656. else if (field == "bullet")
  9657. lua_interface->SetInt32Value(state, effect->subbullet);
  9658. else if (field == "percentage")
  9659. lua_interface->SetInt32Value(state, effect->percentage);
  9660. else // no match
  9661. return 0;
  9662. return 1;
  9663. }
  9664. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9665. if (!lua_interface)
  9666. return 0;
  9667. LuaSpell* spell = lua_interface->GetSpell(state);
  9668. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9669. Spawn* target = lua_interface->GetSpawn(state, 3);
  9670. if (!target) {
  9671. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9672. return 0;
  9673. }
  9674. if (!target->IsEntity()) {
  9675. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9676. return 0;
  9677. }
  9678. if (!spell) {
  9679. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9680. return 0;
  9681. }
  9682. if (caster && !caster->IsEntity()) {
  9683. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9684. return 0;
  9685. }
  9686. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9687. return 0;
  9688. }
  9689. int EQ2Emu_lua_InWater(lua_State* state) {
  9690. if (!lua_interface)
  9691. return 0;
  9692. Spawn* spawn = lua_interface->GetSpawn(state);
  9693. lua_interface->ResetFunctionStack(state);
  9694. if (spawn) {
  9695. lua_interface->SetBooleanValue(state, spawn->InWater());
  9696. return 1;
  9697. }
  9698. return 0;
  9699. }
  9700. int EQ2Emu_lua_InLava(lua_State* state) {
  9701. if (!lua_interface)
  9702. return 0;
  9703. Spawn* spawn = lua_interface->GetSpawn(state);
  9704. lua_interface->ResetFunctionStack(state);
  9705. if (spawn) {
  9706. lua_interface->SetBooleanValue(state, spawn->InLava());
  9707. return 1;
  9708. }
  9709. return 0;
  9710. }
  9711. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9712. if (!lua_interface)
  9713. return 0;
  9714. Spawn* attacker = lua_interface->GetSpawn(state);
  9715. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9716. int8 type = lua_interface->GetInt8Value(state, 3);
  9717. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9718. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9719. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9720. string spell_name = lua_interface->GetStringValue(state, 7);
  9721. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9722. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9723. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9724. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9725. lua_interface->ResetFunctionStack(state);
  9726. if (!attacker) {
  9727. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9728. return 0;
  9729. }
  9730. if (!attacker->IsEntity()) {
  9731. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9732. return 0;
  9733. }
  9734. if (!victim) {
  9735. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9736. return 0;
  9737. }
  9738. if (!victim->IsEntity()) {
  9739. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9740. return 0;
  9741. }
  9742. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9743. return 0;
  9744. }
  9745. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9746. if (!lua_interface)
  9747. return 0;
  9748. Spawn* spawn = lua_interface->GetSpawn(state);
  9749. lua_interface->ResetFunctionStack(state);
  9750. if (spawn) {
  9751. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9752. return 1;
  9753. }
  9754. return 0;
  9755. }
  9756. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9757. if (!lua_interface)
  9758. return 0;
  9759. Spawn* spawn = lua_interface->GetSpawn(state);
  9760. bool invul = lua_interface->GetBooleanValue(state, 2);
  9761. lua_interface->ResetFunctionStack(state);
  9762. if (spawn) {
  9763. spawn->SetInvulnerable(invul);
  9764. }
  9765. return 0;
  9766. }
  9767. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9768. if (!lua_interface)
  9769. return 0;
  9770. string category = lua_interface->GetStringValue(state);
  9771. string name = lua_interface->GetStringValue(state, 2);
  9772. lua_interface->ResetFunctionStack(state);
  9773. Rule *ret = 0;
  9774. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9775. lua_interface->SetInt32Value(state, ret->GetInt32());
  9776. return 1;
  9777. }
  9778. lua_interface->LogError("%s: LUA GetRuleFlag Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9779. return 0;
  9780. }
  9781. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9782. if (!lua_interface)
  9783. return 0;
  9784. Spawn* spawn = lua_interface->GetSpawn(state);
  9785. string type = lua_interface->GetStringValue(state, 2);
  9786. lua_interface->ResetFunctionStack(state);
  9787. if (spawn) {
  9788. int res = 1;
  9789. boost::to_lower(type);
  9790. if(type == "assigned_aa")
  9791. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9792. else if ( type == "unassigned_aa")
  9793. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9794. else if ( type == "assigned_tradeskill_aa")
  9795. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9796. else if ( type == "unassigned_tradeskill_aa")
  9797. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9798. else if ( type == "assigned_prestige_aa")
  9799. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9800. else if ( type == "unassigned_prestige_aa")
  9801. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9802. else if ( type == "assigned_tradeskill_prestige_aa")
  9803. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9804. else if ( type == "unassigned_tradeskill_prestige_aa")
  9805. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9806. else
  9807. res = 0;
  9808. return res;
  9809. }
  9810. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9811. return 0;
  9812. }
  9813. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  9814. if (!lua_interface)
  9815. return 0;
  9816. Spawn* spawn = lua_interface->GetSpawn(state);
  9817. string type = lua_interface->GetStringValue(state, 2);
  9818. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9819. lua_interface->ResetFunctionStack(state);
  9820. if (spawn) {
  9821. boost::to_lower(type);
  9822. if(type == "assigned_aa")
  9823. spawn->SetAssignedAA((sint16)value);
  9824. else if ( type == "unassigned_aa")
  9825. spawn->SetUnassignedAA((sint16)value);
  9826. else if ( type == "assigned_tradeskill_aa")
  9827. spawn->SetTradeskillAA((sint16)value);
  9828. else if ( type == "unassigned_tradeskill_aa")
  9829. spawn->SetUnassignedTradeskillAA((sint16)value);
  9830. else if ( type == "assigned_prestige_aa")
  9831. spawn->SetPrestigeAA((sint16)value);
  9832. else if ( type == "unassigned_prestige_aa")
  9833. spawn->SetUnassignedPrestigeAA((sint16)value);
  9834. else if ( type == "assigned_tradeskill_prestige_aa")
  9835. spawn->SetTradeskillPrestigeAA((sint16)value);
  9836. else if ( type == "unassigned_tradeskill_prestige_aa")
  9837. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  9838. if(spawn->IsPlayer())
  9839. ((Player*)spawn)->SetCharSheetChanged(true);
  9840. }
  9841. return 0;
  9842. }
  9843. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  9844. if (!lua_interface)
  9845. return 0;
  9846. string titleName = lua_interface->GetStringValue(state);
  9847. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  9848. lua_interface->ResetFunctionStack(state);
  9849. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  9850. lua_interface->SetSInt32Value(state, index);
  9851. return 1;
  9852. }
  9853. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  9854. if (!lua_interface)
  9855. return 0;
  9856. Spawn* spawn = lua_interface->GetSpawn(state);
  9857. string titleName = lua_interface->GetStringValue(state, 2);
  9858. lua_interface->ResetFunctionStack(state);
  9859. if(!spawn->IsPlayer())
  9860. {
  9861. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  9862. lua_interface->SetSInt32Value(state, -1);
  9863. return 1;
  9864. }
  9865. Player* player = (Player*)spawn;
  9866. // check if player already has the title, don't need to add twice
  9867. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9868. if ( playerHasTitle)
  9869. {
  9870. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  9871. return 1;
  9872. }
  9873. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  9874. if(!title)
  9875. {
  9876. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9877. lua_interface->SetSInt32Value(state, -1);
  9878. return 1;
  9879. }
  9880. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  9881. if(returnIdx < 0)
  9882. {
  9883. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9884. }
  9885. lua_interface->SetSInt32Value(state, returnIdx);
  9886. player->GetClient()->SendTitleUpdate();
  9887. return 1;
  9888. }
  9889. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  9890. if (!lua_interface)
  9891. return 0;
  9892. Spawn* spawn = lua_interface->GetSpawn(state);
  9893. string titleName = lua_interface->GetStringValue(state, 2);
  9894. lua_interface->ResetFunctionStack(state);
  9895. if(!spawn->IsPlayer())
  9896. {
  9897. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  9898. return 0;
  9899. }
  9900. Player* player = (Player*)spawn;
  9901. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9902. if(!title)
  9903. {
  9904. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9905. return 0;
  9906. }
  9907. if(title->GetPrefix())
  9908. {
  9909. 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());
  9910. return 0;
  9911. }
  9912. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  9913. player->GetClient()->SendTitleUpdate();
  9914. return 1;
  9915. }
  9916. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  9917. if (!lua_interface)
  9918. return 0;
  9919. Spawn* spawn = lua_interface->GetSpawn(state);
  9920. string titleName = lua_interface->GetStringValue(state, 2);
  9921. lua_interface->ResetFunctionStack(state);
  9922. if(!spawn->IsPlayer())
  9923. {
  9924. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  9925. return 0;
  9926. }
  9927. Player* player = (Player*)spawn;
  9928. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9929. if(!title)
  9930. {
  9931. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9932. return 0;
  9933. }
  9934. if(!title->GetPrefix())
  9935. {
  9936. 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());
  9937. return 0;
  9938. }
  9939. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  9940. player->GetClient()->SendTitleUpdate();
  9941. return 1;
  9942. }
  9943. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  9944. if (!lua_interface)
  9945. return 0;
  9946. Spawn* spawn = lua_interface->GetSpawn(state);
  9947. lua_interface->ResetFunctionStack(state);
  9948. if(!spawn->IsPlayer())
  9949. {
  9950. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  9951. return 0;
  9952. }
  9953. Player* player = (Player*)spawn;
  9954. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  9955. player->GetClient()->SendTitleUpdate();
  9956. return 1;
  9957. }
  9958. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  9959. if (!lua_interface)
  9960. return 0;
  9961. Spawn* spawn = lua_interface->GetSpawn(state);
  9962. lua_interface->ResetFunctionStack(state);
  9963. if(!spawn->IsPlayer())
  9964. {
  9965. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  9966. return 0;
  9967. }
  9968. Player* player = (Player*)spawn;
  9969. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  9970. player->GetClient()->SendTitleUpdate();
  9971. return 1;
  9972. }
  9973. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  9974. if (!lua_interface)
  9975. return 0;
  9976. Spawn* spawn = lua_interface->GetSpawn(state);
  9977. string field = lua_interface->GetStringValue(state, 2);
  9978. lua_interface->ResetFunctionStack(state);
  9979. if(!spawn || !spawn->IsEntity())
  9980. {
  9981. 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));
  9982. return 0;
  9983. }
  9984. Entity* ent = (Entity*)spawn;
  9985. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  9986. return 1;
  9987. }
  9988. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  9989. if (!lua_interface)
  9990. return 0;
  9991. Spawn* spawn = lua_interface->GetSpawn(state);
  9992. string field = lua_interface->GetStringValue(state, 2);
  9993. lua_interface->ResetFunctionStack(state);
  9994. if(!spawn || !spawn->IsEntity())
  9995. {
  9996. 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));
  9997. return 0;
  9998. }
  9999. Entity* ent = (Entity*)spawn;
  10000. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10001. return 1;
  10002. }
  10003. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10004. if (!lua_interface)
  10005. return 0;
  10006. Spawn* spawn = lua_interface->GetSpawn(state);
  10007. string field = lua_interface->GetStringValue(state, 2);
  10008. lua_interface->ResetFunctionStack(state);
  10009. if(!spawn || !spawn->IsEntity())
  10010. {
  10011. 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));
  10012. return 0;
  10013. }
  10014. Entity* ent = (Entity*)spawn;
  10015. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10016. return 1;
  10017. }
  10018. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10019. if (!lua_interface)
  10020. return 0;
  10021. Spawn* spawn = lua_interface->GetSpawn(state);
  10022. string field = lua_interface->GetStringValue(state, 2);
  10023. lua_interface->ResetFunctionStack(state);
  10024. if(!spawn || !spawn->IsEntity())
  10025. {
  10026. 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));
  10027. return 0;
  10028. }
  10029. Entity* ent = (Entity*)spawn;
  10030. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10031. return 1;
  10032. }
  10033. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10034. if (!lua_interface)
  10035. return 0;
  10036. Spawn* spawn = lua_interface->GetSpawn(state);
  10037. string field = lua_interface->GetStringValue(state, 2);
  10038. string value = lua_interface->GetStringValue(state, 3);
  10039. lua_interface->ResetFunctionStack(state);
  10040. if(!spawn || !spawn->IsEntity())
  10041. {
  10042. 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));
  10043. return 0;
  10044. }
  10045. Entity* ent = (Entity*)spawn;
  10046. bool set_ = ent->SetInfoStructString(field, value);
  10047. lua_interface->SetBooleanValue(state, set_);
  10048. return 1;
  10049. }
  10050. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10051. if (!lua_interface)
  10052. return 0;
  10053. Spawn* spawn = lua_interface->GetSpawn(state);
  10054. string field = lua_interface->GetStringValue(state, 2);
  10055. int64 value = lua_interface->GetInt64Value(state, 3);
  10056. lua_interface->ResetFunctionStack(state);
  10057. if(!spawn || !spawn->IsEntity())
  10058. {
  10059. 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));
  10060. return 0;
  10061. }
  10062. Entity* ent = (Entity*)spawn;
  10063. bool set_ = ent->SetInfoStructUInt(field, value);
  10064. lua_interface->SetBooleanValue(state, set_);
  10065. return 1;
  10066. }
  10067. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10068. if (!lua_interface)
  10069. return 0;
  10070. Spawn* spawn = lua_interface->GetSpawn(state);
  10071. string field = lua_interface->GetStringValue(state, 2);
  10072. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10073. lua_interface->ResetFunctionStack(state);
  10074. if(!spawn || !spawn->IsEntity())
  10075. {
  10076. 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));
  10077. return 0;
  10078. }
  10079. Entity* ent = (Entity*)spawn;
  10080. bool set_ = ent->SetInfoStructSInt(field, value);
  10081. lua_interface->SetBooleanValue(state, set_);
  10082. return 1;
  10083. }
  10084. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10085. if (!lua_interface)
  10086. return 0;
  10087. Spawn* spawn = lua_interface->GetSpawn(state);
  10088. string field = lua_interface->GetStringValue(state, 2);
  10089. float value = lua_interface->GetFloatValue(state, 3);
  10090. lua_interface->ResetFunctionStack(state);
  10091. if(!spawn || !spawn->IsEntity())
  10092. {
  10093. 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));
  10094. return 0;
  10095. }
  10096. Entity* ent = (Entity*)spawn;
  10097. bool set_ = ent->SetInfoStructFloat(field, value);
  10098. lua_interface->SetBooleanValue(state, set_);
  10099. return 1;
  10100. }
  10101. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10102. if (!lua_interface)
  10103. return 0;
  10104. Spawn* spawn = lua_interface->GetSpawn(state);
  10105. bool value = lua_interface->GetBooleanValue(state, 2);
  10106. lua_interface->ResetFunctionStack(state);
  10107. if(!spawn || !spawn->IsPlayer())
  10108. {
  10109. 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));
  10110. return 0;
  10111. }
  10112. ((Player*)spawn)->SetCharSheetChanged(value);
  10113. return 0;
  10114. }