LuaFunctions.cpp 395 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = spawn->GetZone()->GetClientBySpawn(player);
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  374. }
  375. else
  376. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if(!luaspell || luaspell->resisted) {
  1229. return 0;
  1230. }
  1231. Spawn* caster = luaspell->caster;
  1232. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1233. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1234. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1235. Spawn* target = lua_interface->GetSpawn(state, 4);
  1236. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1237. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1238. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1239. lua_interface->ResetFunctionStack(state);
  1240. boost::to_lower(heal_type);
  1241. if (caster && caster->IsEntity()) {
  1242. bool success = false;
  1243. luaspell->resisted = false;
  1244. if (target) {
  1245. float distance = caster->GetDistance(target, true);
  1246. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1247. success = true;
  1248. }
  1249. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1250. Spawn* target = 0;
  1251. ZoneServer* zone = luaspell->caster->GetZone();
  1252. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1253. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1254. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1255. float distance = caster->GetDistance(target, true);
  1256. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1257. }
  1258. }
  1259. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1260. success = true;
  1261. }
  1262. if (success) {
  1263. if (caster->GetZone())
  1264. caster->GetZone()->TriggerCharSheetTimer();
  1265. }
  1266. }
  1267. return 0;
  1268. }
  1269. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1270. if (!lua_interface)
  1271. return 0;
  1272. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1273. if(!luaspell || luaspell->resisted) {
  1274. return 0;
  1275. }
  1276. Spawn* caster = luaspell->caster;
  1277. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1278. float percentage = lua_interface->GetFloatValue(state, 2);
  1279. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1280. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1281. Spawn* target = lua_interface->GetSpawn(state, 5);
  1282. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1283. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1284. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1285. lua_interface->ResetFunctionStack(state);
  1286. boost::to_lower(heal_type);
  1287. int32 min_heal = 0, max_heal = 0;
  1288. if (caster && caster->IsEntity() && target) {
  1289. if(percentage <= 0.0f)
  1290. {
  1291. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1292. return 0;
  1293. }
  1294. if(heal_type == "power")
  1295. {
  1296. if(current_value)
  1297. {
  1298. if(caster_value)
  1299. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1300. else
  1301. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1302. }
  1303. else
  1304. {
  1305. if(caster_value)
  1306. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1307. else
  1308. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(current_value)
  1314. {
  1315. if(caster_value)
  1316. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1317. else
  1318. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1319. }
  1320. else
  1321. {
  1322. if(caster_value)
  1323. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1324. else
  1325. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1326. }
  1327. }
  1328. bool success = false;
  1329. luaspell->resisted = false;
  1330. if (target) {
  1331. float distance = caster->GetDistance(target, true);
  1332. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1333. success = true;
  1334. }
  1335. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1336. Spawn* target = 0;
  1337. ZoneServer* zone = luaspell->caster->GetZone();
  1338. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1339. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1340. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1341. float distance = caster->GetDistance(target, true);
  1342. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1343. }
  1344. }
  1345. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1346. success = true;
  1347. }
  1348. if (success) {
  1349. if (caster->GetZone())
  1350. caster->GetZone()->TriggerCharSheetTimer();
  1351. }
  1352. }
  1353. return 0;
  1354. }
  1355. int EQ2Emu_lua_AddItem(lua_State* state) {
  1356. if (!lua_interface)
  1357. return 0;
  1358. Spawn* spawn = lua_interface->GetSpawn(state);
  1359. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1360. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1361. lua_interface->ResetFunctionStack(state);
  1362. // default of 1 quantity to add
  1363. if (quantity == 0)
  1364. quantity = 1;
  1365. if (spawn && spawn->IsPlayer()) {
  1366. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1367. if (client && item_id > 0) {
  1368. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1369. return 1;
  1370. }
  1371. }
  1372. lua_interface->SetBooleanValue(state, false);
  1373. return 1;
  1374. }
  1375. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1376. if (!lua_interface)
  1377. return 0;
  1378. Spawn* spawn = lua_interface->GetSpawn(state);
  1379. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1380. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1381. string location = lua_interface->GetStringValue(state, 4);
  1382. int16 item_count = lua_interface->GetInt16Value(state,5);
  1383. //devn00b: if we dont have a count, assume 1 item.
  1384. if(!item_count) {
  1385. item_count = 1;
  1386. }
  1387. lua_interface->ResetFunctionStack(state);
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1390. if (client && item_id > 0) {
  1391. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1392. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1393. else
  1394. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1395. if (send_messages) {
  1396. Item* item = master_item_list.GetItem(item_id);
  1397. if (item) {
  1398. if(item_count > 1) {
  1399. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1400. string popup_text1 = "You receive "+ item_count;
  1401. string popup_text2 = " " + item->name;
  1402. string popup_text = popup_text1 + popup_text2;
  1403. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1404. // return 1;
  1405. } else {
  1406. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1407. string popup_text = "You receive " + item->name;
  1408. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1409. }
  1410. }
  1411. }
  1412. return 1;
  1413. }
  1414. }
  1415. lua_interface->SetBooleanValue(state, false);
  1416. return 1;
  1417. }
  1418. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1419. Spawn* spawn = lua_interface->GetSpawn(state);
  1420. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1421. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1422. lua_interface->ResetFunctionStack(state);
  1423. // default of 1 to remove
  1424. if (quantity == 0)
  1425. quantity = 1;
  1426. Client* client;
  1427. Item* item;
  1428. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1429. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1430. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1431. if (client->RemoveItem(item, quantity)) {
  1432. lua_interface->SetBooleanValue(state, true);
  1433. return 1;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_HasItem(lua_State* state) {
  1442. Spawn* player = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. if (player && player->IsPlayer()) {
  1447. bool hasItem = false;
  1448. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1449. if (!hasItem)
  1450. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1451. lua_interface->SetBooleanValue(state, hasItem);
  1452. return 1;
  1453. }
  1454. lua_interface->SetBooleanValue(state, false);
  1455. return 1;
  1456. }
  1457. int EQ2Emu_lua_Spawn(lua_State* state) {
  1458. if (!lua_interface)
  1459. return 0;
  1460. ZoneServer* zone = lua_interface->GetZone(state);
  1461. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1462. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1463. float x = lua_interface->GetFloatValue(state, 4);
  1464. float y = lua_interface->GetFloatValue(state, 5);
  1465. float z = lua_interface->GetFloatValue(state, 6);
  1466. float heading = lua_interface->GetFloatValue(state, 7);
  1467. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1468. Spawn* spawn = zone->GetSpawn(spawn_id);
  1469. if (!spawn)
  1470. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1471. else {
  1472. spawn->SetX(x);
  1473. spawn->SetZ(z);
  1474. spawn->SetY(y,true,true);
  1475. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1476. spawn->SetHeading(heading);
  1477. if (restricted_npc)
  1478. spawn->AddAllowAccessSpawn(spawn);
  1479. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1480. bool scriptActive = false;
  1481. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1482. scriptActive = true;
  1483. spawn->SetSpawnScript(string(spawn_script));
  1484. }
  1485. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1486. zone->AddSpawn(spawn);
  1487. if (scriptActive) {
  1488. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1489. }
  1490. lua_interface->ResetFunctionStack(state);
  1491. lua_interface->SetSpawnValue(state, spawn);
  1492. return 1;
  1493. }
  1494. }
  1495. else {
  1496. string output = "Invalid paramaters to LUA Spawn command: \n";
  1497. if (!zone)
  1498. output = output.append("\t").append("Missing zone reference. \n");
  1499. if (spawn_id == 0)
  1500. output = output.append("\t").append("Missing spawn_id.");
  1501. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1502. }
  1503. lua_interface->ResetFunctionStack(state);
  1504. return 0;
  1505. }
  1506. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1507. if (!lua_interface)
  1508. return 0;
  1509. ZoneServer* zone = lua_interface->GetZone(state);
  1510. lua_interface->ResetFunctionStack(state);
  1511. if (zone) {
  1512. lua_interface->SetStringValue(state, zone->GetZoneName());
  1513. return 1;
  1514. }
  1515. return 0;
  1516. }
  1517. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1518. if (!lua_interface)
  1519. return 0;
  1520. ZoneServer* zone = lua_interface->GetZone(state);
  1521. lua_interface->ResetFunctionStack(state);
  1522. if (zone) {
  1523. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1524. return 1;
  1525. }
  1526. return 0;
  1527. }
  1528. int EQ2Emu_lua_GetZone(lua_State* state) {
  1529. if (!lua_interface)
  1530. return 0;
  1531. int32 zone_id = lua_interface->GetInt32Value(state);
  1532. ZoneServer* zone = 0;
  1533. if (zone_id > 0)
  1534. zone = zone_list.Get(zone_id);
  1535. else {
  1536. string zone_name = lua_interface->GetStringValue(state);
  1537. if (zone_name.length() > 0) {
  1538. zone = zone_list.Get(zone_name.c_str());
  1539. }
  1540. else {
  1541. Spawn* spawn = lua_interface->GetSpawn(state);
  1542. if (spawn)
  1543. zone = spawn->GetZone();
  1544. }
  1545. }
  1546. lua_interface->ResetFunctionStack(state);
  1547. if (zone) {
  1548. lua_interface->SetZoneValue(state, zone);
  1549. return 1;
  1550. }
  1551. return 0;
  1552. }
  1553. int EQ2Emu_lua_AddHate(lua_State* state) {
  1554. Spawn* entity = lua_interface->GetSpawn(state);
  1555. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1556. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1557. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1558. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1559. if(!luaspell || luaspell->resisted) {
  1560. return 0;
  1561. }
  1562. if (entity && entity->IsEntity() && amount != 0) {
  1563. if (luaspell) {
  1564. ZoneServer* zone = luaspell->caster->GetZone();
  1565. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1566. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1567. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1568. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1569. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1570. if (send_packet)
  1571. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1572. }
  1573. }
  1574. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1575. }
  1576. else if (npc && npc->IsNPC() && npc->GetZone())
  1577. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1578. }
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. int EQ2Emu_lua_Zone(lua_State* state) {
  1583. if (!lua_interface)
  1584. return 0;
  1585. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1586. ZoneServer* zone = lua_interface->GetZone(state);
  1587. Spawn* player = lua_interface->GetSpawn(state, 2);
  1588. Client* client = 0;
  1589. if (player && player->IsPlayer())
  1590. client = player->GetZone()->GetClientBySpawn(player);
  1591. float x = lua_interface->GetFloatValue(state, 3);
  1592. float y = lua_interface->GetFloatValue(state, 4);
  1593. float z = lua_interface->GetFloatValue(state, 5);
  1594. float heading = lua_interface->GetFloatValue(state, 6);
  1595. if (zone && client) {
  1596. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1597. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1598. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1599. {
  1600. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1601. return 0;
  1602. }
  1603. if (x != 0 || y != 0 || z != 0) {
  1604. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1605. player->SetX(x);
  1606. player->SetY(y);
  1607. player->SetZ(z);
  1608. player->SetHeading(heading);
  1609. client->Zone(zone->GetZoneName(), false);
  1610. }
  1611. else
  1612. client->Zone(zone->GetZoneName());
  1613. }
  1614. else
  1615. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1616. lua_interface->ResetFunctionStack(state);
  1617. return 0;
  1618. }
  1619. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1620. if (!lua_interface)
  1621. return 0;
  1622. Spawn* spawn = lua_interface->GetSpawn(state);
  1623. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1624. if (spawn && spawn2)
  1625. spawn->AddAllowAccessSpawn(spawn2);
  1626. lua_interface->ResetFunctionStack(state);
  1627. return 0;
  1628. }
  1629. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1630. if (!lua_interface)
  1631. return 0;
  1632. Spawn* target = lua_interface->GetSpawn(state);
  1633. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1634. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1635. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1636. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1637. lua_interface->ResetFunctionStack(state);
  1638. if (!target) {
  1639. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1640. return 0;
  1641. }
  1642. if (!target->IsEntity()) {
  1643. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1644. return 0;
  1645. }
  1646. if (spell_id <= 0) {
  1647. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1648. return 0;
  1649. }
  1650. if (caster && !caster->IsEntity()) {
  1651. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1652. return 0;
  1653. }
  1654. if (spell_tier == 0)
  1655. spell_tier = 1;
  1656. if (!caster)
  1657. caster = target;
  1658. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1659. return 0;
  1660. }
  1661. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1662. if (!lua_interface)
  1663. return 0;
  1664. Spawn* target = lua_interface->GetSpawn(state);
  1665. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1666. if(!luaspell || luaspell->resisted) {
  1667. return 0;
  1668. }
  1669. Spawn* caster = luaspell->caster;
  1670. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1671. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1672. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1673. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1674. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1675. //lua_interface->ResetFunctionStack(state);
  1676. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1677. vector<int16> faction_req;
  1678. vector<int16> race_req;
  1679. int32 class_req = 0;
  1680. int32 i = 0;
  1681. int8 f = 0;
  1682. int8 r = 0;
  1683. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1684. if (class_id < 100) {
  1685. class_req += pow(2.0, double(class_id - 1));
  1686. }
  1687. else if (class_id > 100 && class_id < 1000) {
  1688. race_req.push_back(class_id);
  1689. r++;
  1690. }
  1691. else {
  1692. faction_req.push_back(class_id);
  1693. f++;
  1694. }
  1695. i++;
  1696. }
  1697. lua_interface->ResetFunctionStack(state);
  1698. if (caster && caster->IsEntity()) {
  1699. bool race_match = false;
  1700. bool success = false;
  1701. luaspell->resisted = false;
  1702. if (luaspell->targets.size() > 0) {
  1703. ZoneServer* zone = luaspell->caster->GetZone();
  1704. Spawn* target = 0;
  1705. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1706. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1707. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1708. if (race_req.size() > 0) {
  1709. for (int8 i = 0; i < race_req.size(); i++) {
  1710. if (target->GetLuaRaceId() == race_req[i]) {
  1711. race_match = true;
  1712. }
  1713. }
  1714. }
  1715. else
  1716. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1717. if (race_match == true) {
  1718. float distance = caster->GetDistance(target, true);
  1719. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1720. }
  1721. }
  1722. }
  1723. success = true;
  1724. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1725. }
  1726. else if (target) {
  1727. //check class and race/faction here
  1728. if (race_req.size() > 0) {
  1729. for (int8 i = 0; i < race_req.size(); i++) {
  1730. if (target->GetLuaRaceId() == race_req[i]) {
  1731. race_match = true;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1737. if (race_match == true) {
  1738. float distance = caster->GetDistance(target, true);
  1739. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1740. success = true;
  1741. }
  1742. }
  1743. if (success) {
  1744. Spell* spell = luaspell->spell;
  1745. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1746. ((Player*)caster)->InCombat(true);
  1747. if (caster->GetZone())
  1748. caster->GetZone()->TriggerCharSheetTimer();
  1749. }
  1750. }
  1751. }
  1752. return 0;
  1753. }
  1754. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1755. if (!lua_interface)
  1756. return 0;
  1757. Spawn* spawn = lua_interface->GetSpawn(state);
  1758. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1759. lua_interface->ResetFunctionStack(state);
  1760. if (spawn && value != 0) {
  1761. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1762. spawn->SetPower(spawn->GetTotalPower());
  1763. else
  1764. spawn->SetPower(spawn->GetPower() + value);
  1765. }
  1766. return 0;
  1767. }
  1768. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1769. if (!lua_interface)
  1770. return 0;
  1771. Spawn* spawn = lua_interface->GetSpawn(state);
  1772. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1773. lua_interface->ResetFunctionStack(state);
  1774. if (spawn && value != 0) {
  1775. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1776. spawn->SetHP(spawn->GetTotalHP());
  1777. else
  1778. spawn->SetHP(spawn->GetHP() + value);
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1787. lua_interface->ResetFunctionStack(state);
  1788. if (spawn && value != 0) {
  1789. spawn->SetPower(spawn->GetPower() + value);
  1790. if (value > spawn->GetTotalHPBase())
  1791. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1792. }
  1793. return 0;
  1794. }
  1795. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1796. if (!lua_interface)
  1797. return 0;
  1798. Spawn* spawn = lua_interface->GetSpawn(state);
  1799. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1800. lua_interface->ResetFunctionStack(state);
  1801. if (spawn && value != 0) {
  1802. spawn->SetHP(spawn->GetHP() + value);
  1803. if (value > spawn->GetTotalHPBase())
  1804. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1805. }
  1806. return 0;
  1807. }
  1808. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1809. if (!lua_interface)
  1810. return 0;
  1811. Spawn* spawn = lua_interface->GetSpawn(state);
  1812. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1813. lua_interface->ResetFunctionStack(state);
  1814. if (spawn) {
  1815. spawn->SetHP(value);
  1816. if (value > spawn->GetTotalHPBase())
  1817. spawn->SetTotalHP(value);
  1818. }
  1819. return 0;
  1820. }
  1821. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1822. if (!lua_interface)
  1823. return 0;
  1824. Spawn* spawn = lua_interface->GetSpawn(state);
  1825. float value = lua_interface->GetFloatValue(state, 2);
  1826. lua_interface->ResetFunctionStack(state);
  1827. if (spawn && spawn->IsEntity() && value > 0)
  1828. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1829. if (spawn->IsPlayer())
  1830. ((Player*)spawn)->SetCharSheetChanged(true);
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1838. lua_interface->ResetFunctionStack(state);
  1839. if (spawn && spawn->IsEntity() && value > 0)
  1840. ((Entity*)spawn)->SetTotalHPBase(value);
  1841. return 0;
  1842. }
  1843. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1844. if (!lua_interface)
  1845. return 0;
  1846. Spawn* spawn = lua_interface->GetSpawn(state);
  1847. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1848. lua_interface->ResetFunctionStack(state);
  1849. if (spawn && value > 0) {
  1850. spawn->SetPower(value);
  1851. if (value > spawn->GetTotalPowerBase())
  1852. spawn->SetTotalPower(value);
  1853. }
  1854. return 0;
  1855. }
  1856. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1857. if (!lua_interface)
  1858. return 0;
  1859. Spawn* spawn = lua_interface->GetSpawn(state);
  1860. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1861. lua_interface->ResetFunctionStack(state);
  1862. if (spawn && spawn->IsEntity() && value > 0)
  1863. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1864. return 0;
  1865. }
  1866. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1867. if (!lua_interface)
  1868. return 0;
  1869. Spawn* spawn = lua_interface->GetSpawn(state);
  1870. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1871. lua_interface->ResetFunctionStack(state);
  1872. if (spawn && spawn->IsEntity() && value > 0)
  1873. ((Entity*)spawn)->SetTotalPowerBase(value);
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. float x = lua_interface->GetFloatValue(state, 2);
  1881. float y = lua_interface->GetFloatValue(state, 3);
  1882. float z = lua_interface->GetFloatValue(state, 4);
  1883. float heading = lua_interface->GetFloatValue(state, 5);
  1884. lua_interface->ResetFunctionStack(state);
  1885. if (spawn) {
  1886. spawn->SetX(x);
  1887. spawn->SetY(y);
  1888. spawn->SetZ(z);
  1889. if (heading != 0)
  1890. spawn->SetHeading(heading);
  1891. spawn->SetSpawnOrigX(spawn->GetX());
  1892. spawn->SetSpawnOrigY(spawn->GetY());
  1893. spawn->SetSpawnOrigZ(spawn->GetZ());
  1894. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1895. if (spawn->IsPlayer()) {
  1896. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1897. if (client) {
  1898. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1899. client->QueuePacket(packet);
  1900. }
  1901. }
  1902. }
  1903. return 0;
  1904. }
  1905. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1906. if (!lua_interface)
  1907. return 0;
  1908. Spawn* spawn = lua_interface->GetSpawn(state);
  1909. float value = lua_interface->GetFloatValue(state, 2);
  1910. lua_interface->ResetFunctionStack(state);
  1911. if (spawn) {
  1912. spawn->SetHeading(value);
  1913. if (spawn->IsPlayer()) {
  1914. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1915. if (client) {
  1916. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1917. client->QueuePacket(packet);
  1918. }
  1919. }
  1920. }
  1921. return 0;
  1922. }
  1923. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1924. if (!lua_interface)
  1925. return 0;
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. int16 value = lua_interface->GetInt16Value(state, 2);
  1928. lua_interface->ResetFunctionStack(state);
  1929. if (spawn)
  1930. spawn->SetModelType(value);
  1931. return 0;
  1932. }
  1933. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1934. if (!lua_interface)
  1935. return 0;
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. int8 value = lua_interface->GetInt8Value(state, 2);
  1938. lua_interface->ResetFunctionStack(state);
  1939. if (spawn) {
  1940. if (spawn->IsPlayer())
  1941. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1942. else
  1943. spawn->SetAdventureClass(value);
  1944. }
  1945. return 0;
  1946. }
  1947. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1948. if (!lua_interface)
  1949. return 0;
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. int8 value = lua_interface->GetInt8Value(state, 2);
  1952. lua_interface->ResetFunctionStack(state);
  1953. if (spawn) {
  1954. spawn->SetTradeskillClass(value);
  1955. if (spawn->IsEntity()) {
  1956. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1957. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1958. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1959. }
  1960. if (spawn->IsPlayer())
  1961. ((Player*)spawn)->SetCharSheetChanged(true);
  1962. }
  1963. return 0;
  1964. }
  1965. int EQ2Emu_lua_SetMount(lua_State* state) {
  1966. if (!lua_interface)
  1967. return 0;
  1968. Spawn* spawn = lua_interface->GetSpawn(state);
  1969. int16 value = lua_interface->GetInt16Value(state, 2);
  1970. if (spawn && spawn->IsEntity()) {
  1971. ((Entity*)spawn)->SetMount(value);
  1972. EQ2_Color color;
  1973. color.red = 255;
  1974. color.green = 255;
  1975. color.blue = 255;
  1976. ((Entity*)spawn)->SetMountColor(&color);
  1977. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1978. }
  1979. return 0;
  1980. }
  1981. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1982. if (!lua_interface)
  1983. return 0;
  1984. Spawn* spawn = lua_interface->GetSpawn(state);
  1985. EQ2_Color mount_color;
  1986. EQ2_Color saddle_color;
  1987. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1988. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1989. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1990. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1991. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1992. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1993. if (spawn && spawn->IsEntity()) {
  1994. ((Entity*)spawn)->SetMountColor(&mount_color);
  1995. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1996. }
  1997. return 0;
  1998. }
  1999. int EQ2Emu_lua_GetMount(lua_State* state) {
  2000. if (!lua_interface)
  2001. return 0;
  2002. Spawn* spawn = lua_interface->GetSpawn(state);
  2003. if (spawn && spawn->IsEntity()) {
  2004. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2005. return 1;
  2006. }
  2007. return 0;
  2008. }
  2009. int EQ2Emu_lua_GetRace(lua_State* state) {
  2010. if (!lua_interface)
  2011. return 0;
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. if (spawn)
  2014. {
  2015. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2016. lua_interface->SetInt32Value(state, spawn->GetRace());
  2017. return 1;
  2018. }
  2019. return 0;
  2020. }
  2021. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2022. if (!lua_interface)
  2023. return 0;
  2024. Spawn* spawn = lua_interface->GetSpawn(state);
  2025. if (spawn) {
  2026. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2027. return 1;
  2028. }
  2029. return 0;
  2030. }
  2031. int EQ2Emu_lua_GetClass(lua_State* state) {
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn) {
  2034. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2040. Spawn* spawn = lua_interface->GetSpawn(state);
  2041. if (spawn) {
  2042. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2043. return 1;
  2044. }
  2045. return 0;
  2046. }
  2047. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2048. if (!lua_interface)
  2049. return 0;
  2050. Spawn* spawn = lua_interface->GetSpawn(state);
  2051. float value = lua_interface->GetFloatValue(state, 2);
  2052. lua_interface->ResetFunctionStack(state);
  2053. if (spawn) {
  2054. spawn->SetSpeed(value);
  2055. if(spawn->IsEntity())
  2056. ((Entity*)spawn)->SetSpeed(value);
  2057. if (spawn->IsPlayer()) {
  2058. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2059. if (client) {
  2060. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2061. if (packet) {
  2062. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2063. packet->setDataByName("speed", value);
  2064. packet->setDataByName("size", 0.51);
  2065. EQ2Packet* app = packet->serialize();
  2066. client->QueuePacket(app);
  2067. safe_delete(packet);
  2068. }
  2069. }
  2070. }
  2071. }
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. const int16 type = lua_interface->GetInt16Value(state, 2);
  2079. const float value = lua_interface->GetFloatValue(state, 3);
  2080. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2081. if(!luaspell || luaspell->resisted) {
  2082. return 0;
  2083. }
  2084. int64 class_req = 0;
  2085. int32 class_id = 0;
  2086. vector<int16> faction_req;
  2087. vector<int16> race_req;
  2088. int32 i = 0;
  2089. int8 f = 0;
  2090. int8 r = 0;
  2091. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2092. if (class_id < 100) {
  2093. class_req += pow(2.0, double(class_id - 1));
  2094. }
  2095. else if (class_id > 100 && class_id < 1000) {
  2096. race_req.push_back(class_id);
  2097. r++;
  2098. }
  2099. else {
  2100. faction_req.push_back(class_id);
  2101. f++;
  2102. }
  2103. i++;
  2104. }
  2105. if (value != 0 && type >= 0) {
  2106. if (luaspell && luaspell->spell && luaspell->caster) {
  2107. ZoneServer* zone = luaspell->caster->GetZone();
  2108. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2109. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2110. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2111. if (target) {
  2112. if (target->IsPlayer()) {
  2113. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2114. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2115. if (((Player*)target)->GetGroupMemberInfo())
  2116. ((Player*)target)->UpdateGroupMemberInfo();
  2117. ((Player*)target)->SetCharSheetChanged(true);
  2118. }
  2119. else if (target->IsNPC())
  2120. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2121. else
  2122. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2123. }
  2124. }
  2125. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2126. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2127. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2128. }
  2129. else if (spawn && spawn->IsEntity()) {
  2130. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2131. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2132. if (spawn->IsPlayer())
  2133. ((Player*)spawn)->SetCharSheetChanged(true);
  2134. }
  2135. else
  2136. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2137. }
  2138. else
  2139. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2140. return 0;
  2141. }
  2142. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2143. if (!lua_interface)
  2144. return 0;
  2145. Spawn* spawn = lua_interface->GetSpawn(state);
  2146. int16 type = lua_interface->GetInt16Value(state, 2);
  2147. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2148. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2149. if (!spawn) {
  2150. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2151. return 0;
  2152. }
  2153. if (!spawn->IsEntity()) {
  2154. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2155. return 0;
  2156. }
  2157. if (value == 0) {
  2158. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2159. return 0;
  2160. }
  2161. if (!luaspell || !luaspell->spell) {
  2162. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2163. return 0;
  2164. }
  2165. if(luaspell->resisted) {
  2166. return 0;
  2167. }
  2168. int32 class_req = 0;
  2169. vector<int16> faction_req;
  2170. vector<int16> race_req;
  2171. int32 class_id = 0;
  2172. int32 i = 0;
  2173. int8 f = 0;
  2174. int8 r = 0;
  2175. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2176. if (class_id < 100) {
  2177. class_req += pow(2.0, double(class_id - 1));
  2178. }
  2179. else if (class_id > 100 && class_id < 1000) {
  2180. race_req.push_back(class_id);
  2181. r++;
  2182. }
  2183. else {
  2184. faction_req.push_back(class_id);
  2185. f++;
  2186. }
  2187. i++;
  2188. }
  2189. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2190. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2191. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2192. if (spawn->IsPlayer())
  2193. ((Player*)spawn)->SetCharSheetChanged(true);
  2194. return 0;
  2195. }
  2196. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2197. if (!lua_interface)
  2198. return 0;
  2199. Spawn* spawn = lua_interface->GetSpawn(state);
  2200. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2201. if (!spawn) {
  2202. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2203. return 0;
  2204. }
  2205. if (!spawn->IsEntity()) {
  2206. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2207. return 0;
  2208. }
  2209. if (!luaspell || !luaspell->spell) {
  2210. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2211. return 0;
  2212. }
  2213. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2214. if (spawn->IsPlayer())
  2215. ((Player*)spawn)->SetCharSheetChanged(true);
  2216. return 0;
  2217. }
  2218. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2219. if (!lua_interface)
  2220. return 0;
  2221. Spawn* spawn = lua_interface->GetSpawn(state);
  2222. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2223. if (luaspell && luaspell->spell) {
  2224. ZoneServer* zone = luaspell->caster->GetZone();
  2225. Spawn* target = 0;
  2226. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2227. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2228. target = zone->GetSpawnByID(luaspell->targets[i]);
  2229. if (target && target->IsEntity()) {
  2230. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2231. if (target->IsPlayer())
  2232. ((Player*)target)->SetCharSheetChanged(true);
  2233. }
  2234. }
  2235. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2236. }
  2237. else if (spawn && spawn->IsEntity()) {
  2238. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2239. if (spawn->IsPlayer())
  2240. ((Player*)spawn)->SetCharSheetChanged(true);
  2241. }
  2242. return 0;
  2243. }
  2244. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2245. if (!lua_interface)
  2246. return 0;
  2247. Spawn* spawn = lua_interface->GetSpawn(state);
  2248. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2249. float value = lua_interface->GetFloatValue(state, 3);
  2250. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2251. if (value != 0) {
  2252. int32 spell_id = 0;
  2253. if (luaspell && luaspell->spell && luaspell->caster) {
  2254. if(luaspell->resisted) {
  2255. return 0;
  2256. }
  2257. spell_id = luaspell->spell->GetSpellID();
  2258. ZoneServer* zone = luaspell->caster->GetZone();
  2259. Spawn* target = 0;
  2260. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2261. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2262. target = zone->GetSpawnByID(luaspell->targets[i]);
  2263. if (target && target->Alive()) {
  2264. if (target->IsPlayer()) {
  2265. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2266. Client* client = target->GetZone()->GetClientBySpawn(target);
  2267. if (client) {
  2268. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2269. if (packet)
  2270. client->QueuePacket(packet);
  2271. }
  2272. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2273. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2274. }
  2275. else if (target->IsNPC()) {
  2276. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2277. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2278. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2279. }
  2280. else
  2281. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2282. }
  2283. }
  2284. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2285. }
  2286. else if (spawn) {
  2287. if (spawn->IsPlayer()) {
  2288. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2289. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2290. if (client) {
  2291. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2292. if (packet)
  2293. client->QueuePacket(packet);
  2294. }
  2295. }
  2296. else if (spawn->IsNPC())
  2297. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2298. else
  2299. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2300. }
  2301. }
  2302. else
  2303. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2304. return 0;
  2305. }
  2306. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2307. if (!lua_interface)
  2308. return 0;
  2309. Spawn* spawn = lua_interface->GetSpawn(state);
  2310. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2311. if (spawn && spawn->IsPlayer()) {
  2312. int32 spell_id = 0;
  2313. if (luaspell && luaspell->spell) {
  2314. if(luaspell->resisted) {
  2315. return 0;
  2316. }
  2317. spell_id = luaspell->spell->GetSpellID();
  2318. ZoneServer* zone = luaspell->caster->GetZone();
  2319. Spawn* target = 0;
  2320. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2321. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2322. target = zone->GetSpawnByID(luaspell->targets[i]);
  2323. if (target) {
  2324. if (target->IsPlayer()) {
  2325. ((Player*)target)->RemoveSkillBonus(spell_id);
  2326. Client* client = target->GetZone()->GetClientBySpawn(target);
  2327. if (client) {
  2328. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2329. if (packet)
  2330. client->QueuePacket(packet);
  2331. }
  2332. }
  2333. else if (target->IsNPC())
  2334. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2335. else
  2336. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2337. }
  2338. }
  2339. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2340. }
  2341. else if (spawn) {
  2342. if (spawn->IsPlayer()) {
  2343. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2344. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2345. if (client) {
  2346. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2347. if (packet)
  2348. client->QueuePacket(packet);
  2349. }
  2350. }
  2351. else if (spawn->IsNPC())
  2352. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2353. else
  2354. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2355. }
  2356. }
  2357. return 0;
  2358. }
  2359. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2360. if (!lua_interface)
  2361. return 0;
  2362. Spawn* spawn = lua_interface->GetSpawn(state);
  2363. int8 type = lua_interface->GetInt32Value(state, 2);
  2364. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2365. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2366. if(luaspell && luaspell->resisted) {
  2367. return 0;
  2368. }
  2369. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2370. ZoneServer* zone = luaspell->caster->GetZone();
  2371. Spawn* target = 0;
  2372. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2373. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2374. target = zone->GetSpawnByID(luaspell->targets[i]);
  2375. if (target && target->IsEntity()) {
  2376. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2377. ((Entity*)target)->AddMezSpell(luaspell);
  2378. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2379. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2384. ((Entity*)target)->AddStifleSpell(luaspell);
  2385. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2386. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2387. if (target->IsNPC())
  2388. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2391. ((Entity*)target)->AddDazeSpell(luaspell);
  2392. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2393. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2394. if (target->IsNPC())
  2395. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2396. }
  2397. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2398. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2399. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2400. ((Entity*)target)->AddStunSpell(luaspell);
  2401. if (target->IsNPC())
  2402. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2403. }
  2404. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2405. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2406. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2407. ((Entity*)target)->AddRootSpell(luaspell);
  2408. if (target->IsNPC())
  2409. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2410. }
  2411. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2414. ((Entity*)target)->AddFearSpell(luaspell);
  2415. if (target->IsNPC())
  2416. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2417. }
  2418. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2419. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2420. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2421. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2422. }
  2423. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2424. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2425. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2426. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2427. }
  2428. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2429. ((Entity*)target)->AddSnareSpell(luaspell);
  2430. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2431. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2432. if (target->IsNPC())
  2433. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2434. }
  2435. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2436. ((Entity*)target)->AddFlightSpell(luaspell);
  2437. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2438. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2439. }
  2440. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2441. ((Entity*)target)->AddGlideSpell(luaspell);
  2442. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2443. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2444. }
  2445. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2446. ((Entity*)target)->AddSafefallSpell(luaspell);
  2447. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2448. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2449. }
  2450. else
  2451. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2452. }
  2453. else
  2454. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2455. }
  2456. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2457. }
  2458. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2459. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2460. ((Entity*)spawn)->AddMezSpell(luaspell);
  2461. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2462. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2463. }
  2464. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2465. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2466. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2467. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2468. }
  2469. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2470. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2471. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2472. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2473. }
  2474. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2475. ((Entity*)spawn)->AddStunSpell(luaspell);
  2476. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2477. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2478. }
  2479. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2480. ((Entity*)spawn)->AddRootSpell(luaspell);
  2481. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2482. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2483. }
  2484. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2485. ((Entity*)spawn)->AddFearSpell(luaspell);
  2486. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2487. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2488. }
  2489. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2490. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2491. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2492. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2493. }
  2494. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2495. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2496. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2497. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2498. }
  2499. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2500. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2501. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2502. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2503. }
  2504. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2505. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2506. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2507. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2508. }
  2509. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2510. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2511. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2512. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2513. }
  2514. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2515. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2516. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2517. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2518. }
  2519. else
  2520. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2521. }
  2522. else
  2523. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2524. return 0;
  2525. }
  2526. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2527. if (!lua_interface)
  2528. return 0;
  2529. Spawn* spawn = lua_interface->GetSpawn(state);
  2530. int8 type = lua_interface->GetInt8Value(state, 2);
  2531. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2532. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2533. if (spawn && spawn->IsEntity()) {
  2534. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2535. ZoneServer* zone = luaspell->caster->GetZone();
  2536. Spawn* target = 0;
  2537. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2538. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2539. target = zone->GetSpawnByID(luaspell->targets[i]);
  2540. if (target) {
  2541. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2542. ((Entity*)target)->RemoveMezSpell(luaspell);
  2543. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2544. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2545. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2546. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2547. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2548. ((Entity*)target)->RemoveStunSpell(luaspell);
  2549. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2550. ((Entity*)target)->RemoveRootSpell(luaspell);
  2551. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2552. ((Entity*)target)->RemoveFearSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2554. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2556. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2558. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2560. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2561. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2562. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2563. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2564. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2565. else
  2566. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2567. }
  2568. }
  2569. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2570. }
  2571. else if (only_remove_spawn) {
  2572. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2573. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2575. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2577. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2579. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2581. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2583. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2585. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2587. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2588. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2589. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2590. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2591. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2592. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2593. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2594. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2595. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2596. else
  2597. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2598. }
  2599. }
  2600. return 0;
  2601. }
  2602. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2603. if (!lua_interface)
  2604. return 0;
  2605. Spawn* spawn = lua_interface->GetSpawn(state);
  2606. int8 type = lua_interface->GetInt8Value(state, 2);
  2607. bool hasEffect = false;
  2608. if (!spawn)
  2609. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2610. else if (!spawn->IsEntity())
  2611. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2612. else if (type < CONTROL_MAX_EFFECTS)
  2613. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2614. else
  2615. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2616. lua_interface->SetBooleanValue(state, hasEffect);
  2617. return 1;
  2618. }
  2619. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2620. if (!lua_interface)
  2621. return 0;
  2622. Spawn* spawn = lua_interface->GetSpawn(state);
  2623. float distance = 0.0f;
  2624. if (!spawn)
  2625. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2626. else if (!spawn->IsNPC())
  2627. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2628. else
  2629. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2630. lua_interface->SetFloatValue(state, distance);
  2631. return 1;
  2632. }
  2633. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. float distance = 0.0f;
  2638. if (!spawn)
  2639. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2640. else if (!spawn->IsNPC())
  2641. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2642. else
  2643. distance = ((NPC*)spawn)->GetAggroRadius();
  2644. lua_interface->SetFloatValue(state, distance);
  2645. return 1;
  2646. }
  2647. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2648. if (!lua_interface)
  2649. return 0;
  2650. Spawn* spawn = lua_interface->GetSpawn(state);
  2651. float distance = lua_interface->GetFloatValue(state, 2);
  2652. bool override = lua_interface->GetBooleanValue(state, 3);
  2653. bool result = false;
  2654. lua_interface->ResetFunctionStack(state);
  2655. if (!spawn)
  2656. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2657. else if (!spawn->IsNPC())
  2658. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2659. else
  2660. {
  2661. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2662. result = true;
  2663. }
  2664. lua_interface->SetBooleanValue(state, result);
  2665. return 1;
  2666. }
  2667. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2668. if (!lua_interface)
  2669. return 0;
  2670. Spawn* spawn = lua_interface->GetSpawn(state);
  2671. int16 value = lua_interface->GetInt16Value(state, 2);
  2672. if (spawn && spawn->IsEntity()) {
  2673. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2674. if (spawn->IsPlayer())
  2675. ((Player*)spawn)->SetCharSheetChanged(true);
  2676. }
  2677. return 0;
  2678. }
  2679. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Spawn* spawn = lua_interface->GetSpawn(state);
  2683. int16 value = lua_interface->GetInt16Value(state, 2);
  2684. if (spawn && spawn->IsEntity()) {
  2685. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2686. if (spawn->IsPlayer())
  2687. ((Player*)spawn)->SetCharSheetChanged(true);
  2688. }
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Spawn* spawn = lua_interface->GetSpawn(state);
  2695. int16 value = lua_interface->GetInt16Value(state, 2);
  2696. if (spawn && spawn->IsEntity()) {
  2697. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2698. if (spawn->IsPlayer())
  2699. ((Player*)spawn)->SetCharSheetChanged(true);
  2700. }
  2701. return 0;
  2702. }
  2703. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2704. if (!lua_interface)
  2705. return 0;
  2706. Spawn* spawn = lua_interface->GetSpawn(state);
  2707. int16 value = lua_interface->GetInt16Value(state, 2);
  2708. if (spawn && spawn->IsEntity()) {
  2709. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2710. if (spawn->IsPlayer())
  2711. ((Player*)spawn)->SetCharSheetChanged(true);
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Spawn* spawn = lua_interface->GetSpawn(state);
  2719. int16 value = lua_interface->GetInt16Value(state, 2);
  2720. if (spawn && spawn->IsEntity()) {
  2721. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2722. if (spawn->IsPlayer())
  2723. ((Player*)spawn)->SetCharSheetChanged(true);
  2724. }
  2725. return 0;
  2726. }
  2727. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2728. if (!lua_interface)
  2729. return 0;
  2730. Spawn* spawn = lua_interface->GetSpawn(state);
  2731. int8 value = lua_interface->GetInt8Value(state, 2);
  2732. if (spawn && spawn->IsEntity()) {
  2733. ((Entity*)spawn)->SetDeity(value);
  2734. if (spawn->IsPlayer())
  2735. ((Player*)spawn)->SetCharSheetChanged(true);
  2736. }
  2737. lua_interface->ResetFunctionStack(state);
  2738. return 0;
  2739. }
  2740. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2741. if (!lua_interface)
  2742. return 0;
  2743. Spawn* spawn = lua_interface->GetSpawn(state);
  2744. if (spawn && spawn->IsEntity()) {
  2745. int8 deity = ((Entity*)spawn)->GetDeity();
  2746. lua_interface->SetInt32Value(state, deity);
  2747. return 1;
  2748. }
  2749. return 0;
  2750. }
  2751. int EQ2Emu_lua_SetInt(lua_State* state) {
  2752. if (!lua_interface)
  2753. return 0;
  2754. Spawn* spawn = lua_interface->GetSpawn(state);
  2755. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2756. if (spawn && spawn->IsEntity()) {
  2757. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2758. if (spawn->IsPlayer())
  2759. ((Player*)spawn)->SetCharSheetChanged(true);
  2760. }
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_SetWis(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. float value = lua_interface->GetFloatValue(state, 2);
  2768. if (spawn && spawn->IsEntity()) {
  2769. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2770. if (spawn->IsPlayer())
  2771. ((Player*)spawn)->SetCharSheetChanged(true);
  2772. }
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_SetSta(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float value = lua_interface->GetFloatValue(state, 2);
  2780. if (spawn && spawn->IsEntity()) {
  2781. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2782. if (spawn->IsPlayer())
  2783. ((Player*)spawn)->SetCharSheetChanged(true);
  2784. }
  2785. return 0;
  2786. }
  2787. int EQ2Emu_lua_SetStr(lua_State* state) {
  2788. if (!lua_interface)
  2789. return 0;
  2790. Spawn* spawn = lua_interface->GetSpawn(state);
  2791. float value = lua_interface->GetFloatValue(state, 2);
  2792. if (spawn && spawn->IsEntity()) {
  2793. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2794. if (spawn->IsPlayer())
  2795. ((Player*)spawn)->SetCharSheetChanged(true);
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. float value = lua_interface->GetFloatValue(state, 2);
  2804. if (spawn && spawn->IsEntity()) {
  2805. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2806. if (spawn->IsPlayer())
  2807. ((Player*)spawn)->SetCharSheetChanged(true);
  2808. }
  2809. return 0;
  2810. }
  2811. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2812. if (!lua_interface)
  2813. return 0;
  2814. Spawn* spawn = lua_interface->GetSpawn(state);
  2815. if (spawn) {
  2816. lua_interface->SetInt32Value(state, spawn->GetHP());
  2817. return 1;
  2818. }
  2819. return 0;
  2820. }
  2821. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2822. if (!lua_interface)
  2823. return 0;
  2824. Spawn* spawn = lua_interface->GetSpawn(state);
  2825. if (spawn) {
  2826. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2827. return 1;
  2828. }
  2829. return 0;
  2830. }
  2831. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2832. if (!lua_interface)
  2833. return 0;
  2834. Spawn* spawn = lua_interface->GetSpawn(state);
  2835. if (spawn) {
  2836. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2837. return 1;
  2838. }
  2839. return 0;
  2840. }
  2841. int EQ2Emu_lua_GetName(lua_State* state) {
  2842. if (!lua_interface)
  2843. return 0;
  2844. Spawn* spawn = lua_interface->GetSpawn(state);
  2845. if (spawn) {
  2846. lua_interface->SetStringValue(state, spawn->GetName());
  2847. return 1;
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn) {
  2854. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn) {
  2864. lua_interface->SetInt32Value(state, spawn->GetPower());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn) {
  2874. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2880. if (!lua_interface)
  2881. return 0;
  2882. Spawn* spawn = lua_interface->GetSpawn(state);
  2883. if (spawn) {
  2884. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2885. return 1;
  2886. }
  2887. return 0;
  2888. }
  2889. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2890. if (!lua_interface)
  2891. return 0;
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2894. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2895. if (spawn && spawn2) {
  2896. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2897. lua_interface->SetFloatValue(state, distance);
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetX(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn) {
  2907. lua_interface->SetFloatValue(state, spawn->GetX());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetY(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. if (spawn) {
  2917. lua_interface->SetFloatValue(state, spawn->GetY());
  2918. return 1;
  2919. }
  2920. return 0;
  2921. }
  2922. int EQ2Emu_lua_GetZ(lua_State* state) {
  2923. if (!lua_interface)
  2924. return 0;
  2925. Spawn* spawn = lua_interface->GetSpawn(state);
  2926. if (spawn) {
  2927. lua_interface->SetFloatValue(state, spawn->GetZ());
  2928. return 1;
  2929. }
  2930. return 0;
  2931. }
  2932. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2933. if (!lua_interface)
  2934. return 0;
  2935. Spawn* spawn = lua_interface->GetSpawn(state);
  2936. if (spawn) {
  2937. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. if (spawn) {
  2947. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Spawn* spawn = lua_interface->GetSpawn(state);
  2956. if (spawn) {
  2957. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* spawn = lua_interface->GetSpawn(state);
  2966. if (spawn && spawn->IsEntity()) {
  2967. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2968. return 1;
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetInt(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn && spawn->IsEntity()) {
  2977. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetWis(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn && spawn->IsEntity()) {
  2987. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetSta(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn && spawn->IsEntity()) {
  2997. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetStr(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn && spawn->IsEntity()) {
  3007. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3013. if (!lua_interface)
  3014. return 0;
  3015. Spawn* spawn = lua_interface->GetSpawn(state);
  3016. if (spawn && spawn->IsEntity()) {
  3017. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3018. return 1;
  3019. }
  3020. return 0;
  3021. }
  3022. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3023. if (!lua_interface)
  3024. return 0;
  3025. Spawn* spawn = lua_interface->GetSpawn(state);
  3026. if (spawn && spawn->IsEntity()) {
  3027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3028. return 1;
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Spawn* spawn = lua_interface->GetSpawn(state);
  3036. if (spawn && spawn->IsEntity()) {
  3037. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3038. return 1;
  3039. }
  3040. return 0;
  3041. }
  3042. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3043. if (!lua_interface)
  3044. return 0;
  3045. Spawn* spawn = lua_interface->GetSpawn(state);
  3046. if (spawn && spawn->IsEntity()) {
  3047. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3048. return 1;
  3049. }
  3050. return 0;
  3051. }
  3052. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3053. if (!lua_interface)
  3054. return 0;
  3055. Spawn* spawn = lua_interface->GetSpawn(state);
  3056. if (spawn && spawn->IsEntity()) {
  3057. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3058. return 1;
  3059. }
  3060. return 0;
  3061. }
  3062. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3063. if (!lua_interface)
  3064. return 0;
  3065. Spawn* spawn = lua_interface->GetSpawn(state);
  3066. if (spawn && spawn->IsEntity()) {
  3067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3068. return 1;
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Spawn* player = lua_interface->GetSpawn(state);
  3076. if (!player || !player->IsPlayer()) {
  3077. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3078. return 0;
  3079. }
  3080. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3081. if (quest_id <= 0) {
  3082. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3083. return 0;
  3084. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3085. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3086. return 0;
  3087. }
  3088. int32 step = lua_interface->GetInt32Value(state, 3);
  3089. if (step > 0) {
  3090. Client* client = player->GetZone()->GetClientBySpawn(player);
  3091. if (client)
  3092. client->AddPendingQuestUpdate(quest_id, step);
  3093. } else {
  3094. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3099. Spawn* player = lua_interface->GetSpawn(state);
  3100. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3101. int32 step = lua_interface->GetInt32Value(state, 3);
  3102. int32 progress = lua_interface->GetInt32Value(state, 4);
  3103. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3104. Client* client = player->GetZone()->GetClientBySpawn(player);
  3105. if (client)
  3106. client->AddPendingQuestUpdate(quest_id, step, progress);
  3107. }
  3108. return 0;
  3109. }
  3110. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3111. if (!lua_interface)
  3112. return 0;
  3113. Spawn* player = lua_interface->GetSpawn(state);
  3114. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3115. if (player && player->IsPlayer() && quest_id > 0) {
  3116. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* player = lua_interface->GetSpawn(state);
  3125. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3126. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3127. if (player && player->IsPlayer() && quest_id > 0) {
  3128. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3129. return 1;
  3130. }
  3131. return 0;
  3132. }
  3133. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Spawn* player = lua_interface->GetSpawn(state);
  3137. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3138. if (player && player->IsPlayer() && quest_id > 0) {
  3139. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3140. return 1;
  3141. }
  3142. return 0;
  3143. }
  3144. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3145. if (!lua_interface)
  3146. return 0;
  3147. Quest* quest = lua_interface->GetQuest(state);
  3148. string name = lua_interface->GetStringValue(state, 2);
  3149. string type = lua_interface->GetStringValue(state, 3);
  3150. string zone = lua_interface->GetStringValue(state, 4);
  3151. int16 level = lua_interface->GetInt16Value(state, 5);
  3152. string description = lua_interface->GetStringValue(state, 6);
  3153. bool load = true;
  3154. if (!quest) {
  3155. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3156. load = false;
  3157. }
  3158. if (load && name.length() == 0) {
  3159. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3160. load = false;
  3161. }
  3162. if (load && type.length() == 0) {
  3163. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3164. load = false;
  3165. }
  3166. if (load && zone.length() == 0) {
  3167. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3168. load = false;
  3169. }
  3170. if (load && description.length() == 0) {
  3171. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3172. load = false;
  3173. }
  3174. if (load && level == 0) {
  3175. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3176. load = false;
  3177. }
  3178. if (load)
  3179. quest->RegisterQuest(name, type, zone, level, description);
  3180. return 0;
  3181. }
  3182. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3183. if (!lua_interface)
  3184. return 0;
  3185. Quest* quest = lua_interface->GetQuest(state);
  3186. if (quest) {
  3187. int8 level = lua_interface->GetInt16Value(state, 2);
  3188. quest->SetPrereqLevel(level);
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Quest* quest = lua_interface->GetQuest(state);
  3196. if (quest) {
  3197. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3198. quest->AddPrereqQuest(quest_id);
  3199. }
  3200. return 0;
  3201. }
  3202. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3203. if (!lua_interface)
  3204. return 0;
  3205. Quest* quest = lua_interface->GetQuest(state);
  3206. if (quest) {
  3207. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3208. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3209. if (quantity == 0)
  3210. quantity = 1;
  3211. Item* master_item = master_item_list.GetItem(item_id);
  3212. if (master_item) {
  3213. Item* item = new Item(master_item);
  3214. item->details.count = quantity;
  3215. quest->AddPrereqItem(item);
  3216. }
  3217. }
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Spawn* player = lua_interface->GetSpawn(state);
  3224. if(!player || !player->IsPlayer()) {
  3225. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3226. return 0;
  3227. }
  3228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3229. if (quest_id > 0) {
  3230. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3231. return 1;
  3232. } else {
  3233. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3234. }
  3235. return 0;
  3236. }
  3237. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3238. if (!lua_interface)
  3239. return 0;
  3240. Quest* quest = lua_interface->GetQuest(state);
  3241. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3242. lua_interface->ResetFunctionStack(state);
  3243. if (quest && spawn_id > 0)
  3244. quest->SetQuestReturnNPC(spawn_id);
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Spawn* spawn = lua_interface->GetSpawn(state);
  3251. int32 time = lua_interface->GetInt32Value(state, 2);
  3252. string function = lua_interface->GetStringValue(state, 3);
  3253. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3254. Spawn* player = lua_interface->GetSpawn(state, 5);
  3255. lua_interface->ResetFunctionStack(state);
  3256. if (!spawn) {
  3257. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3258. return 0;
  3259. }
  3260. if (time <= 0) {
  3261. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3262. return 0;
  3263. }
  3264. if (function.length() == 0) {
  3265. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3266. return 0;
  3267. }
  3268. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3269. if ( time < 10)
  3270. time = 10;
  3271. timer->timer = Timer::GetCurrentTime2() + time;
  3272. timer->function = function;
  3273. timer->spawn = spawn->GetID();
  3274. timer->player = player ? player->GetID() : 0;
  3275. if (max_count == 0)
  3276. max_count = 1;
  3277. timer->max_count = max_count;
  3278. timer->current_count = 0;
  3279. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3280. return 0;
  3281. }
  3282. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3283. if (!lua_interface)
  3284. return 0;
  3285. Spawn* spawn = lua_interface->GetSpawn(state);
  3286. string function = lua_interface->GetStringValue(state, 2);
  3287. lua_interface->ResetFunctionStack(state);
  3288. if (!spawn) {
  3289. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3290. return 0;
  3291. }
  3292. if(!spawn->GetZone()) {
  3293. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3294. return 0;
  3295. }
  3296. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3297. return 0;
  3298. }
  3299. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3300. if (!lua_interface)
  3301. return 0;
  3302. Spawn* player = lua_interface->GetSpawn(state);
  3303. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3304. lua_interface->ResetFunctionStack(state);
  3305. if (player && player->IsPlayer() && quest_id > 0) {
  3306. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3307. return 1;
  3308. }
  3309. return 0;
  3310. }
  3311. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3312. if (!lua_interface)
  3313. return 0;
  3314. Spawn* player = lua_interface->GetSpawn(state);
  3315. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3316. lua_interface->ResetFunctionStack(state);
  3317. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3318. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3319. if (quest)
  3320. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3321. return 1;
  3322. }
  3323. return 0;
  3324. }
  3325. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3326. if (!lua_interface)
  3327. return 0;
  3328. Spawn* player = lua_interface->GetSpawn(state);
  3329. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3330. lua_interface->ResetFunctionStack(state);
  3331. if (player && player->IsPlayer() && quest_id > 0) {
  3332. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3333. return 1;
  3334. }
  3335. return 0;
  3336. }
  3337. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3338. if (!lua_interface)
  3339. return 0;
  3340. Spawn* npc = lua_interface->GetSpawn(state);
  3341. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3342. lua_interface->ResetFunctionStack(state);
  3343. if (npc && !npc->IsPlayer() && quest_id > 0)
  3344. npc->AddProvidedQuest(quest_id);
  3345. return 0;
  3346. }
  3347. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3348. if (!lua_interface)
  3349. return 0;
  3350. Spawn* npc = lua_interface->GetSpawn(state);
  3351. Spawn* player = lua_interface->GetSpawn(state, 2);
  3352. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3353. bool forced = lua_interface->GetBooleanValue(state, 4);
  3354. lua_interface->ResetFunctionStack(state);
  3355. /* NPC is allowed to be null */
  3356. if (player && player->IsPlayer() && quest_id > 0) {
  3357. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3358. if (master_quest) {
  3359. Client* client = player->GetZone()->GetClientBySpawn(player);
  3360. if (!client) {
  3361. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3362. }
  3363. Quest* quest = new Quest(master_quest);
  3364. if (!quest) {
  3365. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3366. }
  3367. if (client && quest) {
  3368. if (npc)
  3369. quest->SetQuestGiver(npc->GetDatabaseID());
  3370. else
  3371. quest->SetQuestGiver(0);
  3372. client->AddPendingQuest(quest, forced);
  3373. }
  3374. }
  3375. else {
  3376. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3377. }
  3378. }
  3379. else {
  3380. 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);
  3381. }
  3382. return 0;
  3383. }
  3384. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3385. if (!lua_interface)
  3386. return 0;
  3387. Quest* quest = lua_interface->GetQuest(state);
  3388. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3389. lua_interface->ResetFunctionStack(state);
  3390. if (quest) {
  3391. quest->AddPrereqClass(class_id);
  3392. }
  3393. return 0;
  3394. }
  3395. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3396. if (!lua_interface)
  3397. return 0;
  3398. Quest* quest = lua_interface->GetQuest(state);
  3399. int8 race = lua_interface->GetInt8Value(state, 2);
  3400. lua_interface->ResetFunctionStack(state);
  3401. if (quest) {
  3402. quest->AddPrereqRace(race);
  3403. }
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest) {
  3413. quest->AddPrereqModelType(model_type);
  3414. }
  3415. return 0;
  3416. }
  3417. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3418. if (!lua_interface)
  3419. return 0;
  3420. Quest* quest = lua_interface->GetQuest(state);
  3421. int8 level = lua_interface->GetInt8Value(state, 2);
  3422. lua_interface->ResetFunctionStack(state);
  3423. if (!quest) {
  3424. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3425. return 0;
  3426. }
  3427. quest->SetPrereqTSLevel(level);
  3428. return 0;
  3429. }
  3430. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3431. if (!lua_interface)
  3432. return 0;
  3433. Quest* quest = lua_interface->GetQuest(state);
  3434. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3435. lua_interface->ResetFunctionStack(state);
  3436. if (!quest) {
  3437. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3438. return 0;
  3439. }
  3440. quest->AddPrereqTradeskillClass(class_id);
  3441. return 0;
  3442. }
  3443. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3444. if (!lua_interface)
  3445. return 0;
  3446. Quest* quest = lua_interface->GetQuest(state);
  3447. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3448. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3449. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3450. lua_interface->ResetFunctionStack(state);
  3451. if (quest) {
  3452. quest->AddPrereqFaction(faction_id, min, max);
  3453. }
  3454. return 0;
  3455. }
  3456. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3457. if (!lua_interface)
  3458. return 0;
  3459. Quest* quest = lua_interface->GetQuest(state);
  3460. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3461. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3462. lua_interface->ResetFunctionStack(state);
  3463. if (quest) {
  3464. if (quantity == 0)
  3465. quantity = 1;
  3466. Item* master_item = master_item_list.GetItem(item_id);
  3467. if (master_item) {
  3468. Item* item = new Item(master_item);
  3469. item->details.count = quantity;
  3470. quest->AddSelectableRewardItem(item);
  3471. }
  3472. }
  3473. return 0;
  3474. }
  3475. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3476. if (!lua_interface)
  3477. return 0;
  3478. Quest* quest = lua_interface->GetQuest(state);
  3479. if (quest) {
  3480. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3481. vector<Item*>* items = quest->GetRewardItems();
  3482. if (items) {
  3483. vector<Item*>::iterator itr;
  3484. for (itr = items->begin(); itr != items->end(); itr++) {
  3485. if (*itr && (*itr)->details.item_id == item_id) {
  3486. lua_interface->SetBooleanValue(state, true);
  3487. return 1;
  3488. }
  3489. }
  3490. }
  3491. }
  3492. lua_interface->SetBooleanValue(state, false);
  3493. return 1;
  3494. }
  3495. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3500. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3501. lua_interface->ResetFunctionStack(state);
  3502. if (quest) {
  3503. if (quantity == 0)
  3504. quantity = 1;
  3505. Item* master_item = master_item_list.GetItem(item_id);
  3506. if (master_item) {
  3507. Item* item = new Item(master_item);
  3508. item->details.count = quantity;
  3509. quest->AddRewardItem(item);
  3510. }
  3511. }
  3512. return 0;
  3513. }
  3514. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3515. if (!lua_interface)
  3516. return 0;
  3517. Quest* quest = lua_interface->GetQuest(state);
  3518. int32 copper = lua_interface->GetInt32Value(state, 2);
  3519. int32 silver = lua_interface->GetInt32Value(state, 3);
  3520. int32 gold = lua_interface->GetInt32Value(state, 4);
  3521. int32 plat = lua_interface->GetInt32Value(state, 5);
  3522. lua_interface->ResetFunctionStack(state);
  3523. if (quest) {
  3524. quest->AddRewardCoins(copper, silver, gold, plat);
  3525. }
  3526. return 0;
  3527. }
  3528. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3529. if (!lua_interface)
  3530. return 0;
  3531. Quest* quest = lua_interface->GetQuest(state);
  3532. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3533. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3534. lua_interface->ResetFunctionStack(state);
  3535. if (quest && faction_id > 0 && amount != 0)
  3536. quest->AddRewardFaction(faction_id, amount);
  3537. return 0;
  3538. }
  3539. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3540. if (!lua_interface)
  3541. return 0;
  3542. Quest* quest = lua_interface->GetQuest(state);
  3543. int32 status = lua_interface->GetInt32Value(state, 2);
  3544. lua_interface->ResetFunctionStack(state);
  3545. if (quest) {
  3546. quest->SetRewardStatus(status);
  3547. }
  3548. return 0;
  3549. }
  3550. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3551. if (!lua_interface)
  3552. return 0;
  3553. Quest* quest = lua_interface->GetQuest(state);
  3554. int32 status = lua_interface->GetInt32Value(state, 2);
  3555. lua_interface->ResetFunctionStack(state);
  3556. if (quest) {
  3557. quest->SetStatusTmpReward(status);
  3558. }
  3559. return 0;
  3560. }
  3561. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3562. if (!lua_interface)
  3563. return 0;
  3564. Quest* quest = lua_interface->GetQuest(state);
  3565. int64 coins = lua_interface->GetInt64Value(state, 2);
  3566. lua_interface->ResetFunctionStack(state);
  3567. if (quest) {
  3568. quest->SetCoinTmpReward(coins);
  3569. }
  3570. return 0;
  3571. }
  3572. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3573. if (!lua_interface)
  3574. return 0;
  3575. Quest* quest = lua_interface->GetQuest(state);
  3576. string comment = lua_interface->GetStringValue(state, 2);
  3577. lua_interface->ResetFunctionStack(state);
  3578. if (quest) {
  3579. quest->SetRewardComment(comment);
  3580. }
  3581. return 0;
  3582. }
  3583. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3584. if (!lua_interface)
  3585. return 0;
  3586. Quest* quest = lua_interface->GetQuest(state);
  3587. int32 exp = lua_interface->GetInt32Value(state, 2);
  3588. lua_interface->ResetFunctionStack(state);
  3589. if (quest) {
  3590. quest->SetRewardXP(exp);
  3591. }
  3592. return 0;
  3593. }
  3594. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3595. Quest* quest = lua_interface->GetQuest(state);
  3596. int32 step = lua_interface->GetInt32Value(state, 2);
  3597. string description = lua_interface->GetStringValue(state, 3);
  3598. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3599. float percentage = lua_interface->GetFloatValue(state, 5);
  3600. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3601. int16 icon = lua_interface->GetInt16Value(state, 7);
  3602. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3603. if (quest) {
  3604. const char* taskgroup = 0;
  3605. if (str_taskgroup.length() > 0)
  3606. taskgroup = str_taskgroup.c_str();
  3607. int32 id = 0;
  3608. vector<int32>* ids = 0;
  3609. int i = 0;
  3610. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3611. if (ids == 0)
  3612. ids = new vector<int32>;
  3613. ids->push_back(id);
  3614. i++;
  3615. }
  3616. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3617. if (quest_step && icon && quantity > 0)
  3618. quest_step->SetIcon(icon);
  3619. if (quest->GetPlayer()) {
  3620. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3621. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3622. }
  3623. }
  3624. lua_interface->ResetFunctionStack(state);
  3625. return 0;
  3626. }
  3627. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3628. {
  3629. if (!lua_interface)
  3630. return 0;
  3631. Quest* quest = lua_interface->GetQuest(state);
  3632. int32 step = lua_interface->GetInt32Value(state, 2);
  3633. string description = lua_interface->GetStringValue(state, 3);
  3634. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3635. float percentage = lua_interface->GetFloatValue(state, 5);
  3636. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3637. int16 icon = lua_interface->GetInt16Value(state, 7);
  3638. if (quest) {
  3639. const char* taskgroup = 0;
  3640. if (str_taskgroup.length() > 0)
  3641. taskgroup = str_taskgroup.c_str();
  3642. int32 id = 0;
  3643. vector<int32>* ids = 0;
  3644. int i = 0;
  3645. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3646. if (ids == 0)
  3647. ids = new vector<int32>;
  3648. ids->push_back(id);
  3649. i++;
  3650. }
  3651. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3652. if (quest_step && icon > 0 && quantity > 0)
  3653. quest_step->SetIcon(icon);
  3654. if (quest->GetPlayer()) {
  3655. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3656. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3657. }
  3658. safe_delete(ids);
  3659. }
  3660. lua_interface->ResetFunctionStack(state);
  3661. return 0;
  3662. }
  3663. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3664. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3665. }
  3666. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3667. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3668. }
  3669. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3670. if (!lua_interface)
  3671. return 0;
  3672. Quest* quest = lua_interface->GetQuest(state);
  3673. int32 step = lua_interface->GetInt32Value(state, 2);
  3674. string description = lua_interface->GetStringValue(state, 3);
  3675. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3676. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3677. int16 icon = lua_interface->GetInt16Value(state, 6);
  3678. if (quest) {
  3679. const char* taskgroup = 0;
  3680. if (str_taskgroup.length() > 0)
  3681. taskgroup = str_taskgroup.c_str();
  3682. int32 npc_id = 0;
  3683. vector<int32>* ids = 0;
  3684. int i = 0;
  3685. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3686. if (ids == 0)
  3687. ids = new vector<int32>;
  3688. ids->push_back(npc_id);
  3689. i++;
  3690. }
  3691. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3692. if (quest_step && icon > 0)
  3693. quest_step->SetIcon(icon);
  3694. if (quest->GetPlayer()) {
  3695. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3696. if(client)
  3697. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3698. }
  3699. safe_delete(ids);
  3700. }
  3701. lua_interface->ResetFunctionStack(state);
  3702. return 0;
  3703. }
  3704. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3705. if (!lua_interface)
  3706. return 0;
  3707. Quest* quest = lua_interface->GetQuest(state);
  3708. int32 step = lua_interface->GetInt32Value(state, 2);
  3709. string description = lua_interface->GetStringValue(state, 3);
  3710. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3711. float percentage = lua_interface->GetFloatValue(state, 5);
  3712. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3713. int16 icon = lua_interface->GetInt16Value(state, 7);
  3714. if (quest) {
  3715. const char* taskgroup = 0;
  3716. if (str_taskgroup.length() > 0)
  3717. taskgroup = str_taskgroup.c_str();
  3718. int32 item_id = 0;
  3719. vector<int32>* ids = 0;
  3720. int i = 0;
  3721. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3722. if (ids == 0)
  3723. ids = new vector<int32>;
  3724. ids->push_back(item_id);
  3725. i++;
  3726. }
  3727. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3728. if (quest_step && icon > 0 && quantity > 0)
  3729. quest_step->SetIcon(icon);
  3730. if (quest->GetPlayer()) {
  3731. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3732. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3733. }
  3734. safe_delete(ids);
  3735. }
  3736. lua_interface->ResetFunctionStack(state);
  3737. return 0;
  3738. }
  3739. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3740. if (!lua_interface)
  3741. return 0;
  3742. Quest* quest = lua_interface->GetQuest(state);
  3743. int32 step = lua_interface->GetInt32Value(state, 2);
  3744. string description = lua_interface->GetStringValue(state, 3);
  3745. float max_variation = lua_interface->GetFloatValue(state, 4);
  3746. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3747. int16 icon = lua_interface->GetInt16Value(state, 6);
  3748. if (quest) {
  3749. const char* taskgroup = 0;
  3750. if (str_taskgroup.length() > 0)
  3751. taskgroup = str_taskgroup.c_str();
  3752. vector<Location>* locations = 0;
  3753. int8 i = 7;
  3754. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3755. while (true) {
  3756. Location loc;
  3757. loc.x = lua_interface->GetFloatValue(state, i);
  3758. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3759. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3760. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3761. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3762. break;
  3763. if (locations == 0)
  3764. locations = new vector<Location>;
  3765. locations->push_back(loc);
  3766. i += 4;
  3767. }
  3768. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3769. if (quest_step && icon > 0)
  3770. quest_step->SetIcon(icon);
  3771. if (quest->GetPlayer()) {
  3772. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3773. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3774. }
  3775. }
  3776. lua_interface->ResetFunctionStack(state);
  3777. return 0;
  3778. }
  3779. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3780. if (!lua_interface)
  3781. return 0;
  3782. Quest* quest = lua_interface->GetQuest(state);
  3783. int32 step = lua_interface->GetInt32Value(state, 2);
  3784. string description = lua_interface->GetStringValue(state, 3);
  3785. float max_variation = lua_interface->GetFloatValue(state, 4);
  3786. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3787. int16 icon = lua_interface->GetInt16Value(state, 6);
  3788. if (quest) {
  3789. const char* taskgroup = 0;
  3790. if (str_taskgroup.length() > 0)
  3791. taskgroup = str_taskgroup.c_str();
  3792. vector<Location>* locations = 0;
  3793. int8 i = 7;
  3794. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3795. while (true) {
  3796. Location loc;
  3797. loc.x = lua_interface->GetFloatValue(state, i);
  3798. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3799. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3800. loc.zone_id = 0;
  3801. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3802. break;
  3803. if (locations == 0)
  3804. locations = new vector<Location>;
  3805. locations->push_back(loc);
  3806. i += 3;
  3807. }
  3808. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3809. if (quest_step && icon > 0)
  3810. quest_step->SetIcon(icon);
  3811. if (quest->GetPlayer()) {
  3812. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3813. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3814. }
  3815. }
  3816. lua_interface->ResetFunctionStack(state);
  3817. return 0;
  3818. }
  3819. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3820. if (!lua_interface)
  3821. return 0;
  3822. Quest* quest = lua_interface->GetQuest(state);
  3823. int32 step = lua_interface->GetInt32Value(state, 2);
  3824. string description = lua_interface->GetStringValue(state, 3);
  3825. float max_variation = lua_interface->GetFloatValue(state, 4);
  3826. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3827. int16 icon = lua_interface->GetInt16Value(state, 6);
  3828. if (quest) {
  3829. const char* taskgroup = 0;
  3830. if (str_taskgroup.length() > 0)
  3831. taskgroup = str_taskgroup.c_str();
  3832. vector<Location>* locations = 0;
  3833. int i = 7;
  3834. while (true) {
  3835. Location loc;
  3836. loc.x = lua_interface->GetFloatValue(state, i);
  3837. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3838. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3839. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3840. break;
  3841. if (locations == 0)
  3842. locations = new vector<Location>;
  3843. locations->push_back(loc);
  3844. i += 3;
  3845. }
  3846. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3847. if (quest_step && icon > 0)
  3848. quest_step->SetIcon(icon);
  3849. if (quest->GetPlayer()) {
  3850. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3851. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3852. }
  3853. }
  3854. lua_interface->ResetFunctionStack(state);
  3855. return 0;
  3856. }
  3857. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3858. Quest* quest = lua_interface->GetQuest(state);
  3859. int32 step = lua_interface->GetInt32Value(state, 2);
  3860. string description = lua_interface->GetStringValue(state, 3);
  3861. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3862. float percentage = lua_interface->GetFloatValue(state, 5);
  3863. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3864. int16 icon = lua_interface->GetInt16Value(state, 7);
  3865. if (quest) {
  3866. const char* taskgroup = 0;
  3867. if (str_taskgroup.length() > 0)
  3868. taskgroup = str_taskgroup.c_str();
  3869. int32 spell_id = 0;
  3870. vector<int32>* ids = 0;
  3871. int i = 0;
  3872. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3873. if (ids == 0)
  3874. ids = new vector<int32>;
  3875. ids->push_back(spell_id);
  3876. i++;
  3877. }
  3878. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3879. if (quest_step && icon > 0 && quantity > 0)
  3880. quest_step->SetIcon(icon);
  3881. if (quest->GetPlayer()) {
  3882. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3883. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3884. }
  3885. safe_delete(ids);
  3886. }
  3887. lua_interface->ResetFunctionStack(state);
  3888. return 0;
  3889. }
  3890. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3891. if (!lua_interface)
  3892. return 0;
  3893. Quest* quest = lua_interface->GetQuest(state);
  3894. int32 step = lua_interface->GetInt32Value(state, 2);
  3895. string description = lua_interface->GetStringValue(state, 3);
  3896. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3897. float percentage = lua_interface->GetFloatValue(state, 5);
  3898. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3899. int16 icon = lua_interface->GetInt16Value(state, 7);
  3900. if (quest) {
  3901. const char* taskgroup = 0;
  3902. if (str_taskgroup.length() > 0)
  3903. taskgroup = str_taskgroup.c_str();
  3904. int32 item_id = 0;
  3905. vector<int32>* ids = 0;
  3906. int i = 0;
  3907. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3908. if (ids == 0)
  3909. ids = new vector<int32>;
  3910. ids->push_back(item_id);
  3911. i++;
  3912. }
  3913. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3914. if (quest_step && icon > 0 && quantity > 0)
  3915. quest_step->SetIcon(icon);
  3916. if (quest->GetPlayer()) {
  3917. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3918. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3919. }
  3920. safe_delete(ids);
  3921. }
  3922. lua_interface->ResetFunctionStack(state);
  3923. return 0;
  3924. }
  3925. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3926. if (!lua_interface)
  3927. return 0;
  3928. Quest* quest = lua_interface->GetQuest(state);
  3929. int32 step = lua_interface->GetInt32Value(state, 2);
  3930. string description = lua_interface->GetStringValue(state, 3);
  3931. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3932. float percentage = lua_interface->GetFloatValue(state, 5);
  3933. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3934. int16 icon = lua_interface->GetInt16Value(state, 7);
  3935. if (quest) {
  3936. const char* taskgroup = 0;
  3937. if (str_taskgroup.length() > 0)
  3938. taskgroup = str_taskgroup.c_str();
  3939. int32 item_id = 0;
  3940. vector<int32>* ids = 0;
  3941. int i = 0;
  3942. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3943. if (ids == 0)
  3944. ids = new vector<int32>;
  3945. ids->push_back(item_id);
  3946. i++;
  3947. }
  3948. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3949. if (quest_step && icon > 0 && quantity > 0)
  3950. quest_step->SetIcon(icon);
  3951. if (quest->GetPlayer()) {
  3952. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3953. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3954. }
  3955. safe_delete(ids);
  3956. }
  3957. lua_interface->ResetFunctionStack(state);
  3958. return 0;
  3959. }
  3960. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3961. if (!lua_interface)
  3962. return 0;
  3963. Quest* quest = lua_interface->GetQuest(state);
  3964. string action = lua_interface->GetStringValue(state, 2);
  3965. lua_interface->ResetFunctionStack(state);
  3966. if (quest) {
  3967. if (action.length() > 0)
  3968. quest->SetCompleteAction(action);
  3969. }
  3970. return 0;
  3971. }
  3972. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3973. if (!lua_interface)
  3974. return 0;
  3975. Quest* quest = lua_interface->GetQuest(state);
  3976. int32 step = lua_interface->GetInt32Value(state, 2);
  3977. string action = lua_interface->GetStringValue(state, 3);
  3978. lua_interface->ResetFunctionStack(state);
  3979. if (quest) {
  3980. if (step > 0 && action.length() > 0)
  3981. quest->AddCompleteAction(step, action);
  3982. }
  3983. return 0;
  3984. }
  3985. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3986. if (!lua_interface)
  3987. return 0;
  3988. Quest* quest = lua_interface->GetQuest(state);
  3989. int32 step = lua_interface->GetInt32Value(state, 2);
  3990. string action = lua_interface->GetStringValue(state, 3);
  3991. lua_interface->ResetFunctionStack(state);
  3992. if (quest) {
  3993. if (step > 0 && action.length() > 0)
  3994. quest->AddProgressAction(step, action);
  3995. }
  3996. return 0;
  3997. }
  3998. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3999. if (!lua_interface)
  4000. return 0;
  4001. Quest* quest = lua_interface->GetQuest(state);
  4002. string description = lua_interface->GetStringValue(state, 2);
  4003. lua_interface->ResetFunctionStack(state);
  4004. if (quest && description.length() > 0)
  4005. quest->SetDescription(description);
  4006. return 0;
  4007. }
  4008. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4009. if (!lua_interface)
  4010. return 0;
  4011. Quest* quest = lua_interface->GetQuest(state);
  4012. string description = lua_interface->GetStringValue(state, 2);
  4013. lua_interface->ResetFunctionStack(state);
  4014. if (quest && description.length() > 0)
  4015. quest->SetCompletedDescription(description);
  4016. return 0;
  4017. }
  4018. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4019. if (!lua_interface)
  4020. return 0;
  4021. Quest* quest = lua_interface->GetQuest(state);
  4022. int32 step = lua_interface->GetInt32Value(state, 2);
  4023. string description = lua_interface->GetStringValue(state, 3);
  4024. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4025. lua_interface->ResetFunctionStack(state);
  4026. if (quest && step > 0 && description.length() > 0) {
  4027. quest->SetTaskGroupDescription(step, description, display_bullets);
  4028. /* if (quest->GetPlayer()) {
  4029. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4030. if (client)
  4031. client->SendQuestUpdateStep(quest, step, false);
  4032. }*/
  4033. }
  4034. return 0;
  4035. }
  4036. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4037. if (!lua_interface)
  4038. return 0;
  4039. Quest* quest = lua_interface->GetQuest(state);
  4040. int32 step = lua_interface->GetInt32Value(state, 2);
  4041. string description = lua_interface->GetStringValue(state, 3);
  4042. lua_interface->ResetFunctionStack(state);
  4043. if (quest && step > 0 && description.length() > 0) {
  4044. quest->SetStepDescription(step, description);
  4045. /*if (quest->GetPlayer()) {
  4046. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4047. if (client)
  4048. client->SendQuestUpdateStepImmediately(quest, step);
  4049. }*/
  4050. }
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4054. Quest* quest = lua_interface->GetQuest(state);
  4055. string zone = lua_interface->GetStringValue(state, 2);
  4056. lua_interface->ResetFunctionStack(state);
  4057. if (quest && zone.length() > 0)
  4058. quest->SetZone(zone);
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Quest* quest = lua_interface->GetQuest(state);
  4065. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4066. lua_interface->ResetFunctionStack(state);
  4067. if (quest && spawn) {
  4068. if (spawn->IsPlayer()) {
  4069. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4070. if (client)
  4071. {
  4072. client->AddPendingQuestAcceptReward(quest);
  4073. client->AddPendingQuestReward(quest);
  4074. }
  4075. }
  4076. }
  4077. return 0;
  4078. }
  4079. int EQ2Emu_lua_Harvest(lua_State* state) {
  4080. if (!lua_interface)
  4081. return 0;
  4082. Spawn* player = lua_interface->GetSpawn(state);
  4083. Spawn* node = lua_interface->GetSpawn(state, 2);
  4084. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4085. Client* client = player->GetZone()->GetClientBySpawn(player);
  4086. if (client) {
  4087. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4088. ((GroundSpawn*)node)->ProcessHarvest(client);
  4089. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4090. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4091. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4092. }
  4093. }
  4094. }
  4095. else if (player && player->IsPlayer()) {
  4096. Client* client = player->GetZone()->GetClientBySpawn(player);
  4097. if (client)
  4098. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4099. }
  4100. lua_interface->ResetFunctionStack(state);
  4101. return 0;
  4102. }
  4103. int EQ2Emu_lua_Bind(lua_State* state) {
  4104. if (!lua_interface)
  4105. return 0;
  4106. Spawn* spawn = lua_interface->GetSpawn(state);
  4107. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4108. float x = lua_interface->GetFloatValue(state, 3);
  4109. float y = lua_interface->GetFloatValue(state, 4);
  4110. float z = lua_interface->GetFloatValue(state, 5);
  4111. float h = lua_interface->GetFloatValue(state, 6);
  4112. lua_interface->ResetFunctionStack(state);
  4113. if (!spawn) {
  4114. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4115. return 0;
  4116. }
  4117. if (!spawn->IsPlayer()) {
  4118. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4119. return 0;
  4120. }
  4121. if (zone_id == 0) {
  4122. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4123. if (!client) {
  4124. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4125. return 0;
  4126. }
  4127. if (!client->Bind())
  4128. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4129. }
  4130. else {
  4131. Player* player = (Player*)spawn;
  4132. player->GetPlayerInfo()->SetBindZone(zone_id);
  4133. player->GetPlayerInfo()->SetBindX(x);
  4134. player->GetPlayerInfo()->SetBindY(y);
  4135. player->GetPlayerInfo()->SetBindZ(z);
  4136. player->GetPlayerInfo()->SetBindHeading(h);
  4137. }
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_Gate(lua_State* state) {
  4141. if (!lua_interface)
  4142. return 0;
  4143. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4144. Spawn* spawn = lua_interface->GetSpawn(state);
  4145. lua_interface->ResetFunctionStack(state);
  4146. if (spawn) {
  4147. if (spawn->IsPlayer()) {
  4148. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4149. if (client) {
  4150. if (!client->Gate((spell != nullptr) ? true : false))
  4151. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4152. }
  4153. }
  4154. }
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. bool ret = false;
  4161. Spawn* spawn = lua_interface->GetSpawn(state);
  4162. lua_interface->ResetFunctionStack(state);
  4163. if (spawn) {
  4164. if (spawn->IsPlayer()) {
  4165. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4166. if (client)
  4167. ret = client->BindAllowed();
  4168. }
  4169. }
  4170. lua_interface->SetBooleanValue(state, ret);
  4171. return 1;
  4172. }
  4173. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4174. if (!lua_interface)
  4175. return 0;
  4176. bool ret = false;
  4177. Spawn* spawn = lua_interface->GetSpawn(state);
  4178. lua_interface->ResetFunctionStack(state);
  4179. if (spawn) {
  4180. if (spawn->IsPlayer()) {
  4181. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4182. ZoneServer* zone = lua_interface->GetZone(state);
  4183. if (client && zone){
  4184. ret = zone->GetCanGate();
  4185. }
  4186. }
  4187. }
  4188. lua_interface->SetBooleanValue(state, ret);
  4189. return 1;
  4190. }
  4191. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4192. Spawn* spawn = lua_interface->GetSpawn(state);
  4193. lua_interface->ResetFunctionStack(state);
  4194. if (spawn) {
  4195. lua_interface->SetBooleanValue(state, spawn->Alive());
  4196. return 1;
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4201. if (!lua_interface)
  4202. return 0;
  4203. Spawn* spawn = lua_interface->GetSpawn(state);
  4204. lua_interface->ResetFunctionStack(state);
  4205. if (spawn && spawn->IsEntity()) {
  4206. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4207. return 1;
  4208. }
  4209. return 0;
  4210. }
  4211. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4212. Spawn* spawn = lua_interface->GetSpawn(state);
  4213. string message = lua_interface->GetStringValue(state, 2);
  4214. string color_str = lua_interface->GetStringValue(state, 3);
  4215. lua_interface->ResetFunctionStack(state);
  4216. int8 color = CHANNEL_NARRATIVE;
  4217. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4218. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4219. if (client) {
  4220. if (color_str.length() > 0) {
  4221. // leave for backwards compat, but all future should just use the number
  4222. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4223. color = CHANNEL_COLOR_RED;
  4224. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4225. color = CHANNEL_COLOR_YELLOW;
  4226. else
  4227. {
  4228. // use a number to specify the channel as per Commands/Commands.h defines
  4229. color = (int8)atoul(color_str.c_str());
  4230. }
  4231. }
  4232. client->SimpleMessage(color, message.c_str());
  4233. }
  4234. }
  4235. return 0;
  4236. }
  4237. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4238. Spawn* spawn = lua_interface->GetSpawn(state);
  4239. string message = lua_interface->GetStringValue(state, 2);
  4240. int8 red = lua_interface->GetInt8Value(state, 3);
  4241. int8 green = lua_interface->GetInt8Value(state, 4);
  4242. int8 blue = lua_interface->GetInt8Value(state, 5);
  4243. lua_interface->ResetFunctionStack(state);
  4244. if (!spawn) {
  4245. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4246. return 0;
  4247. }
  4248. int32 words = ::CountWordsInString(message.c_str());
  4249. if (words < 5)
  4250. words = 5;
  4251. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4252. if (client)
  4253. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4254. return 0;
  4255. }
  4256. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4257. Spawn* spawn = lua_interface->GetSpawn(state);
  4258. int8 param = lua_interface->GetInt8Value(state, 2);
  4259. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4260. int8 value = lua_interface->GetInt8Value(state, 4);
  4261. lua_interface->ResetFunctionStack(state);
  4262. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4263. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4264. if (client) {
  4265. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4266. switch (param) {
  4267. case 1: {
  4268. packet->setDataByName("parameter1", param_value);
  4269. break;
  4270. }
  4271. case 2: {
  4272. packet->setDataByName("parameter2", param_value);
  4273. break;
  4274. }
  4275. case 3: {
  4276. packet->setDataByName("parameter3", param_value);
  4277. break;
  4278. }
  4279. case 4: {
  4280. packet->setDataByName("parameter4", param_value);
  4281. break;
  4282. }
  4283. case 5: {
  4284. packet->setDataByName("parameter5", param_value);
  4285. break;
  4286. }
  4287. }
  4288. packet->setDataByName("value", value);
  4289. client->QueuePacket(packet->serialize());
  4290. safe_delete(packet);
  4291. }
  4292. }
  4293. return 0;
  4294. }
  4295. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4296. Spawn* spawn = lua_interface->GetSpawn(state);
  4297. lua_interface->ResetFunctionStack(state);
  4298. if (spawn && spawn->IsPlayer()) {
  4299. if (((Player*)spawn)->GetIsTracking())
  4300. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4301. else
  4302. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4303. }
  4304. return 0;
  4305. }
  4306. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4307. Spawn* player = lua_interface->GetSpawn(state);
  4308. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4309. string name = lua_interface->GetStringValue(state, 3);
  4310. float distance = lua_interface->GetFloatValue(state, 4);
  4311. string command = lua_interface->GetStringValue(state, 5);
  4312. string error_text = lua_interface->GetStringValue(state, 6);
  4313. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4314. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4315. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4316. lua_interface->ResetFunctionStack(state);
  4317. if (spawn) {
  4318. if (distance == 0)
  4319. distance = 10.0f;
  4320. if (command.length() == 0)
  4321. command = name;
  4322. if (command.length() < 1 && name.length() < 1)
  4323. {
  4324. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4325. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4326. spawn->RemovePrimaryCommands();
  4327. }
  4328. else
  4329. {
  4330. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4331. }
  4332. }
  4333. return 0;
  4334. }
  4335. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4336. if (!lua_interface)
  4337. return 0;
  4338. Spawn* player = lua_interface->GetSpawn(state);
  4339. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4340. int16 tier = lua_interface->GetInt16Value(state, 3);
  4341. lua_interface->ResetFunctionStack(state);
  4342. if (player && player->IsPlayer()) {
  4343. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4344. return 1;
  4345. }
  4346. return 0;
  4347. }
  4348. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4349. if (!lua_interface)
  4350. return 0;
  4351. Spawn* player = lua_interface->GetSpawn(state);
  4352. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4353. int16 tier = lua_interface->GetInt16Value(state, 3);
  4354. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4355. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4356. bool add_to_hotbar = true;
  4357. if (num_args > 4) {
  4358. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4359. }
  4360. lua_interface->ResetFunctionStack(state);
  4361. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4362. if (player && spell && player->IsPlayer()) {
  4363. Client* client = player->GetClient();
  4364. if (client) {
  4365. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4366. {
  4367. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4368. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4369. client->GetPlayer()->UnlockSpell(spell);
  4370. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4371. }
  4372. else
  4373. {
  4374. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4375. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4376. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4377. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4378. client->GetPlayer()->UnlockSpell(spell);
  4379. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4380. }
  4381. //if (client ) {
  4382. // ((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);
  4383. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4384. if (outapp)
  4385. client->QueuePacket(outapp);
  4386. }
  4387. }
  4388. return 0;
  4389. }
  4390. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4391. if (!lua_interface)
  4392. return 0;
  4393. Spawn* player = lua_interface->GetSpawn(state);
  4394. lua_interface->ResetFunctionStack(state);
  4395. if (player && player->IsPlayer()) {
  4396. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4397. return 1;
  4398. }
  4399. return 0;
  4400. }
  4401. int EQ2Emu_lua_Attack(lua_State* state) {
  4402. if (lua_interface) {
  4403. Spawn* npc = lua_interface->GetSpawn(state);
  4404. Spawn* player = lua_interface->GetSpawn(state, 2);
  4405. lua_interface->ResetFunctionStack(state);
  4406. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4407. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4408. }
  4409. return 0;
  4410. }
  4411. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4412. if (lua_interface) {
  4413. Spawn* target = lua_interface->GetSpawn(state);
  4414. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4415. lua_interface->ResetFunctionStack(state);
  4416. if (target && target->GetZone())
  4417. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4418. }
  4419. return 0;
  4420. }
  4421. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4422. Spawn* player;
  4423. if (lua_interface) {
  4424. player = lua_interface->GetSpawn(state);
  4425. lua_interface->ResetFunctionStack(state);
  4426. if (player && player->IsPlayer()) {
  4427. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4428. return 1;
  4429. }
  4430. }
  4431. return 0;
  4432. }
  4433. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4434. Spawn* player;
  4435. Client* client;
  4436. if (lua_interface) {
  4437. player = lua_interface->GetSpawn(state);
  4438. lua_interface->ResetFunctionStack(state);
  4439. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4440. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4441. client->HandInCollections();
  4442. }
  4443. return 0;
  4444. }
  4445. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4446. Spawn* widget;
  4447. if (lua_interface) {
  4448. widget = lua_interface->GetSpawn(state);
  4449. lua_interface->ResetFunctionStack(state);
  4450. if (widget && widget->IsWidget())
  4451. ((Widget*)widget)->HandleUse(nullptr, "");
  4452. }
  4453. return 0;
  4454. }
  4455. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4456. Spawn* spawn = 0;
  4457. int32 primary_list = 0;
  4458. int32 secondary_list = 0;
  4459. if (lua_interface) {
  4460. spawn = lua_interface->GetSpawn(state);
  4461. primary_list = lua_interface->GetInt32Value(state, 2);
  4462. secondary_list = lua_interface->GetInt32Value(state, 3);
  4463. lua_interface->ResetFunctionStack(state);
  4464. if (!spawn->IsNPC()) {
  4465. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4466. return 0;
  4467. }
  4468. NPC* npc = (NPC*)spawn;
  4469. npc->SetPrimarySpellList(primary_list);
  4470. npc->SetSecondarySpellList(secondary_list);
  4471. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4472. }
  4473. return 0;
  4474. }
  4475. int EQ2Emu_lua_GetPet(lua_State* state) {
  4476. if (!lua_interface)
  4477. return 0;
  4478. Spawn* spawn = lua_interface->GetSpawn(state);
  4479. lua_interface->ResetFunctionStack(state);
  4480. if (spawn) {
  4481. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4482. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4483. return 1;
  4484. }
  4485. }
  4486. return 0;
  4487. }
  4488. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4489. if (!lua_interface)
  4490. return 0;
  4491. Spawn* spawn = lua_interface->GetSpawn(state);
  4492. lua_interface->ResetFunctionStack(state);
  4493. if (spawn) {
  4494. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4495. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4496. return 1;
  4497. }
  4498. }
  4499. return 0;
  4500. }
  4501. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4502. if (!lua_interface)
  4503. return 0;
  4504. Spawn* spawn = lua_interface->GetSpawn(state);
  4505. lua_interface->ResetFunctionStack(state);
  4506. if (spawn) {
  4507. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4508. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4509. return 1;
  4510. }
  4511. }
  4512. return 0;
  4513. }
  4514. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4515. if (!lua_interface)
  4516. return 0;
  4517. Spawn* spawn = lua_interface->GetSpawn(state);
  4518. lua_interface->ResetFunctionStack(state);
  4519. if (spawn) {
  4520. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4521. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4522. return 1;
  4523. }
  4524. }
  4525. return 0;
  4526. }
  4527. int EQ2Emu_lua_Charm(lua_State* state) {
  4528. if (!lua_interface)
  4529. return 0;
  4530. Spawn* owner = lua_interface->GetSpawn(state);
  4531. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4532. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4533. lua_interface->ResetFunctionStack(state);
  4534. if (!luaspell) {
  4535. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4536. return 0;
  4537. }
  4538. if(luaspell->resisted) {
  4539. return 0;
  4540. }
  4541. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4542. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4543. pet->SetPet(true);
  4544. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4545. ((NPC*)pet)->SetOwner((Entity*)owner);
  4546. // If owner is player and player does not have a summoned pet set the players charsheet
  4547. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4548. Player* player = (Player*)owner;
  4549. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4550. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4551. player->GetInfoStruct()->set_pet_movement(2);
  4552. player->GetInfoStruct()->set_pet_behavior(3);
  4553. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4554. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4555. // Make sure the values get sent to the client
  4556. player->SetCharSheetChanged(true);
  4557. }
  4558. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4559. pet->SetSpawnScript("");
  4560. // Set faction to the same as the owner
  4561. pet->SetFactionID(owner->GetFactionID());
  4562. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4563. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4564. // Clear hate list
  4565. ((NPC*)pet)->Brain()->ClearHate();
  4566. // Set the brain to a pet brain
  4567. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4568. }
  4569. return 0;
  4570. }
  4571. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4572. if (!lua_interface)
  4573. return 0;
  4574. Spawn* spawn = lua_interface->GetSpawn(state);
  4575. lua_interface->ResetFunctionStack(state);
  4576. if (!spawn) {
  4577. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4578. return 0;
  4579. }
  4580. vector<Spawn*> groupMembers;
  4581. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4582. groupMembers = *spawn->GetSpawnGroup();
  4583. }
  4584. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4585. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4586. deque<GroupMemberInfo*>::iterator itr;
  4587. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4588. if (group)
  4589. {
  4590. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4591. deque<GroupMemberInfo*>* members = group->GetMembers();
  4592. GroupMemberInfo* info = 0;
  4593. for (itr = members->begin(); itr != members->end(); itr++) {
  4594. info = *itr;
  4595. if (info->client)
  4596. groupMembers.push_back(info->client->GetPlayer());
  4597. }
  4598. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4599. }
  4600. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4601. }
  4602. else
  4603. return 0;
  4604. lua_createtable(state, groupMembers.size(), 0);
  4605. int newTable = lua_gettop(state);
  4606. for (int32 i = 0; i < groupMembers.size(); i++) {
  4607. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4608. lua_rawseti(state, newTable, i + 1);
  4609. }
  4610. return 1;
  4611. }
  4612. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4613. if (!lua_interface)
  4614. return 0;
  4615. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4616. lua_interface->SetOptionWindowValue(state, option_window);
  4617. return 1;
  4618. }
  4619. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4620. if (!lua_interface)
  4621. return 0;
  4622. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4623. if (option_window) {
  4624. OptionWindowOption option_window_option;
  4625. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4626. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4627. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4628. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4629. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4630. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4631. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4632. option_window->push_back(option_window_option);
  4633. }
  4634. return 0;
  4635. }
  4636. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4637. if (!lua_interface)
  4638. return 0;
  4639. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4640. Spawn* player = lua_interface->GetSpawn(state, 2);
  4641. string window_title = lua_interface->GetStringValue(state, 3);
  4642. string cancel_command = lua_interface->GetStringValue(state, 4);
  4643. Client* client = player->GetZone()->GetClientBySpawn(player);
  4644. if (option_window && window_title.length() > 0 && client) {
  4645. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4646. if (!packet)
  4647. return 0;
  4648. packet->setDataByName("title_text", window_title.c_str());
  4649. if (cancel_command.length() > 0)
  4650. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4651. packet->setArrayLengthByName("num_selections", option_window->size());
  4652. vector<OptionWindowOption>::iterator itr;
  4653. int8 i = 0;
  4654. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4655. OptionWindowOption opt = *itr;
  4656. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4657. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4658. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4659. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4660. if (opt.optionCommand.length() > 0)
  4661. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4662. if (opt.optionConfirmTitle.length() > 0)
  4663. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4664. i++;
  4665. }
  4666. client->QueuePacket(packet->serialize());
  4667. safe_delete(option_window);
  4668. safe_delete(packet);
  4669. }
  4670. return 0;
  4671. }
  4672. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4673. if (!lua_interface)
  4674. return 0;
  4675. Spawn* spawn = lua_interface->GetSpawn(state);
  4676. if (spawn) {
  4677. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4678. return 1;
  4679. }
  4680. else
  4681. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4685. if (!lua_interface)
  4686. return 0;
  4687. Spawn* spawn = lua_interface->GetSpawn(state);
  4688. if (spawn) {
  4689. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4690. return 1;
  4691. }
  4692. else
  4693. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4694. return 0;
  4695. }
  4696. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4697. if (!lua_interface)
  4698. return 0;
  4699. Spawn* spawn = lua_interface->GetSpawn(state);
  4700. if (spawn) {
  4701. int8 class_id = spawn->GetTradeskillClass();
  4702. // Need to add 42 for the offset in the array
  4703. class_id += 44;
  4704. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4705. return 1;
  4706. }
  4707. else
  4708. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4709. return 0;
  4710. }
  4711. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4712. if (!lua_interface)
  4713. return 0;
  4714. Spawn* spawn = lua_interface->GetSpawn(state);
  4715. int16 level = lua_interface->GetInt8Value(state, 2);
  4716. if (spawn) {
  4717. if (spawn->IsPlayer())
  4718. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4719. else
  4720. spawn->SetTSLevel(level);
  4721. }
  4722. else
  4723. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4724. return 0;
  4725. }
  4726. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4727. if (!lua_interface)
  4728. return 0;
  4729. Spawn* spawn = lua_interface->GetSpawn(state);
  4730. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4731. if (spawn) {
  4732. spawn->SetAttackable(attackable);
  4733. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4734. }
  4735. return 0;
  4736. }
  4737. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4738. // Check to see if we have a valid lua_interface
  4739. if (!lua_interface)
  4740. return 0;
  4741. // Get the spawn that is getting the pet
  4742. Spawn* spawn = lua_interface->GetSpawn(state);
  4743. // Get the DB ID of the pet
  4744. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4745. // The max level the pet can gain
  4746. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4747. // Get the spell that this command was called from
  4748. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4749. // Check to make sure the spawn pointer is valid
  4750. if (!spawn) {
  4751. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4752. return 0;
  4753. }
  4754. // Check to make sure the spawn is an entity
  4755. if (!spawn->IsEntity()) {
  4756. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. // Check to make sure the spawn doesn't already have a pet of this type
  4760. if (((Entity*)spawn)->GetPet()) {
  4761. if (spawn->IsPlayer()) {
  4762. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4763. if (client)
  4764. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4765. }
  4766. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4767. return 0;
  4768. }
  4769. // Check to see if the DB ID for the pet is set
  4770. if (pet_id == 0) {
  4771. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4772. return 0;
  4773. }
  4774. // Check to see if the pointer to the spell is valid
  4775. if (!luaspell) {
  4776. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4777. return 0;
  4778. }
  4779. if(luaspell->resisted) {
  4780. return 0;
  4781. }
  4782. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4783. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4784. if (!pet) {
  4785. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4786. return 0;
  4787. }
  4788. // Check to make sure the pet is an npc
  4789. if (!pet->IsNPC()) {
  4790. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4791. return 0;
  4792. }
  4793. // Spawn the pet at the same location as the owner
  4794. pet->SetX(spawn->GetX());
  4795. pet->SetY(spawn->GetY());
  4796. pet->SetZ(spawn->GetZ());
  4797. pet->SetLocation(spawn->GetLocation());
  4798. pet->SetHeading(spawn->GetHeading());
  4799. spawn->GetZone()->AddSpawn(pet);
  4800. /*
  4801. const char* spawn_script = world.GetSpawnScript(pet_id);
  4802. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4803. spawn->SetSpawnScript(string(spawn_script));
  4804. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4805. }*/
  4806. // Get a random pet name
  4807. string random_pet_name;
  4808. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4809. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4810. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4811. // If player set various values for the char sheet (pet window)
  4812. if (spawn->IsPlayer()) {
  4813. Player* player = (Player*)spawn;
  4814. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4815. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4816. player->GetInfoStruct()->set_pet_movement(2);
  4817. player->GetInfoStruct()->set_pet_behavior(3);
  4818. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4819. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4820. // Make sure the values get sent to the client
  4821. player->SetCharSheetChanged(true);
  4822. }
  4823. // Set the pets name
  4824. pet->SetName(random_pet_name.c_str());
  4825. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4826. if (max_level > 0)
  4827. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4828. else
  4829. pet->SetLevel(spawn->GetLevel());
  4830. // Set the max level this pet can reach
  4831. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4832. // Set the faction of the pet to the same faction as the owner
  4833. pet->SetFactionID(spawn->GetFactionID());
  4834. // Set the spawn as a pet
  4835. pet->SetPet(true);
  4836. // Give a pointer of the owner to the pet
  4837. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4838. // Give a pointer of the pet to the owner
  4839. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4840. // Set the pet type
  4841. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4842. // Set the spell id used to create this pet
  4843. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4844. // Set the spell tier used to create this pet
  4845. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4846. // Set the pets spawn type to 6
  4847. pet->SetSpawnType(6);
  4848. // Set the pets brain
  4849. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4850. // Check to see if the pet has a subtitle
  4851. if (strlen(pet->GetSubTitle()) > 0) {
  4852. // Add the players name to the front of the sub title
  4853. string pet_subtitle;
  4854. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4855. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4856. // Set the pets subtitle to the new one
  4857. pet->SetSubTitle(pet_subtitle.c_str());
  4858. }
  4859. // Add the "Pet Options" entity command to the pet
  4860. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4861. // Set the pet as the return value for this function
  4862. lua_interface->SetSpawnValue(state, pet);
  4863. return 1;
  4864. }
  4865. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4866. if (!lua_interface)
  4867. return 0;
  4868. Spawn* spawn = lua_interface->GetSpawn(state);
  4869. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4870. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4871. if (!spawn) {
  4872. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4873. return 0;
  4874. }
  4875. if (!spawn->IsEntity()) {
  4876. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4877. return 0;
  4878. }
  4879. if (((Entity*)spawn)->GetDeityPet()) {
  4880. if (spawn->IsPlayer()) {
  4881. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4882. if (client)
  4883. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4884. }
  4885. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4886. return 0;
  4887. }
  4888. if (pet_id == 0) {
  4889. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4890. return 0;
  4891. }
  4892. if (!luaspell) {
  4893. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4894. return 0;
  4895. }
  4896. if(luaspell->resisted) {
  4897. return 0;
  4898. }
  4899. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4900. if (!pet) {
  4901. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4902. return 0;
  4903. }
  4904. if (!pet->IsNPC()) {
  4905. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4906. return 0;
  4907. }
  4908. pet->SetX(spawn->GetX());
  4909. pet->SetY(spawn->GetY());
  4910. pet->SetZ(spawn->GetZ());
  4911. pet->SetLocation(spawn->GetLocation());
  4912. pet->SetHeading(spawn->GetHeading());
  4913. spawn->GetZone()->AddSpawn(pet);
  4914. string random_pet_name;
  4915. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4916. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4917. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4918. pet->SetName(random_pet_name.c_str());
  4919. pet->SetLevel(spawn->GetLevel());
  4920. pet->SetFactionID(spawn->GetFactionID());
  4921. pet->SetPet(true);
  4922. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4923. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4924. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4925. pet->SetSpawnType(6);
  4926. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4927. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4928. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4929. if (strlen(pet->GetSubTitle()) > 0) {
  4930. string pet_subtitle;
  4931. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4932. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4933. pet->SetSubTitle(pet_subtitle.c_str());
  4934. }
  4935. // deity and cosmetic pets are not attackable
  4936. pet->SetAttackable(false);
  4937. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4938. lua_interface->SetSpawnValue(state, pet);
  4939. return 1;
  4940. }
  4941. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4942. if (!lua_interface)
  4943. return 0;
  4944. Spawn* spawn = lua_interface->GetSpawn(state);
  4945. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4946. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4947. if (!spawn) {
  4948. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4949. return 0;
  4950. }
  4951. if (!spawn->IsEntity()) {
  4952. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4953. return 0;
  4954. }
  4955. if (((Entity*)spawn)->GetCosmeticPet()) {
  4956. if (spawn->IsPlayer()) {
  4957. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4958. if (client)
  4959. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4960. }
  4961. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4962. return 0;
  4963. }
  4964. if (pet_id == 0) {
  4965. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4966. return 0;
  4967. }
  4968. if (!luaspell) {
  4969. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. if(luaspell->resisted) {
  4973. return 0;
  4974. }
  4975. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4976. if (!pet) {
  4977. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4978. return 0;
  4979. }
  4980. if (!pet->IsNPC()) {
  4981. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4982. return 0;
  4983. }
  4984. pet->SetX(spawn->GetX());
  4985. pet->SetY(spawn->GetY());
  4986. pet->SetZ(spawn->GetZ());
  4987. pet->SetLocation(spawn->GetLocation());
  4988. pet->SetHeading(spawn->GetHeading());
  4989. spawn->GetZone()->AddSpawn(pet);
  4990. string random_pet_name;
  4991. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4992. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4993. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4994. pet->SetName(random_pet_name.c_str());
  4995. pet->SetLevel(spawn->GetLevel());
  4996. pet->SetFactionID(spawn->GetFactionID());
  4997. pet->SetPet(true);
  4998. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4999. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5000. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5001. pet->SetSpawnType(6);
  5002. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5003. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5004. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5005. if (strlen(pet->GetSubTitle()) > 0) {
  5006. string pet_subtitle;
  5007. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5008. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5009. pet->SetSubTitle(pet_subtitle.c_str());
  5010. }
  5011. pet->SetAttackable(false);
  5012. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5013. lua_interface->SetSpawnValue(state, pet);
  5014. return 1;
  5015. }
  5016. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5017. if (!lua_interface)
  5018. return 0;
  5019. Spawn* spawn = lua_interface->GetSpawn(state);
  5020. if (!spawn) {
  5021. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5022. return 0;
  5023. }
  5024. if (!spawn->IsPet()) {
  5025. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5026. return 0;
  5027. }
  5028. if (!((NPC*)spawn)->IsDismissing())
  5029. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5030. return 0;
  5031. }
  5032. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5033. if (!lua_interface)
  5034. return 0;
  5035. Quest* quest = lua_interface->GetQuest(state);
  5036. if (!quest) {
  5037. 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));
  5038. return 0;
  5039. }
  5040. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5041. if (feather_color > 0)
  5042. quest->SetFeatherColor(feather_color);
  5043. return 0;
  5044. }
  5045. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5046. if (!lua_interface)
  5047. return 0;
  5048. Spawn* spawn = lua_interface->GetSpawn(state);
  5049. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5050. if (!spawn) {
  5051. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5052. return 0;
  5053. }
  5054. if (!spawn2) {
  5055. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5056. return 0;
  5057. }
  5058. spawn->RemoveSpawnAccess(spawn2);
  5059. return 0;
  5060. }
  5061. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5062. if (!lua_interface)
  5063. return 0;
  5064. ZoneServer* zone = lua_interface->GetZone(state);
  5065. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5066. if (!zone) {
  5067. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5068. return 0;
  5069. }
  5070. if (location_id == 0) {
  5071. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5072. return 0;
  5073. }
  5074. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5075. if (!location) {
  5076. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5077. return 0;
  5078. }
  5079. Spawn* spawn = 0;
  5080. if (location->entities[0]) {
  5081. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5082. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5083. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5084. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5085. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5086. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5087. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5088. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5089. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5090. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5091. if(spawn && spawn->IsOmittedByDBFlag())
  5092. {
  5093. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5094. safe_delete(spawn);
  5095. spawn = 0;
  5096. return 0;
  5097. }
  5098. if (spawn) {
  5099. const char* script = 0;
  5100. for (int x = 0; x < 3; x++) {
  5101. switch (x) {
  5102. case 0:
  5103. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5104. break;
  5105. case 1:
  5106. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5107. break;
  5108. case 2:
  5109. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5110. break;
  5111. }
  5112. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5113. spawn->SetSpawnScript(string(script));
  5114. break;
  5115. }
  5116. }
  5117. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5118. lua_interface->SetSpawnValue(state, spawn);
  5119. return 1;
  5120. }
  5121. else {
  5122. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5123. safe_delete(spawn);
  5124. }
  5125. }
  5126. return 0;
  5127. }
  5128. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5129. if (!lua_interface)
  5130. return 0;
  5131. Spawn* caster = lua_interface->GetSpawn(state);
  5132. Spawn* target = lua_interface->GetSpawn(state, 2);
  5133. int32 id = lua_interface->GetInt32Value(state, 3);
  5134. string command = lua_interface->GetStringValue(state, 4);
  5135. if (!caster) {
  5136. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. if (!target) {
  5140. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. if (!caster->IsPlayer()) {
  5144. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5145. return 0;
  5146. }
  5147. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5148. if (!entity_command) {
  5149. 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());
  5150. return 0;
  5151. }
  5152. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5153. if (!client) {
  5154. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5155. return 0;
  5156. }
  5157. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Spawn* spawn = lua_interface->GetSpawn(state);
  5164. if (!spawn) {
  5165. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. if (!spawn->IsNPC()) {
  5169. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5170. return 0;
  5171. }
  5172. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5173. return 0;
  5174. }
  5175. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5176. if (!lua_interface)
  5177. return 0;
  5178. Spawn* spawn = lua_interface->GetSpawn(state);
  5179. int16 tick = lua_interface->GetInt16Value(state, 2);
  5180. if (!spawn) {
  5181. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5182. return 0;
  5183. }
  5184. if (!spawn->IsNPC()) {
  5185. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. if (tick < 20) {
  5189. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. ((NPC*)spawn)->Brain()->SetTick(tick);
  5193. return 0;
  5194. }
  5195. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5196. if (!lua_interface)
  5197. return 0;
  5198. Spawn* spawn = lua_interface->GetSpawn(state);
  5199. Spawn* target = lua_interface->GetSpawn(state, 2);
  5200. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5201. if (!spawn) {
  5202. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5203. return 0;
  5204. }
  5205. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5206. spawn->SetFollowTarget(target, follow_distance);
  5207. return 0;
  5208. }
  5209. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5210. if (!lua_interface)
  5211. return 0;
  5212. Spawn* spawn = lua_interface->GetSpawn(state);
  5213. if (!spawn) {
  5214. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. Spawn* target = spawn->GetFollowTarget();
  5218. if (target) {
  5219. lua_interface->SetSpawnValue(state, target);
  5220. return 1;
  5221. }
  5222. return 0;
  5223. }
  5224. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5225. if (!lua_interface)
  5226. return 0;
  5227. Spawn* spawn = lua_interface->GetSpawn(state);
  5228. if (!spawn) {
  5229. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5230. return 0;
  5231. }
  5232. if (spawn->following)
  5233. spawn->following = false;
  5234. else
  5235. spawn->following = true;
  5236. return 0;
  5237. }
  5238. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5239. if (!lua_interface)
  5240. return 0;
  5241. Spawn* spawn = lua_interface->GetSpawn(state);
  5242. if (!spawn) {
  5243. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5244. return 0;
  5245. }
  5246. lua_interface->SetBooleanValue(state, spawn->following);
  5247. return 1;
  5248. }
  5249. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5250. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5251. // I will attempt to explain how this function works for future refrence
  5252. // Fist lets make sure lua_interface is valid, if not return out
  5253. if (!lua_interface)
  5254. return 0;
  5255. // Next we grab the first 2 params same as we usually would
  5256. Spawn* spawn = lua_interface->GetSpawn(state);
  5257. string var = lua_interface->GetStringValue(state, 2);
  5258. // 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
  5259. // 1 = Spawn
  5260. // 2 = Zone
  5261. // 3 = Item
  5262. // 4 = Quest
  5263. // 5 = String
  5264. // 6 = nil (null)
  5265. int8 dataType = 0;
  5266. // Define pointers for each potential type
  5267. Spawn* spawnVal = 0;
  5268. ZoneServer* zone = 0;
  5269. Item* item = 0;
  5270. Quest* quest = 0;
  5271. string val;
  5272. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5273. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5274. // options window are also light user data be we do not handle those.
  5275. // We check with lua_islightuserdata(lua_State*, index)
  5276. if (lua_islightuserdata(state, 3)) {
  5277. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5278. // and convert it to LUAUserData*
  5279. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5280. // Check to make sure the data we got is valid, if not give an error
  5281. if (!data || !data->IsCorrectlyInitialized()) {
  5282. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5283. }
  5284. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5285. else if (data->IsSpawn()) {
  5286. spawnVal = data->spawn;
  5287. dataType = 1;
  5288. }
  5289. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5290. else if (data->IsZone()) {
  5291. zone = data->zone;
  5292. dataType = 2;
  5293. }
  5294. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5295. else if (data->IsItem()) {
  5296. item = data->item;
  5297. dataType = 3;
  5298. }
  5299. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5300. else if (data->IsQuest()) {
  5301. quest = data->quest;
  5302. dataType = 4;
  5303. }
  5304. }
  5305. // Wasn't light user data, check if it is nil(null)
  5306. else if (lua_isnil(state, 3)) {
  5307. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5308. dataType = 6;
  5309. }
  5310. // Wasn't light user data or nil (null), must be a string
  5311. else {
  5312. // Set the string and dataType variable
  5313. val = lua_interface->GetStringValue(state, 3);
  5314. dataType = 5;
  5315. }
  5316. // We now have all the params, lets check to make sure they are valid
  5317. if (!spawn) {
  5318. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (var.length() == 0) {
  5322. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5323. return 0;
  5324. }
  5325. if (dataType == 0) {
  5326. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5327. return 0;
  5328. }
  5329. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5330. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5331. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5332. switch (dataType) {
  5333. case 1:
  5334. // 1 = Spawn
  5335. spawn->AddTempVariable(var, spawnVal);
  5336. break;
  5337. case 2:
  5338. // 2 = Zone
  5339. spawn->AddTempVariable(var, zone);
  5340. break;
  5341. case 3:
  5342. // 3 = Item
  5343. spawn->AddTempVariable(var, item);
  5344. break;
  5345. case 4:
  5346. // 4 = Quest
  5347. spawn->AddTempVariable(var, quest);
  5348. break;
  5349. case 5:
  5350. // 5 = String
  5351. spawn->AddTempVariable(var, val);
  5352. break;
  5353. case 6:
  5354. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5355. spawn->DeleteTempVariable(var);
  5356. break;
  5357. }
  5358. // And we are done so return out
  5359. return 0;
  5360. }
  5361. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5362. if (!lua_interface)
  5363. return 0;
  5364. Spawn* spawn = lua_interface->GetSpawn(state);
  5365. string var = lua_interface->GetStringValue(state, 2);
  5366. if (!spawn) {
  5367. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. if (var.length() == 0) {
  5371. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5372. return 0;
  5373. }
  5374. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5375. int8 type = spawn->GetTempVariableType(var);
  5376. Spawn* spawn2 = 0;
  5377. ZoneServer* zone = 0;
  5378. Item* item = 0;
  5379. Quest* quest = 0;
  5380. // Set the lua function return value based on the type of data the variable contains
  5381. switch (type) {
  5382. case 1:
  5383. spawn2 = spawn->GetTempVariableSpawn(var);
  5384. if (!spawn2)
  5385. return 0;
  5386. lua_interface->SetSpawnValue(state, spawn2);
  5387. break;
  5388. case 2:
  5389. zone = spawn->GetTempVariableZone(var);
  5390. if (!zone)
  5391. return 0;
  5392. lua_interface->SetZoneValue(state, zone);
  5393. break;
  5394. case 3:
  5395. item = spawn->GetTempVariableItem(var);
  5396. if (!item)
  5397. return 0;
  5398. lua_interface->SetItemValue(state, item);
  5399. break;
  5400. case 4:
  5401. quest = spawn->GetTempVariableQuest(var);
  5402. if (!quest)
  5403. return 0;
  5404. lua_interface->SetQuestValue(state, quest);
  5405. break;
  5406. case 5:
  5407. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5408. break;
  5409. default:
  5410. // Not a valid type then the variable was not set so return out
  5411. return 0;
  5412. }
  5413. // Return value was set so return out
  5414. return 1;
  5415. }
  5416. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5417. {
  5418. if (!lua_interface)
  5419. return 0;
  5420. Quest* quest = lua_interface->GetQuest(state);
  5421. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5422. string description = lua_interface->GetStringValue(state, 3);
  5423. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5424. if (!quest) {
  5425. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5426. lua_interface->SetBooleanValue(state, false);
  5427. return 1;
  5428. }
  5429. if (!spawn) {
  5430. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5431. lua_interface->SetBooleanValue(state, false);
  5432. return 1;
  5433. }
  5434. if (!spawn->IsPlayer()) {
  5435. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5436. lua_interface->SetBooleanValue(state, false);
  5437. return 1;
  5438. }
  5439. if (item_id == 0) {
  5440. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5441. lua_interface->SetBooleanValue(state, false);
  5442. return 1;
  5443. }
  5444. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5445. if (!client) {
  5446. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5447. lua_interface->SetBooleanValue(state, false);
  5448. return 1;
  5449. }
  5450. Item* item = master_item_list.GetItem(item_id);
  5451. if (!item) {
  5452. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5453. lua_interface->SetBooleanValue(state, false);
  5454. return 1;
  5455. }
  5456. Item* firstItem = new Item(item);
  5457. quest->AddTmpRewardItem(firstItem);
  5458. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5459. bool itemsAddedSuccessfully = true;
  5460. if(num_args > 4)
  5461. {
  5462. for(int8 n=5;n<num_args+1;n++)
  5463. {
  5464. int32 new_item = lua_interface->GetInt32Value(state, n);
  5465. Item* tmpItem = master_item_list.GetItem(new_item);
  5466. if(tmpItem)
  5467. {
  5468. Item* newTmpItem = new Item(tmpItem);
  5469. quest->AddTmpRewardItem(newTmpItem);
  5470. }
  5471. else
  5472. itemsAddedSuccessfully = false;
  5473. }
  5474. }
  5475. client->AddPendingQuestAcceptReward(quest);
  5476. client->DisplayQuestComplete(quest, true, description);
  5477. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5478. return 1;
  5479. }
  5480. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Quest* quest = lua_interface->GetQuest(state);
  5484. if (!quest) {
  5485. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5486. return 0;
  5487. }
  5488. quest->SetRepeatable(true);
  5489. return 0;
  5490. }
  5491. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5492. if (!lua_interface)
  5493. return 0;
  5494. Spawn* spawn = lua_interface->GetSpawn(state);
  5495. if (!spawn) {
  5496. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5497. return 0;
  5498. }
  5499. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5500. string ret = classes.GetClassNameCase(base_class);
  5501. if (ret.length() > 0) {
  5502. lua_interface->SetStringValue(state, ret.c_str());
  5503. return 1;
  5504. }
  5505. return 0;
  5506. }
  5507. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5508. if (!lua_interface)
  5509. return 0;
  5510. Spawn* player = lua_interface->GetSpawn(state);
  5511. if (player && player->IsPlayer()) {
  5512. Client* client = player->GetClient();
  5513. if (client)
  5514. client->SendWaypoints();
  5515. }
  5516. return 0;
  5517. }
  5518. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5519. if (!lua_interface)
  5520. return 0;
  5521. Spawn* player = lua_interface->GetSpawn(state);
  5522. string name = lua_interface->GetStringValue(state, 2);
  5523. int32 type = lua_interface->GetInt32Value(state, 3);
  5524. if (type == 0)
  5525. type = 2;
  5526. if (name.length() > 0) {
  5527. if (player && player->IsPlayer()) {
  5528. Client* client = player->GetClient();
  5529. if (client)
  5530. client->AddWaypoint(name, type);
  5531. }
  5532. }
  5533. return 0;
  5534. }
  5535. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5536. if (!lua_interface)
  5537. return 0;
  5538. Spawn* player = lua_interface->GetSpawn(state);
  5539. string name = lua_interface->GetStringValue(state, 2);
  5540. if (name.length() > 0) {
  5541. if (player && player->IsPlayer()) {
  5542. Client* client = player->GetClient();
  5543. if (client)
  5544. client->RemoveWaypoint(name);
  5545. }
  5546. }
  5547. return 0;
  5548. }
  5549. int EQ2Emu_lua_AddWard(lua_State* state) {
  5550. if (!lua_interface)
  5551. return 0;
  5552. int32 damage = lua_interface->GetInt32Value(state);
  5553. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5554. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5555. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5556. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5557. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5558. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5559. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5560. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5561. if(!spell || spell->resisted) {
  5562. return 0;
  5563. }
  5564. bool ward_was_added = false;
  5565. ZoneServer* zone = spell->caster->GetZone();
  5566. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5567. for (int32 i = 0; i < spell->targets.size(); i++) {
  5568. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5569. if (!target)
  5570. continue;
  5571. if (target->IsEntity()) {
  5572. // If the ward is already active remove it
  5573. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5574. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5575. // Create new ward info
  5576. WardInfo* ward = new WardInfo;
  5577. ward->Spell = spell;
  5578. ward->BaseDamage = damage;
  5579. ward->DamageLeft = damage;
  5580. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5581. ward->keepWard = keepWard;
  5582. ward->WardType = wardType;
  5583. if (damageAbsorptionPercent > 100)
  5584. damageAbsorptionPercent = 100;
  5585. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5586. if (damageAbsorptionMaxHealthPercent > 100)
  5587. damageAbsorptionMaxHealthPercent = 100;
  5588. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5589. ward->RedirectDamagePercent = redirectDamagePercent;
  5590. ward->LastRedirectDamage = 0;
  5591. ward->LastAbsorbedDamage = 0;
  5592. ward->HitCount = 0;
  5593. spell->num_triggers = maxHitCount;
  5594. spell->had_triggers = true;
  5595. spell->cancel_after_all_triggers = false;
  5596. ward->MaxHitCount = maxHitCount;
  5597. if (wardType == WARD_TYPE_MAGICAL)
  5598. ward->DamageType = damageTypes;
  5599. // Add the ward to the entity
  5600. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5601. ward_was_added = true;
  5602. }
  5603. }
  5604. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5605. if (ward_was_added && spell->caster->IsPlayer()) {
  5606. spell->had_dmg_remaining = true;
  5607. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5608. }
  5609. return 0;
  5610. }
  5611. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5612. if (!lua_interface)
  5613. return 0;
  5614. int32 amount = lua_interface->GetInt32Value(state);
  5615. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5616. WardInfo* ward = 0;
  5617. if(!spell || spell->resisted) {
  5618. return 0;
  5619. }
  5620. ZoneServer* zone = spell->caster->GetZone();
  5621. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5622. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5623. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5624. ward = target->GetWard(spell->spell->GetSpellID());
  5625. if (target && ward) {
  5626. ward->DamageLeft += amount;
  5627. if (ward->DamageLeft > ward->BaseDamage)
  5628. ward->DamageLeft = ward->BaseDamage;
  5629. for (int32 i = 0; i < spell->targets.size(); i++) {
  5630. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5631. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5632. }
  5633. }
  5634. }
  5635. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5636. if (ward && spell->caster->IsPlayer())
  5637. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5638. return 0;
  5639. }
  5640. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5641. if (!lua_interface)
  5642. return 0;
  5643. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5644. if (!spell) {
  5645. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5649. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5650. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5651. if (ward) {
  5652. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5653. return 1;
  5654. }
  5655. }
  5656. return 0;
  5657. }
  5658. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5659. if (!lua_interface)
  5660. return 0;
  5661. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5662. if (!spell) {
  5663. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5664. return 0;
  5665. }
  5666. string type = lua_interface->GetStringValue(state, 2);
  5667. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5668. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5669. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5670. if (ward) {
  5671. if (boost::iequals(type, "damageleft"))
  5672. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5673. else if (boost::iequals(type, "basedamage"))
  5674. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5675. else if (boost::iequals(type, "keepward"))
  5676. lua_interface->SetBooleanValue(state, ward->keepWard);
  5677. else if (boost::iequals(type, "wardtype"))
  5678. lua_interface->SetInt32Value(state, ward->WardType);
  5679. else if (boost::iequals(type, "dmgabsorptionpct"))
  5680. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5681. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5682. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5683. else if (boost::iequals(type, "redirectdamagepercent"))
  5684. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5685. else if (boost::iequals(type, "lastredirectdamage"))
  5686. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5687. else if (boost::iequals(type, "lastabsorbeddamage"))
  5688. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5689. else if (boost::iequals(type, "hitcount"))
  5690. lua_interface->SetInt32Value(state, ward->HitCount);
  5691. else if (boost::iequals(type, "maxhitcount"))
  5692. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5693. else
  5694. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5695. return 1;
  5696. }
  5697. }
  5698. return 0;
  5699. }
  5700. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5701. if (!lua_interface)
  5702. return 0;
  5703. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5704. if(!spell) {
  5705. return 0;
  5706. }
  5707. ZoneServer* zone = spell->caster->GetZone();
  5708. Spawn* target = 0;
  5709. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5710. for (int32 i = 0; i < spell->targets.size(); i++) {
  5711. target = zone->GetSpawnByID(spell->targets.at(i));
  5712. if (target && target->IsEntity()) {
  5713. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5714. }
  5715. }
  5716. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5717. return 0;
  5718. }
  5719. int EQ2Emu_lua_Interrupt(lua_State* state)
  5720. {
  5721. if (!lua_interface)
  5722. return 0;
  5723. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5724. Spawn* target = lua_interface->GetSpawn(state, 2);
  5725. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5726. if (!caster)
  5727. {
  5728. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. if (!target)
  5732. {
  5733. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5734. return 0;
  5735. }
  5736. if (!spell) {
  5737. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5738. return 0;
  5739. }
  5740. if (!target->IsEntity() && !spell)
  5741. {
  5742. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. if (!target && spell) {
  5746. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5747. for (int8 i = 0; i < spell->targets.size(); i++) {
  5748. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5749. if (!target || !target->IsEntity())
  5750. continue;
  5751. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5752. }
  5753. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5754. }
  5755. else
  5756. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5757. return 0;
  5758. }
  5759. int EQ2Emu_lua_Stealth(lua_State* state) {
  5760. if (!lua_interface)
  5761. return 0;
  5762. int8 type = lua_interface->GetInt8Value(state);
  5763. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5764. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5765. if (!spell) {
  5766. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. ZoneServer* zone = spell->caster->GetZone();
  5770. if (spawn) {
  5771. if (spawn->IsEntity()) {
  5772. if (type == 1) {
  5773. ((Entity*)spawn)->AddStealthSpell(spell);
  5774. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5775. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5776. }
  5777. else if (type == 2) {
  5778. ((Entity*)spawn)->AddInvisSpell(spell);
  5779. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5780. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5781. }
  5782. return 0;
  5783. }
  5784. else {
  5785. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5786. return 0;
  5787. }
  5788. }
  5789. else {
  5790. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5791. for (int32 i = 0; i < spell->targets.size(); i++) {
  5792. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5793. if (!spawn || !spawn->IsEntity())
  5794. continue;
  5795. if (type == 1) {
  5796. ((Entity*)spawn)->AddStealthSpell(spell);
  5797. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5798. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5799. }
  5800. else if (type == 2) {
  5801. ((Entity*)spawn)->AddInvisSpell(spell);
  5802. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5803. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5804. }
  5805. else {
  5806. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5807. break;
  5808. }
  5809. }
  5810. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5811. }
  5812. return 0;
  5813. }
  5814. int EQ2Emu_lua_IsStealthed(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 IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. if (spawn->IsEntity()) {
  5823. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5824. return 1;
  5825. }
  5826. else
  5827. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5828. return 0;
  5829. }
  5830. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5831. if (!lua_interface)
  5832. return 0;
  5833. Spawn* spawn = lua_interface->GetSpawn(state);
  5834. if (!spawn) {
  5835. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5836. return 0;
  5837. }
  5838. if (spawn->IsEntity()) {
  5839. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5840. return 1;
  5841. }
  5842. else
  5843. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5844. return 0;
  5845. }
  5846. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5847. if (!lua_interface)
  5848. return 0;
  5849. Spawn* player = lua_interface->GetSpawn(state);
  5850. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5851. lua_interface->ResetFunctionStack(state);
  5852. if (!player->IsPlayer()) {
  5853. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5857. return 1;
  5858. }
  5859. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Spawn* player = lua_interface->GetSpawn(state);
  5863. int8 slot = lua_interface->GetInt8Value(state, 2);
  5864. lua_interface->ResetFunctionStack(state);
  5865. if (!player) {
  5866. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. if (!player->IsPlayer()) {
  5870. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5871. return 0;
  5872. }
  5873. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5874. if (!item) {
  5875. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5876. return 0;
  5877. }
  5878. lua_interface->SetItemValue(state, item);
  5879. return 1;
  5880. }
  5881. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5882. if (!lua_interface)
  5883. return 0;
  5884. Spawn* player = lua_interface->GetSpawn(state);
  5885. int32 id = lua_interface->GetInt32Value(state, 2);
  5886. lua_interface->ResetFunctionStack(state);
  5887. if (!player) {
  5888. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. if (!player->IsPlayer()) {
  5892. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5893. return 0;
  5894. }
  5895. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5896. if (!item) {
  5897. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. lua_interface->SetItemValue(state, item);
  5901. return 1;
  5902. }
  5903. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5904. if (!lua_interface)
  5905. return 0;
  5906. Spawn* spawn = lua_interface->GetSpawn(state);
  5907. int8 slot = lua_interface->GetInt8Value(state, 2);
  5908. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5909. lua_interface->ResetFunctionStack(state);
  5910. if (!spawn) {
  5911. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5912. return 0;
  5913. }
  5914. if (!spawn->IsEntity()) {
  5915. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5916. return 0;
  5917. }
  5918. Item* item = master_item_list.GetItem(item_id);
  5919. if (!item) {
  5920. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5921. return 0;
  5922. }
  5923. Item* copy = new Item(item);
  5924. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5925. if(result)
  5926. {
  5927. ((Entity*)spawn)->SetEquipment(copy, slot);
  5928. spawn->vis_changed = true;
  5929. if(spawn->IsPlayer())
  5930. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5931. }
  5932. else
  5933. {
  5934. safe_delete(copy);
  5935. }
  5936. lua_interface->SetBooleanValue(state, result);
  5937. return 1;
  5938. }
  5939. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. Spawn* spawn = lua_interface->GetSpawn(state);
  5943. int8 slot = lua_interface->GetInt8Value(state, 2);
  5944. Item* item = lua_interface->GetItem(state, 3);
  5945. lua_interface->ResetFunctionStack(state);
  5946. if (!spawn) {
  5947. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5948. return 0;
  5949. }
  5950. if (!spawn->IsEntity()) {
  5951. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5952. return 0;
  5953. }
  5954. if (!item) {
  5955. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5956. return 0;
  5957. }
  5958. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5959. if(result)
  5960. {
  5961. ((Entity*)spawn)->SetEquipment(item, slot);
  5962. spawn->vis_changed = true;
  5963. if(spawn->IsPlayer())
  5964. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5965. }
  5966. lua_interface->SetBooleanValue(state, result);
  5967. return 1;
  5968. }
  5969. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5970. if (!lua_interface)
  5971. return 0;
  5972. Spawn* spawn = lua_interface->GetSpawn(state);
  5973. int8 slot = lua_interface->GetInt8Value(state, 2);
  5974. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5975. lua_interface->ResetFunctionStack(state);
  5976. if (!spawn) {
  5977. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. if (!spawn->IsEntity()) {
  5981. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5982. return 0;
  5983. }
  5984. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5985. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5986. spawn->vis_changed = true;
  5987. if(spawn->IsPlayer())
  5988. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5989. lua_interface->SetBooleanValue(state, true);
  5990. return 1;
  5991. }
  5992. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. int8 slot = lua_interface->GetInt8Value(state, 2);
  5997. int16 type = lua_interface->GetInt16Value(state, 3);
  5998. int8 r = lua_interface->GetInt8Value(state, 4);
  5999. int8 g = lua_interface->GetInt8Value(state, 5);
  6000. int8 b = lua_interface->GetInt8Value(state, 6);
  6001. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6002. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6003. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6004. lua_interface->ResetFunctionStack(state);
  6005. if (!spawn) {
  6006. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. if (!spawn->IsEntity()) {
  6010. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6011. return 0;
  6012. }
  6013. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6014. spawn->vis_changed = true;
  6015. lua_interface->SetBooleanValue(state, true);
  6016. return 1;
  6017. }
  6018. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6019. if (!lua_interface)
  6020. return 0;
  6021. Spawn* player = lua_interface->GetSpawn(state);
  6022. int32 id = lua_interface->GetInt32Value(state, 2);
  6023. int8 count = lua_interface->GetInt8Value(state, 3);
  6024. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6025. lua_interface->ResetFunctionStack(state);
  6026. if (!player) {
  6027. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6028. return 0;
  6029. }
  6030. if (!player->IsPlayer()) {
  6031. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. if (!count)
  6035. count = 1;
  6036. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6037. if (!item) {
  6038. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6039. return 0;
  6040. }
  6041. lua_interface->SetItemValue(state, item);
  6042. return 1;
  6043. }
  6044. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6045. if (!lua_interface)
  6046. return 0;
  6047. Spawn* spawn = lua_interface->GetSpawn(state);
  6048. int32 anim = lua_interface->GetInt32Value(state, 2);
  6049. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6050. int8 type = lua_interface->GetInt8Value(state, 4);
  6051. if (!spawn) {
  6052. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. if (spawn2) {
  6056. if (spawn2->IsPlayer()) {
  6057. if (type != 1 && type != 2)
  6058. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6059. else
  6060. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6061. return 0;
  6062. }
  6063. else {
  6064. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. }
  6068. else
  6069. spawn->GetZone()->PlayAnimation(spawn, anim);
  6070. return 0;
  6071. }
  6072. int EQ2Emu_lua_IsPet(lua_State* state) {
  6073. if (!lua_interface)
  6074. return 0;
  6075. Spawn* spawn = lua_interface->GetSpawn(state);
  6076. if (!spawn) {
  6077. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6081. return 1;
  6082. }
  6083. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6084. if (!lua_interface)
  6085. return 0;
  6086. Spawn* spawn = lua_interface->GetSpawn(state);
  6087. if (!spawn) {
  6088. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6089. return 0;
  6090. }
  6091. if (!spawn->IsNPC()) {
  6092. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6093. return 0;
  6094. }
  6095. if (((NPC*)spawn)->GetOwner()) {
  6096. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6097. return 1;
  6098. }
  6099. return 0;
  6100. }
  6101. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6102. if (!lua_interface)
  6103. return 0;
  6104. Spawn* spawn = lua_interface->GetSpawn(state);
  6105. Spawn* target = lua_interface->GetSpawn(state, 2);
  6106. if (!spawn) {
  6107. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6108. return 0;
  6109. }
  6110. if (!spawn) {
  6111. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6112. return 0;
  6113. }
  6114. spawn->SetTarget(target);
  6115. return 0;
  6116. }
  6117. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6118. if (!lua_interface)
  6119. return 0;
  6120. Spawn* spawn = lua_interface->GetSpawn(state);
  6121. bool val = lua_interface->GetBooleanValue(state, 2);
  6122. if (!spawn) {
  6123. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. if (!spawn->IsEntity()) {
  6127. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. ((Entity*)spawn)->InCombat(val);
  6131. if (val) {
  6132. spawn->ClearRunningLocations();
  6133. spawn->CalculateRunningLocation(true);
  6134. }
  6135. return 0;
  6136. }
  6137. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6138. if (!lua_interface)
  6139. return 0;
  6140. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6141. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6142. if (!spawn1) {
  6143. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. if (!spawn2) {
  6147. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6148. return 0;
  6149. }
  6150. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6151. return 1;
  6152. }
  6153. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6154. if (!lua_interface)
  6155. return 0;
  6156. Spawn* spawn = lua_interface->GetSpawn(state);
  6157. if (!spawn) {
  6158. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6159. return 0;
  6160. }
  6161. if (!spawn->IsNPC()) {
  6162. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6163. return 0;
  6164. }
  6165. ((NPC*)spawn)->ClearRunback();
  6166. return 0;
  6167. }
  6168. int EQ2Emu_lua_Runback(lua_State* state) {
  6169. if (!lua_interface)
  6170. return 0;
  6171. Spawn* spawn = lua_interface->GetSpawn(state);
  6172. if (!spawn) {
  6173. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6174. return 0;
  6175. }
  6176. if (!spawn->IsNPC()) {
  6177. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6178. return 0;
  6179. }
  6180. ((NPC*)spawn)->Runback();
  6181. return 0;
  6182. }
  6183. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6184. if (!lua_interface)
  6185. return 0;
  6186. Spawn* spawn = lua_interface->GetSpawn(state);
  6187. if (!spawn) {
  6188. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. if (!spawn->IsNPC()) {
  6192. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6193. return 0;
  6194. }
  6195. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6196. return 1;
  6197. }
  6198. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6199. if (!lua_interface)
  6200. return 0;
  6201. Spawn* spawn = lua_interface->GetSpawn(state);
  6202. if (!spawn) {
  6203. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. if (!spawn->IsEntity()) {
  6207. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6208. return 0;
  6209. }
  6210. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6211. return 1;
  6212. }
  6213. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6214. if (!lua_interface)
  6215. return 0;
  6216. Spawn* spawn = lua_interface->GetSpawn(state);
  6217. if (!spawn) {
  6218. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6219. return 0;
  6220. }
  6221. if (!spawn->IsEntity()) {
  6222. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6226. return 1;
  6227. }
  6228. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6229. if (!lua_interface)
  6230. return 0;
  6231. Spawn* spawn = lua_interface->GetSpawn(state);
  6232. if (!spawn) {
  6233. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6234. return 0;
  6235. }
  6236. if (!spawn->IsEntity()) {
  6237. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6241. return 1;
  6242. }
  6243. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6244. if (!lua_interface)
  6245. return 0;
  6246. Spawn* spawn = lua_interface->GetSpawn(state);
  6247. if (!spawn) {
  6248. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!spawn->IsEntity()) {
  6252. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6256. return 1;
  6257. }
  6258. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6259. if (!lua_interface)
  6260. return 0;
  6261. Spawn* spawn = lua_interface->GetSpawn(state);
  6262. Spawn* target = lua_interface->GetSpawn(state, 2);
  6263. float distance = lua_interface->GetFloatValue(state, 3);
  6264. if (!spawn) {
  6265. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. if (!target) {
  6269. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!spawn->IsNPC()) {
  6273. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. if (!target->IsEntity()) {
  6277. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6278. return 0;
  6279. }
  6280. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6281. return 1;
  6282. }
  6283. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6284. if (!lua_interface)
  6285. return 0;
  6286. Spawn* spawn = lua_interface->GetSpawn(state);
  6287. Spawn* target = lua_interface->GetSpawn(state, 2);
  6288. float distance = lua_interface->GetFloatValue(state, 3);
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!target) {
  6294. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (!spawn->IsNPC()) {
  6298. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. if (!target->IsEntity()) {
  6302. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6303. return 0;
  6304. }
  6305. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6306. return 0;
  6307. }
  6308. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6309. if (!lua_interface)
  6310. return 0;
  6311. Spawn* spawn = lua_interface->GetSpawn(state);
  6312. if (!spawn) {
  6313. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6314. return 0;
  6315. }
  6316. if (!spawn->IsNPC()) {
  6317. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6321. return 1;
  6322. }
  6323. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6324. if (!lua_interface)
  6325. return 0;
  6326. Spawn* spawn = lua_interface->GetSpawn(state);
  6327. if (!spawn) {
  6328. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6329. return 0;
  6330. }
  6331. if (!spawn->IsNPC()) {
  6332. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6333. return 0;
  6334. }
  6335. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6336. return 1;
  6337. }
  6338. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6339. if (!lua_interface)
  6340. return 0;
  6341. Spawn* spawn = lua_interface->GetSpawn(state);
  6342. if (!spawn) {
  6343. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6344. return 0;
  6345. }
  6346. if (!spawn->IsNPC()) {
  6347. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6348. return 0;
  6349. }
  6350. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6351. if (hated) {
  6352. lua_interface->SetSpawnValue(state, hated);
  6353. return 1;
  6354. }
  6355. return 0;
  6356. }
  6357. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6358. if (!lua_interface)
  6359. return 0;
  6360. Spawn* spawn = lua_interface->GetSpawn(state);
  6361. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6362. if (!spawn) {
  6363. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (!spawn->IsNPC()) {
  6367. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6368. return 0;
  6369. }
  6370. if (!hated) {
  6371. ((NPC*)spawn)->Brain()->ClearHate();
  6372. return 0;
  6373. }
  6374. else
  6375. {
  6376. if (!hated->IsEntity()) {
  6377. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6378. return 0;
  6379. }
  6380. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6381. return 0;
  6382. }
  6383. return 0;
  6384. }
  6385. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6386. if (!lua_interface)
  6387. return 0;
  6388. Spawn* spawn = lua_interface->GetSpawn(state);
  6389. if (!spawn) {
  6390. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6391. return 0;
  6392. }
  6393. if (!spawn->IsNPC()) {
  6394. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6395. return 0;
  6396. }
  6397. ((NPC*)spawn)->Brain()->ClearEncounter();
  6398. return 0;
  6399. }
  6400. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6401. if (!lua_interface)
  6402. return 0;
  6403. Spawn* spawn = lua_interface->GetSpawn(state);
  6404. if (!spawn) {
  6405. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6406. return 0;
  6407. }
  6408. if (!spawn->IsNPC()) {
  6409. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6410. return 0;
  6411. }
  6412. // Temp list to store hate list
  6413. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6414. if (encounterList->size() == 0) {
  6415. safe_delete(encounterList);
  6416. return 0;
  6417. }
  6418. lua_createtable(state, encounterList->size(), 0);
  6419. int newTable = lua_gettop(state);
  6420. for (int32 i = 0; i < encounterList->size(); i++) {
  6421. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6422. if (temp)
  6423. lua_interface->SetSpawnValue(state, temp);
  6424. lua_rawseti(state, newTable, i + 1);
  6425. }
  6426. safe_delete(encounterList);
  6427. return 1;
  6428. }
  6429. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6430. if (!lua_interface)
  6431. return 0;
  6432. Spawn* spawn = lua_interface->GetSpawn(state);
  6433. if (!spawn) {
  6434. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. if (!spawn->IsNPC()) {
  6438. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. // Temp list to store hate list
  6442. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6443. if (hateList->size() == 0) {
  6444. safe_delete(hateList);
  6445. return 0;
  6446. }
  6447. lua_createtable(state, hateList->size(), 0);
  6448. int newTable = lua_gettop(state);
  6449. for (int32 i = 0; i < hateList->size(); i++) {
  6450. lua_interface->SetSpawnValue(state, hateList->at(i));
  6451. lua_rawseti(state, newTable, i + 1);
  6452. }
  6453. safe_delete(hateList);
  6454. return 1;
  6455. }
  6456. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6457. if (!lua_interface)
  6458. return 0;
  6459. Spawn* spawn = lua_interface->GetSpawn(state);
  6460. if (!spawn) {
  6461. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. if (spawn->IsPlayer()) {
  6465. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6466. lua_interface->SetBooleanValue(state, true);
  6467. else
  6468. lua_interface->SetBooleanValue(state, false);
  6469. return 1;
  6470. }
  6471. else {
  6472. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6473. return 1;
  6474. }
  6475. }
  6476. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6477. if (!lua_interface)
  6478. return 0;
  6479. Quest* quest = lua_interface->GetQuest(state);
  6480. if (!quest) {
  6481. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6482. return 0;
  6483. }
  6484. quest->SetCompletedFlag(true);
  6485. return 0;
  6486. }
  6487. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6488. if (!lua_interface)
  6489. return 0;
  6490. Spawn* spawn = lua_interface->GetSpawn(state);
  6491. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6492. int8 tier = lua_interface->GetInt8Value(state, 3);
  6493. if (!spawn) {
  6494. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. if (!spawn->IsEntity()) {
  6498. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6499. return 0;
  6500. }
  6501. if (spellID == 0) {
  6502. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6506. if (effect) {
  6507. if (tier > 0) {
  6508. // If a tier was passed chec to see if it is the same as the effect
  6509. if (tier == effect->tier)
  6510. lua_interface->SetBooleanValue(state, true);
  6511. else
  6512. lua_interface->SetBooleanValue(state, false);
  6513. return 1;
  6514. }
  6515. else {
  6516. // Have an effect but no tier was passed so return true
  6517. lua_interface->SetBooleanValue(state, true);
  6518. }
  6519. return 1;
  6520. }
  6521. // no effect so return false
  6522. lua_interface->SetBooleanValue(state, false);
  6523. return 1;
  6524. }
  6525. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6526. if (!lua_interface)
  6527. return 0;
  6528. Spawn* spawn = lua_interface->GetSpawn(state);
  6529. int32 id = lua_interface->GetInt32Value(state, 2);
  6530. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6531. Spawn* spawn2 = 0;
  6532. vector<Spawn*> list;
  6533. if (!spawn) {
  6534. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6535. return 0;
  6536. }
  6537. //If zone not provided, use spawn's zone
  6538. if (!zone)
  6539. zone = spawn->GetZone();
  6540. list = zone->GetSpawnsByID(id);
  6541. if (list.size() == 0) {
  6542. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. vector<Spawn*>::iterator itr = list.begin();
  6546. for (int8 i = 0; i < list.size(); i++) {
  6547. spawn2 = itr[i];
  6548. if (spawn2)
  6549. spawn2->AddAllowAccessSpawn(spawn);
  6550. }
  6551. return 0;
  6552. }
  6553. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6554. if (!lua_interface)
  6555. return 0;
  6556. Spawn* spawn = lua_interface->GetSpawn(state);
  6557. int32 id = lua_interface->GetInt32Value(state, 2);
  6558. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6559. Spawn* spawn2 = 0;
  6560. if (!spawn) {
  6561. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6562. return 0;
  6563. }
  6564. //If zone not provided, use spawn's zone
  6565. if (!zone)
  6566. zone = spawn->GetZone();
  6567. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6568. vector<Spawn*>::iterator itr = list.begin();
  6569. if (list.size() == 0) {
  6570. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6571. return 0;
  6572. }
  6573. for (int8 i = 0; i < list.size(); i++) {
  6574. spawn2 = itr[i];
  6575. if (spawn2)
  6576. spawn2->RemoveSpawnAccess(spawn);
  6577. }
  6578. return 0;
  6579. }
  6580. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6581. if (!lua_interface)
  6582. return 0;
  6583. Quest* quest = lua_interface->GetQuest(state);
  6584. if (!quest) {
  6585. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. quest->SetYellowName(true);
  6589. return 0;
  6590. }
  6591. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6592. if (!lua_interface)
  6593. return 0;
  6594. Spawn* spawn = lua_interface->GetSpawn(state);
  6595. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6596. if (!spawn) {
  6597. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6598. return 0;
  6599. }
  6600. if (!spawn->IsPlayer()) {
  6601. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6605. return 1;
  6606. }
  6607. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6608. if (!lua_interface)
  6609. return 0;
  6610. Spawn* spawn = lua_interface->GetSpawn(state);
  6611. if (!spawn) {
  6612. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. if (!spawn->IsPlayer()) {
  6616. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6617. return 0;
  6618. }
  6619. ZoneServer* zone = spawn->GetZone();
  6620. if (!zone) {
  6621. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. Instance_Type iType = zone->GetInstanceType();
  6625. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6626. iType == GROUP_LOCKOUT_INSTANCE ||
  6627. iType == RAID_LOCKOUT_INSTANCE ||
  6628. iType == SOLO_PERSIST_INSTANCE ||
  6629. iType == GROUP_PERSIST_INSTANCE ||
  6630. iType == RAID_PERSIST_INSTANCE) {
  6631. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6632. if (data) {
  6633. // Check to see if the timer has already been set, if it has return out.
  6634. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6635. return 0;
  6636. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6637. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6638. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6639. if (client) {
  6640. string time_msg = "";
  6641. int32 time = data->success_lockout_time;
  6642. int16 hour;
  6643. int8 min;
  6644. int8 sec;
  6645. hour = time / 3600;
  6646. time = time % 3600;
  6647. min = time / 60;
  6648. time = time % 60;
  6649. sec = time;
  6650. if (hour > 0) {
  6651. char temp[10];
  6652. sprintf(temp, " %i", hour);
  6653. time_msg.append(temp);
  6654. time_msg.append(" hour");
  6655. time_msg.append((hour > 1) ? "s" : "");
  6656. }
  6657. if (min > 0) {
  6658. char temp[5];
  6659. sprintf(temp, " %i", min);
  6660. time_msg.append(temp);
  6661. time_msg.append(" minute");
  6662. time_msg.append((min > 1) ? "s" : "");
  6663. }
  6664. // Only add seconds if minutes and hours are 0
  6665. if (hour == 0 && min == 0 && sec > 0) {
  6666. char temp[5];
  6667. sprintf(temp, " %i", sec);
  6668. time_msg.append(temp);
  6669. time_msg.append(" second");
  6670. time_msg.append((sec > 1) ? "s" : "");
  6671. }
  6672. 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());
  6673. }
  6674. }
  6675. else
  6676. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6677. }
  6678. else
  6679. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6683. if (!lua_interface)
  6684. return 0;
  6685. Spawn* spawn = lua_interface->GetSpawn(state);
  6686. if (!spawn) {
  6687. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6688. return 0;
  6689. }
  6690. if (!spawn->IsPlayer()) {
  6691. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. ZoneServer* zone = spawn->GetZone();
  6695. if (!zone) {
  6696. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. Instance_Type iType = zone->GetInstanceType();
  6700. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6701. iType == GROUP_LOCKOUT_INSTANCE ||
  6702. iType == RAID_LOCKOUT_INSTANCE ||
  6703. iType == SOLO_PERSIST_INSTANCE ||
  6704. iType == GROUP_PERSIST_INSTANCE ||
  6705. iType == RAID_PERSIST_INSTANCE) {
  6706. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6707. if (data) {
  6708. // Check to see if the timer has already been set, if it has return out.
  6709. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6710. return 0;
  6711. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6712. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6713. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6714. if (client) {
  6715. string time_msg = "";
  6716. int32 time = data->failure_lockout_time;
  6717. int16 hour;
  6718. int8 min;
  6719. int8 sec;
  6720. hour = time / 3600;
  6721. time = time % 3600;
  6722. min = time / 60;
  6723. time = time % 60;
  6724. sec = time;
  6725. if (hour > 0) {
  6726. char temp[10];
  6727. sprintf(temp, " %i", hour);
  6728. time_msg.append(temp);
  6729. time_msg.append(" hour");
  6730. time_msg.append((hour > 1) ? "s" : "");
  6731. }
  6732. if (min > 0) {
  6733. char temp[5];
  6734. sprintf(temp, " %i", min);
  6735. time_msg.append(temp);
  6736. time_msg.append(" minute");
  6737. time_msg.append((min > 1) ? "s" : "");
  6738. }
  6739. // Only add seconds if minutes and hours are 0
  6740. if (hour == 0 && min == 0 && sec > 0) {
  6741. char temp[5];
  6742. sprintf(temp, " %i", sec);
  6743. time_msg.append(temp);
  6744. time_msg.append(" second");
  6745. time_msg.append((sec > 1) ? "s" : "");
  6746. }
  6747. 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());
  6748. }
  6749. }
  6750. else
  6751. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6752. }
  6753. else
  6754. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6758. if (!lua_interface)
  6759. return 0;
  6760. Spawn* spawn = lua_interface->GetSpawn(state);
  6761. if (!spawn) {
  6762. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6766. return 1;
  6767. }
  6768. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6769. if (!lua_interface)
  6770. return 0;
  6771. Spawn* player = lua_interface->GetSpawn(state);
  6772. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6773. if (!player) {
  6774. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. if (!player->IsPlayer()) {
  6778. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6779. return 0;
  6780. }
  6781. if (!ground) {
  6782. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6783. return 0;
  6784. }
  6785. if (!ground->IsGroundSpawn()) {
  6786. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6787. return 0;
  6788. }
  6789. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6790. if (!groundspawn_entries) {
  6791. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6792. return 0;
  6793. }
  6794. Skill* skill = 0;
  6795. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6796. if (collection_skill == "Collecting")
  6797. skill = ((Player*)player)->GetSkillByName("Gathering");
  6798. else
  6799. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6800. if (!skill) {
  6801. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6802. return 0;
  6803. }
  6804. vector<GroundSpawnEntry*>::iterator itr;
  6805. GroundSpawnEntry* entry = 0;
  6806. bool can_harvest = false;
  6807. sint32 min_skill = -1;
  6808. int16 totalSkill = skill->current_val;
  6809. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6810. if(skillID != 0xFFFFFFFF)
  6811. {
  6812. ((Entity*)player)->MStats.lock();
  6813. totalSkill += ((Entity*)player)->stats[skillID];
  6814. ((Entity*)player)->MStats.unlock();
  6815. }
  6816. // first, iterate through groundspawn_entries, discard tables player cannot use
  6817. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6818. {
  6819. entry = *itr;
  6820. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6821. min_skill = entry->min_skill_level;
  6822. // if player lacks skill, skip table
  6823. if (entry->min_skill_level > totalSkill)
  6824. continue;
  6825. // if bonus, but player lacks level, skip table
  6826. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6827. continue;
  6828. can_harvest = true;
  6829. break;
  6830. }
  6831. lua_interface->SetBooleanValue(state, can_harvest);
  6832. // If false, send the message to the client
  6833. if (!can_harvest) {
  6834. Client* client = player->GetZone()->GetClientBySpawn(player);
  6835. if (client) {
  6836. string msg = "You do not have enough skill to ";
  6837. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6838. msg.append("gather");
  6839. else if (collection_skill == "Mining")
  6840. msg.append("mine");
  6841. else if (collection_skill == "Trapping")
  6842. msg.append("trap");
  6843. else if (collection_skill == "Foresting")
  6844. msg.append("forest");
  6845. else if (collection_skill == "Fishing")
  6846. msg.append("catch");
  6847. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6848. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6849. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6850. }
  6851. }
  6852. return 1;
  6853. }
  6854. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6855. if (!lua_interface)
  6856. return 0;
  6857. Spawn* player = lua_interface->GetSpawn(state);
  6858. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6859. if (!player) {
  6860. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6861. return 0;
  6862. }
  6863. if (!player->IsPlayer()) {
  6864. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6865. return 0;
  6866. }
  6867. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6868. lua_interface->SetBooleanValue(state, ret);
  6869. return 1;
  6870. }
  6871. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6872. // Check to see if we have a valid lua_interface
  6873. if (!lua_interface)
  6874. return 0;
  6875. // Get the spawn that is getting the pet
  6876. Spawn* spawn = lua_interface->GetSpawn(state);
  6877. Spawn* target = lua_interface->GetSpawn(state, 2);
  6878. // Get the DB ID of the pet
  6879. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6880. float x = lua_interface->GetFloatValue(state, 4);
  6881. float y = lua_interface->GetFloatValue(state, 5);
  6882. float z = lua_interface->GetFloatValue(state, 6);
  6883. // Get the spell that this command was called from
  6884. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6885. // Check to make sure the spawn pointer is valid
  6886. if (!spawn) {
  6887. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6888. return 0;
  6889. }
  6890. // Check to make sure the spawn is an entity
  6891. if (!spawn->IsEntity()) {
  6892. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6893. return 0;
  6894. }
  6895. if (!target) {
  6896. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6897. return 0;
  6898. }
  6899. if (!target->IsEntity()) {
  6900. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6901. return 0;
  6902. }
  6903. // Check to see if the DB ID for the pet is set
  6904. if (pet_id == 0) {
  6905. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6906. return 0;
  6907. }
  6908. // Check to see if the pointer to the spell is valid
  6909. if (!luaspell) {
  6910. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6911. return 0;
  6912. }
  6913. if(luaspell->resisted) {
  6914. return 0;
  6915. }
  6916. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6917. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6918. if (!pet) {
  6919. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6920. return 0;
  6921. }
  6922. // Check to make sure the pet is an npc
  6923. if (!pet->IsNPC()) {
  6924. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6925. return 0;
  6926. }
  6927. if (x == 0)
  6928. x = spawn->GetX();
  6929. if (y == 0)
  6930. y = spawn->GetY();
  6931. if (z == 0)
  6932. z = spawn->GetZ();
  6933. // Spawn the pet at the same location as the owner
  6934. pet->SetX(x);
  6935. pet->SetY(y);
  6936. pet->SetZ(z);
  6937. pet->SetLocation(spawn->GetLocation());
  6938. pet->SetHeading(spawn->GetHeading());
  6939. spawn->GetZone()->AddSpawn(pet);
  6940. /*
  6941. const char* spawn_script = world.GetSpawnScript(pet_id);
  6942. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6943. spawn->SetSpawnScript(string(spawn_script));
  6944. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6945. }*/
  6946. // Get a random pet name
  6947. string random_pet_name;
  6948. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6949. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6950. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6951. // Set the pets name
  6952. pet->SetName(random_pet_name.c_str());
  6953. // Set the level of the pet to the owners level
  6954. pet->SetLevel(spawn->GetLevel());
  6955. // Set the faction of the pet to the same faction as the owner
  6956. pet->SetFactionID(spawn->GetFactionID());
  6957. // Set the spawn as a pet
  6958. pet->SetPet(true);
  6959. // Give a pointer of the owner to the pet
  6960. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6961. // Set the pet type
  6962. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6963. // Set the spell id used to create this pet
  6964. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6965. // Set the spell tier used to create this pet
  6966. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6967. // Set the pets spawn type to 6
  6968. pet->SetSpawnType(6);
  6969. // Set the pets brain
  6970. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6971. // Check to see if the pet has a subtitle
  6972. if (strlen(pet->GetSubTitle()) > 0) {
  6973. // Add the players name to the front of the sub title
  6974. string pet_subtitle;
  6975. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6976. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6977. // Set the pets subtitle to the new one
  6978. pet->SetSubTitle(pet_subtitle.c_str());
  6979. }
  6980. // Set the pet as the return value for this function
  6981. lua_interface->SetSpawnValue(state, pet);
  6982. return 1;
  6983. }
  6984. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6985. if (!lua_interface)
  6986. return 0;
  6987. Spawn* spawn = lua_interface->GetSpawn(state);
  6988. Spawn* player = lua_interface->GetSpawn(state, 2);
  6989. float max_distance = lua_interface->GetFloatValue(state, 3);
  6990. string type = lua_interface->GetStringValue(state, 4);
  6991. if (!spawn || (spawn && spawn->IsPlayer())) {
  6992. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. if (!player || (player && !player->IsPlayer())) {
  6996. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6997. return 0;
  6998. }
  6999. Client* client = 0;
  7000. if (player->GetZone())
  7001. client = player->GetZone()->GetClientBySpawn(player);
  7002. if (!client) {
  7003. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7004. return 0;
  7005. }
  7006. //Set max_distance to default if not set or not proper value
  7007. if (max_distance <= 0)
  7008. max_distance = 500;
  7009. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7010. if (packet) {
  7011. float unknown2_3 = 0;
  7012. int8 placement_mode = 0;
  7013. if (type == "wall") {
  7014. placement_mode = 2;
  7015. unknown2_3 = 150;
  7016. }
  7017. else if (type == "ceiling")
  7018. placement_mode = 1;
  7019. packet->setDataByName("placement_mode", placement_mode);
  7020. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7021. packet->setDataByName("model_type", spawn->GetModelType());
  7022. packet->setDataByName("unknown", 1); //size
  7023. packet->setDataByName("unknown2", 1); //size 2
  7024. packet->setDataByName("unknown2", .5, 1); //size 3
  7025. packet->setDataByName("unknown2", 3, 2);
  7026. packet->setDataByName("unknown2", unknown2_3, 3);
  7027. packet->setDataByName("max_distance", max_distance);
  7028. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7029. client->QueuePacket(packet->serialize());
  7030. safe_delete(packet);
  7031. }
  7032. return 0;
  7033. }
  7034. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7035. if (!lua_interface)
  7036. return 0;
  7037. Item* item = lua_interface->GetItem(state);
  7038. if (!item) {
  7039. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7043. return 1;
  7044. }
  7045. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7046. if (!lua_interface)
  7047. return 0;
  7048. Spawn* spawn = lua_interface->GetSpawn(state);
  7049. if (!spawn) {
  7050. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. if (spawn->GetZone())
  7054. spawn->GetZone()->AddTransportSpawn(spawn);
  7055. return 0;
  7056. }
  7057. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7058. if (!lua_interface)
  7059. return 0;
  7060. Spawn* spawn = lua_interface->GetSpawn(state);
  7061. if (!spawn) {
  7062. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7063. return 0;
  7064. }
  7065. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7066. return 1;
  7067. }
  7068. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7069. if (!lua_interface)
  7070. return 0;
  7071. Skill* skill = lua_interface->GetSkill(state);
  7072. if (!skill) {
  7073. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7074. return 0;
  7075. }
  7076. lua_interface->SetInt32Value(state, skill->current_val);
  7077. return 1;
  7078. }
  7079. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7080. if (!lua_interface)
  7081. return 0;
  7082. Skill* skill = lua_interface->GetSkill(state);
  7083. if (!skill) {
  7084. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. lua_interface->SetInt32Value(state, skill->max_val);
  7088. return 1;
  7089. }
  7090. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7091. if (!lua_interface)
  7092. return 0;
  7093. Skill* skill = lua_interface->GetSkill(state);
  7094. if (!skill) {
  7095. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7096. return 0;
  7097. }
  7098. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7099. return 1;
  7100. }
  7101. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7102. if (!lua_interface)
  7103. return 0;
  7104. Skill* skill = lua_interface->GetSkill(state);
  7105. int16 value = lua_interface->GetInt16Value(state, 2);
  7106. if (!skill) {
  7107. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7108. return 0;
  7109. }
  7110. skill->max_val = value;
  7111. if (skill->max_val < skill->current_val)
  7112. skill->current_val = skill->max_val;
  7113. return 0;
  7114. }
  7115. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7116. if (!lua_interface)
  7117. return 0;
  7118. Skill* skill = lua_interface->GetSkill(state);
  7119. int16 value = lua_interface->GetInt16Value(state, 2);
  7120. if (!skill) {
  7121. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (value > skill->max_val)
  7125. skill->current_val = skill->max_val;
  7126. else
  7127. skill->current_val = value;
  7128. return 0;
  7129. }
  7130. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7131. if (!lua_interface)
  7132. return 0;
  7133. Spawn* player = lua_interface->GetSpawn(state);
  7134. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7135. if (skill_id > 0 && player && player->IsPlayer()) {
  7136. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7137. return 1;
  7138. }
  7139. return 0;
  7140. }
  7141. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7142. if (!lua_interface)
  7143. return 0;
  7144. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7145. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7146. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7147. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7148. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7149. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7150. if (player_spawn && player_spawn->IsPlayer()) {
  7151. Player* player = (Player*)player_spawn;
  7152. bool added = false;
  7153. if (!player->skill_list.HasSkill(skill_id)) {
  7154. player->AddSkill(skill_id, current_val, max_val, true);
  7155. added = true;
  7156. }
  7157. 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
  7158. Client* client = player->GetClient();
  7159. if (client) {
  7160. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7161. if (packet)
  7162. client->QueuePacket(packet);
  7163. }
  7164. }
  7165. if (added) {
  7166. lua_interface->SetBooleanValue(state, true);
  7167. return 1;
  7168. }
  7169. }
  7170. else {
  7171. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7172. }
  7173. }
  7174. else {
  7175. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7176. }
  7177. lua_interface->SetBooleanValue(state, false);
  7178. return 1;
  7179. }
  7180. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7181. if (!lua_interface)
  7182. return 0;
  7183. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7184. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7185. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7186. if (skill_id > 0) {
  7187. if (player_spawn && player_spawn->IsPlayer()) {
  7188. Player* player = (Player*)player_spawn;
  7189. if (player->skill_list.HasSkill(skill_id)) {
  7190. player->RemovePlayerSkill(skill_id);
  7191. if (!more_to_remove) {
  7192. Client* client = player->GetClient();
  7193. if (client) {
  7194. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7195. if (packet)
  7196. client->QueuePacket(packet);
  7197. }
  7198. }
  7199. }
  7200. }
  7201. else {
  7202. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7203. }
  7204. }
  7205. else {
  7206. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7207. }
  7208. return 0;
  7209. }
  7210. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7211. if (!lua_interface)
  7212. return 0;
  7213. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7214. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7215. int16 amount = lua_interface->GetInt8Value(state, 3);
  7216. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7217. if (amount > 0 && skill_type < 100) {
  7218. if (player_spawn && player_spawn->IsPlayer()) {
  7219. Player* player = (Player*)player_spawn;
  7220. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7221. if (!more_to_increase) {
  7222. Client* client = player->GetClient();
  7223. if (client) {
  7224. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7225. if (packet)
  7226. client->QueuePacket(packet);
  7227. }
  7228. }
  7229. }
  7230. else {
  7231. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7232. }
  7233. }
  7234. else {
  7235. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7236. }
  7237. return 0;
  7238. }
  7239. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7240. if (!lua_interface)
  7241. return 0;
  7242. Spawn* spawn = lua_interface->GetSpawn(state);
  7243. string name = lua_interface->GetStringValue(state, 2);
  7244. if (!spawn) {
  7245. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7246. return 0;
  7247. }
  7248. if (!spawn->IsEntity()) {
  7249. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7250. return 0;
  7251. }
  7252. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7253. if (skill) {
  7254. lua_interface->SetSkillValue(state, skill);
  7255. return 1;
  7256. }
  7257. return 0;
  7258. }
  7259. int EQ2Emu_lua_AddProc(lua_State* state) {
  7260. if (!lua_interface)
  7261. return 0;
  7262. Spawn* spawn = lua_interface->GetSpawn(state);
  7263. int8 type = lua_interface->GetInt8Value(state, 2);
  7264. float chance = lua_interface->GetFloatValue(state, 3);
  7265. Item* item = lua_interface->GetItem(state, 4);
  7266. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7267. LuaSpell* spell = 0;
  7268. if (!spawn && (!spell || !use_all_spelltargets)) {
  7269. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7270. return 0;
  7271. }
  7272. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7273. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7274. return 0;
  7275. }
  7276. if (!item)
  7277. spell = lua_interface->GetCurrentSpell(state);
  7278. if (!item && !spell) {
  7279. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7280. return 0;
  7281. }
  7282. if(spell && spell->resisted) {
  7283. return 0;
  7284. }
  7285. if (spell && use_all_spelltargets) {
  7286. Spawn* target;
  7287. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7288. for (int8 i = 0; i < spell->targets.size(); i++) {
  7289. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7290. if (!target || !target->IsEntity())
  7291. continue;
  7292. ((Entity*)target)->AddProc(type, chance, item, spell);
  7293. }
  7294. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7295. }
  7296. else
  7297. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7298. return 0;
  7299. }
  7300. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7301. if (!lua_interface)
  7302. return 0;
  7303. Spawn* spawn = lua_interface->GetSpawn(state);
  7304. Item* item = lua_interface->GetItem(state, 2);
  7305. LuaSpell* spell = 0;
  7306. if (!spawn) {
  7307. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7308. return 0;
  7309. }
  7310. if (!spawn->IsEntity()) {
  7311. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7312. return 0;
  7313. }
  7314. if (!item)
  7315. spell = lua_interface->GetCurrentSpell(state);
  7316. if (!item && !spell) {
  7317. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7318. return 0;
  7319. }
  7320. if (spell) {
  7321. Spawn* target;
  7322. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7323. for (int8 i = 0; i < spell->targets.size(); i++) {
  7324. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7325. if (!target || !target->IsEntity())
  7326. continue;
  7327. ((Entity*)target)->RemoveProc(item, spell);
  7328. }
  7329. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7330. spell->caster->RemoveProc(item, spell);
  7331. }
  7332. else
  7333. ((Entity*)spawn)->RemoveProc(item, spell);
  7334. return 0;
  7335. }
  7336. int EQ2Emu_lua_Knockback(lua_State* state) {
  7337. if (!lua_interface)
  7338. return 0;
  7339. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7340. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7341. int32 duration = lua_interface->GetInt32Value(state, 3);
  7342. float vertical = lua_interface->GetFloatValue(state, 4);
  7343. float horizontal = lua_interface->GetFloatValue(state, 5);
  7344. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7345. if (!target_spawn) {
  7346. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. if (!spawn) {
  7350. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7351. return 0;
  7352. }
  7353. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7354. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7355. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7356. if (packet) {
  7357. packet->setDataByName("target_x", target_spawn->GetX());
  7358. packet->setDataByName("target_y", target_spawn->GetY());
  7359. packet->setDataByName("target_z", target_spawn->GetZ());
  7360. packet->setDataByName("vertical_movement", vertical);
  7361. packet->setDataByName("horizontal_movement", horizontal);
  7362. if (use_heading)
  7363. packet->setDataByName("use_player_heading", 1);
  7364. client->QueuePacket(packet->serialize());
  7365. }
  7366. safe_delete(packet);
  7367. }
  7368. return 0;
  7369. }
  7370. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7371. if (!lua_interface)
  7372. return 0;
  7373. Spawn* spawn = lua_interface->GetSpawn(state);
  7374. if (!spawn) {
  7375. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7376. return 0;
  7377. }
  7378. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7379. return 1;
  7380. }
  7381. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7382. if (!lua_interface)
  7383. return 0;
  7384. Spawn* caster = lua_interface->GetSpawn(state);
  7385. Spawn* target = lua_interface->GetSpawn(state, 2);
  7386. string name = lua_interface->GetStringValue(state, 3);
  7387. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7388. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7389. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7390. string success_msg = lua_interface->GetStringValue(state, 7);
  7391. string effect_msg = lua_interface->GetStringValue(state, 8);
  7392. if (!caster) {
  7393. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7394. return 0;
  7395. }
  7396. if (!caster->IsEntity()) {
  7397. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7398. return 0;
  7399. }
  7400. if (!target) {
  7401. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7402. return 0;
  7403. }
  7404. if (!target->IsEntity()) {
  7405. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7406. return 0;
  7407. }
  7408. if (name.length() == 0) {
  7409. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7410. return 0;
  7411. }
  7412. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7413. return 0;
  7414. }
  7415. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7416. if (!lua_interface)
  7417. return 0;
  7418. string name = lua_interface->GetStringValue(state);
  7419. if (name.length() == 0) {
  7420. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7421. return 0;
  7422. }
  7423. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7424. if (!skill) {
  7425. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7426. return 0;
  7427. }
  7428. lua_interface->SetInt32Value(state, skill->skill_id);
  7429. return 1;
  7430. }
  7431. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7432. if (!lua_interface)
  7433. return 0;
  7434. Spawn* spawn = lua_interface->GetSpawn(state);
  7435. if (!spawn) {
  7436. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7437. return 0;
  7438. }
  7439. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7440. return 1;
  7441. }
  7442. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7443. if (!lua_interface)
  7444. return 0;
  7445. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7446. if (!luaspell) {
  7447. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7448. return 0;
  7449. }
  7450. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7451. return 1;
  7452. }
  7453. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7454. if (!lua_interface)
  7455. return 0;
  7456. Spawn* spawn = lua_interface->GetSpawn(state);
  7457. Spawn* target = lua_interface->GetSpawn(state, 2);
  7458. if (!spawn) {
  7459. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7460. return 0;
  7461. }
  7462. if (!spawn->IsEntity()) {
  7463. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7464. return 0;
  7465. }
  7466. if (!target) {
  7467. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7468. return 0;
  7469. }
  7470. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7471. return 1;
  7472. }
  7473. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7474. if (!lua_interface)
  7475. return 0;
  7476. Spawn* spawn = lua_interface->GetSpawn(state);
  7477. Spawn* target = lua_interface->GetSpawn(state, 2);
  7478. if (!spawn) {
  7479. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7480. return 0;
  7481. }
  7482. if (!spawn->IsEntity()) {
  7483. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7484. return 0;
  7485. }
  7486. if (!target) {
  7487. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7488. return 0;
  7489. }
  7490. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7491. return 1;
  7492. }
  7493. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7494. if (!lua_interface)
  7495. return 0;
  7496. Item* item = lua_interface->GetItem(state);
  7497. if (!item) {
  7498. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7499. return 0;
  7500. }
  7501. lua_interface->SetInt32Value(state, item->details.count);
  7502. return 1;
  7503. }
  7504. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7505. if (!lua_interface)
  7506. return 0;
  7507. Item* item = lua_interface->GetItem(state);
  7508. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7509. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7510. if (!item) {
  7511. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7512. return 0;
  7513. }
  7514. if (!owner) {
  7515. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7516. return 0;
  7517. }
  7518. if (!owner->IsPlayer()) {
  7519. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. if (item->stack_count < new_count) {
  7523. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7524. return 0;
  7525. }
  7526. if (new_count > 0) {
  7527. item->details.count = new_count;
  7528. item->save_needed = true;
  7529. }
  7530. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7531. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7532. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7533. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7534. else
  7535. {
  7536. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7537. return 0;
  7538. }
  7539. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7540. if (!client)
  7541. return 0;
  7542. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7543. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7544. if (app)
  7545. client->QueuePacket(app);
  7546. return 0;
  7547. }
  7548. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7549. if (!lua_interface)
  7550. return 0;
  7551. int32 time = lua_interface->GetInt32Value(state);
  7552. string function = lua_interface->GetStringValue(state, 2);
  7553. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7554. Spawn* target = lua_interface->GetSpawn(state, 4);
  7555. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7556. if (time == 0) {
  7557. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7558. return 0;
  7559. }
  7560. if (function.length() == 0) {
  7561. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7562. return 0;
  7563. }
  7564. if (!spell) {
  7565. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7566. return 0;
  7567. }
  7568. SpellScriptTimer* timer = new SpellScriptTimer;
  7569. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7570. #ifdef WIN32
  7571. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7572. #else
  7573. bzero(timer, sizeof(SpellScriptTimer));
  7574. #endif*/
  7575. timer->caster = 0;
  7576. timer->deleteWhenDone = false;
  7577. timer->target = 0;
  7578. timer->time = Timer::GetCurrentTime2() + time;
  7579. timer->customFunction = function;
  7580. timer->spell = spell;
  7581. if (caster)
  7582. timer->caster = caster->GetID();
  7583. if (target)
  7584. timer->target = target->GetID();
  7585. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7586. return 0;
  7587. }
  7588. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7589. if (!lua_interface)
  7590. return 0;
  7591. float hp_perc = lua_interface->GetFloatValue(state);
  7592. float power_perc = lua_interface->GetFloatValue(state, 2);
  7593. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7594. Spawn* target = lua_interface->GetSpawn(state, 4);
  7595. string heal_name = lua_interface->GetStringValue(state, 5);
  7596. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7597. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7598. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7599. if (!spell) {
  7600. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7601. return 0;
  7602. }
  7603. Entity* caster = spell->caster;
  7604. if (!caster) {
  7605. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7606. return 0;
  7607. }
  7608. Client* client = 0;
  7609. PendingResurrection* rez = 0;
  7610. ZoneServer* zone = spell->caster->GetZone();
  7611. if (!target) {
  7612. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7613. if (spell->targets.size() > 0) {
  7614. vector<int32> spell_targets = spell->targets;
  7615. for (int8 i = 0; i < spell_targets.size(); i++) {
  7616. target = zone->GetSpawnByID(spell_targets.at(i));
  7617. if (!target)
  7618. continue;
  7619. if (!target->IsPlayer())
  7620. continue;
  7621. client = target->GetZone()->GetClientBySpawn(target);
  7622. if (!client)
  7623. continue;
  7624. rez = client->GetCurrentRez();
  7625. if (rez->active)
  7626. continue;
  7627. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7628. rez->active = true;
  7629. rez->caster = caster;
  7630. rez->expire_timer = new Timer;
  7631. int32 duration = spell->spell->GetSpellDuration();
  7632. rez->expire_timer->Start(duration * 100);
  7633. rez->hp_perc = hp_perc;
  7634. rez->mp_perc = power_perc;
  7635. rez->range = spell->spell->GetSpellData()->range;
  7636. rez->spell_name = spell->spell->GetName();
  7637. if (heal_name.length() > 0)
  7638. rez->heal_name = heal_name;
  7639. else
  7640. rez->heal_name = rez->spell_name;
  7641. rez->no_calcs = no_calcs;
  7642. rez->crit_mod = crit_mod;
  7643. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7644. if (send_window)
  7645. client->SendResurrectionWindow();
  7646. else {
  7647. target->GetZone()->ResurrectSpawn(target, client);
  7648. rez->should_delete = true;
  7649. }
  7650. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7651. }
  7652. }
  7653. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7654. }
  7655. else {
  7656. client = target->GetZone()->GetClientBySpawn(target);
  7657. if (!client)
  7658. return 0;
  7659. rez = client->GetCurrentRez();
  7660. if (rez->active)
  7661. return 0;
  7662. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7663. rez->active = true;
  7664. rez->caster = caster;
  7665. rez->expire_timer = new Timer;
  7666. int32 duration = spell->spell->GetSpellDuration();
  7667. rez->expire_timer->Start(duration * 100);
  7668. rez->hp_perc = hp_perc;
  7669. rez->mp_perc = power_perc;
  7670. rez->range = spell->spell->GetSpellData()->range;
  7671. rez->spell_name = spell->spell->GetName();
  7672. if (heal_name.length() > 0)
  7673. rez->heal_name = heal_name;
  7674. else
  7675. rez->heal_name = rez->spell_name;
  7676. rez->no_calcs = no_calcs;
  7677. rez->crit_mod = crit_mod;
  7678. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7679. if (send_window)
  7680. client->SendResurrectionWindow();
  7681. else {
  7682. target->GetZone()->ResurrectSpawn(target, client);
  7683. rez->should_delete = true;
  7684. }
  7685. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7686. }
  7687. return 0;
  7688. }
  7689. int EQ2Emu_lua_SetVision(lua_State* state) {
  7690. if (!lua_interface)
  7691. return 0;
  7692. Spawn* spawn = lua_interface->GetSpawn(state);
  7693. int8 vision = lua_interface->GetInt8Value(state, 2);
  7694. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7695. if (!spawn) {
  7696. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. if (!spawn->IsEntity()) {
  7700. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7701. return 0;
  7702. }
  7703. if (spell && spell->targets.size() > 0) {
  7704. ZoneServer* zone = spell->caster->GetZone();
  7705. for (int8 i = 0; i < spell->targets.size(); i++) {
  7706. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7707. if (target && target->IsEntity()) {
  7708. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7709. if (target->IsPlayer())
  7710. ((Player*)target)->SetCharSheetChanged(true);
  7711. }
  7712. }
  7713. }
  7714. else {
  7715. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7716. if (spawn->IsPlayer())
  7717. ((Player*)spawn)->SetCharSheetChanged(true);
  7718. }
  7719. return 0;
  7720. }
  7721. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. Spawn* spawn = lua_interface->GetSpawn(state);
  7725. float intensity = lua_interface->GetFloatValue(state, 2);
  7726. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7727. if (!spawn) {
  7728. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7729. return 0;
  7730. }
  7731. if (!spawn->IsEntity()) {
  7732. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. if (spell && spell->targets.size() > 0) {
  7736. ZoneServer* zone = spell->caster->GetZone();
  7737. for (int8 i = 0; i < spell->targets.size(); i++) {
  7738. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7739. if (target && target->IsEntity()) {
  7740. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7741. if (target->IsPlayer())
  7742. ((Player*)target)->SetCharSheetChanged(true);
  7743. }
  7744. }
  7745. }
  7746. else {
  7747. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7748. if (spawn->IsPlayer())
  7749. ((Player*)spawn)->SetCharSheetChanged(true);
  7750. }
  7751. return 0;
  7752. }
  7753. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7754. if (!lua_interface)
  7755. return 0;
  7756. Spawn* spawn = lua_interface->GetSpawn(state);
  7757. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7758. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7759. if (!spawn) {
  7760. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7761. return 0;
  7762. }
  7763. if (!spawn->IsEntity()) {
  7764. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7765. return 0;
  7766. }
  7767. if (spell && spell->targets.size() > 0) {
  7768. ZoneServer* zone = spell->caster->GetZone();
  7769. for (int8 i = 0; i < spell->targets.size(); i++) {
  7770. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7771. if (target && target->IsEntity()) {
  7772. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7773. if (target->IsPlayer())
  7774. ((Player*)target)->SetCharSheetChanged(true);
  7775. }
  7776. }
  7777. }
  7778. else {
  7779. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7780. if (spawn->IsPlayer())
  7781. ((Player*)spawn)->SetCharSheetChanged(true);
  7782. }
  7783. return 0;
  7784. }
  7785. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7786. if (!lua_interface)
  7787. return 0;
  7788. Item* item = lua_interface->GetItem(state);
  7789. int8 type = lua_interface->GetInt32Value(state, 2);
  7790. if (!item) {
  7791. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. if (type == 1)
  7795. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7796. else if (type == 2)
  7797. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7798. return 1;
  7799. }
  7800. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7801. if (!lua_interface)
  7802. return 0;
  7803. Spawn* target = lua_interface->GetSpawn(state);
  7804. float val = lua_interface->GetFloatValue(state, 2);
  7805. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7806. // Added from Gangrenous post
  7807. if (spell && spell->resisted)
  7808. return 0;
  7809. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7810. if (val > 1.0f)
  7811. val = 1.0f - (val / 100.0f);
  7812. if (spell && spell->spell && spell->targets.size() > 0) {
  7813. ZoneServer* zone = spell->caster->GetZone();
  7814. for (int32 i = 0; i != spell->targets.size(); i++) {
  7815. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7816. if (spawn && spawn->IsEntity()) {
  7817. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7818. if (spawn->IsPlayer())
  7819. ((Player*)spawn)->SetCharSheetChanged(true);
  7820. }
  7821. }
  7822. }
  7823. else {
  7824. if (target && target->IsEntity()) {
  7825. ((Entity*)target)->SetSpeedMultiplier(val);
  7826. if (target->IsPlayer())
  7827. ((Player*)target)->SetCharSheetChanged(true);
  7828. }
  7829. }
  7830. return 0;
  7831. }
  7832. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7833. if (!lua_interface)
  7834. return 0;
  7835. Spawn* spawn = lua_interface->GetSpawn(state);
  7836. int16 model = lua_interface->GetInt16Value(state, 2);
  7837. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7838. if (spell && spell->spell && spell->targets.size() > 0) {
  7839. ZoneServer* zone = spell->caster->GetZone();
  7840. for (int32 i = 0; i < spell->targets.size(); i++) {
  7841. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7842. if (target)
  7843. target->SetIllusionModel(model);
  7844. }
  7845. }
  7846. else {
  7847. if (!spawn) {
  7848. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7849. return 0;
  7850. }
  7851. spawn->SetIllusionModel(model);
  7852. }
  7853. return 0;
  7854. }
  7855. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7856. if (!lua_interface)
  7857. return 0;
  7858. Spawn* spawn = lua_interface->GetSpawn(state);
  7859. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7860. if (spell && spell->spell && spell->targets.size() > 0) {
  7861. ZoneServer* zone = spell->caster->GetZone();
  7862. for (int32 i = 0; i < spell->targets.size(); i++) {
  7863. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7864. if (target)
  7865. target->SetIllusionModel(0);
  7866. }
  7867. }
  7868. else {
  7869. if (!spawn) {
  7870. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7871. return 0;
  7872. }
  7873. spawn->SetIllusionModel(0);
  7874. }
  7875. return 0;
  7876. }
  7877. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7878. if (!lua_interface)
  7879. return 0;
  7880. Spawn* caster = lua_interface->GetSpawn(state);
  7881. Spawn* target = lua_interface->GetSpawn(state, 2);
  7882. float chance = lua_interface->GetFloatValue(state, 3);
  7883. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7884. if (!caster) {
  7885. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7886. return 0;
  7887. }
  7888. if (!caster->IsEntity()) {
  7889. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7890. return 0;
  7891. }
  7892. if (!target) {
  7893. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7894. return 0;
  7895. }
  7896. if (!target->IsEntity()) {
  7897. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7898. return 0;
  7899. }
  7900. if (chance <= 0) {
  7901. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7902. return 0;
  7903. }
  7904. if (!spell) {
  7905. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. if(spell->resisted) {
  7909. return 0;
  7910. }
  7911. if (((Entity*)caster)->GetThreatTransfer()) {
  7912. return 0;
  7913. }
  7914. ThreatTransfer* transfer = new ThreatTransfer;
  7915. transfer->Target = target->GetID();
  7916. transfer->Amount = chance;
  7917. transfer->Spell = spell;
  7918. ((Entity*)caster)->SetThreatTransfer(transfer);
  7919. return 0;
  7920. }
  7921. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7922. if (!lua_interface)
  7923. return 0;
  7924. Spawn* spawn = lua_interface->GetSpawn(state);
  7925. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7926. if (!spawn) {
  7927. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7928. return 0;
  7929. }
  7930. if (!spell) {
  7931. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7935. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7936. ((Entity*)spawn)->SetThreatTransfer(0);
  7937. safe_delete(transfer);
  7938. }
  7939. return 0;
  7940. }
  7941. int EQ2Emu_lua_CureByType(lua_State* state) {
  7942. if (!lua_interface)
  7943. return 0;
  7944. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7945. if (!spell) {
  7946. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7947. return 0;
  7948. }
  7949. int8 cure_count = lua_interface->GetInt8Value(state);
  7950. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7951. string cure_name = lua_interface->GetStringValue(state, 3);
  7952. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7953. Spawn* target = lua_interface->GetSpawn(state, 5);
  7954. if(!spell || spell->resisted) {
  7955. return 0;
  7956. }
  7957. if (target) {
  7958. if (!target->IsEntity()) {
  7959. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7960. return 0;
  7961. }
  7962. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7963. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7964. }
  7965. else {
  7966. ZoneServer* zone = spell->caster->GetZone();
  7967. vector<int32> targets = spell->targets;
  7968. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7969. for (int8 i = 0; i < targets.size(); i++) {
  7970. target = zone->GetSpawnByID(targets.at(i));
  7971. if (!target || !target->IsEntity())
  7972. continue;
  7973. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7974. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7975. }
  7976. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7977. }
  7978. return 0;
  7979. }
  7980. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7981. if (!lua_interface)
  7982. return 0;
  7983. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7984. if (!spell) {
  7985. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. if(spell->resisted) {
  7989. return 0;
  7990. }
  7991. int8 cure_count = lua_interface->GetInt8Value(state);
  7992. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7993. string cure_name = lua_interface->GetStringValue(state, 3);
  7994. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7995. Spawn* target = lua_interface->GetSpawn(state, 5);
  7996. if (target) {
  7997. if (!target->IsEntity()) {
  7998. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7999. return 0;
  8000. }
  8001. if (((Entity*)target)->GetDetCount() > 0)
  8002. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8003. }
  8004. else {
  8005. ZoneServer* zone = spell->caster->GetZone();
  8006. vector<int32> targets = spell->targets;
  8007. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8008. for (int8 i = 0; i < targets.size(); i++) {
  8009. target = zone->GetSpawnByID(targets.at(i));
  8010. if (!target || !target->IsEntity())
  8011. continue;
  8012. if (((Entity*)target)->GetDetCount() > 0)
  8013. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8014. }
  8015. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8016. }
  8017. return 0;
  8018. }
  8019. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8020. if (!lua_interface)
  8021. return 0;
  8022. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8023. if (!spell) {
  8024. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (!spell->caster) {
  8028. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. if (!spell->caster->GetZone()) {
  8032. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8033. return 0;
  8034. }
  8035. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8036. return 0;
  8037. }
  8038. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8039. if (!lua_interface)
  8040. return 0;
  8041. Spawn* spawn = lua_interface->GetSpawn(state);
  8042. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8043. if (!spell) {
  8044. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8045. return 0;
  8046. }
  8047. if (spawn && spawn->IsEntity())
  8048. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8049. else {
  8050. ZoneServer* zone = spell->caster->GetZone();
  8051. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8052. for (int32 i = 0; i < spell->targets.size(); i++) {
  8053. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8054. if (!spawn || !spawn->IsEntity())
  8055. continue;
  8056. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8057. }
  8058. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8059. }
  8060. return 0;
  8061. }
  8062. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8063. if (!lua_interface)
  8064. return 0;
  8065. Spawn* spawn = lua_interface->GetSpawn(state);
  8066. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8067. if (!spell) {
  8068. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8069. return 0;
  8070. }
  8071. if (spawn && spawn->IsEntity())
  8072. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8073. else {
  8074. ZoneServer* zone = spell->caster->GetZone();
  8075. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8076. for (int32 i = 0; i < spell->targets.size(); i++) {
  8077. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8078. if (!spawn || !spawn->IsEntity())
  8079. continue;
  8080. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8081. }
  8082. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8083. }
  8084. return 0;
  8085. }
  8086. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8087. if (!lua_interface)
  8088. return 0;
  8089. Spawn* caster = lua_interface->GetSpawn(state);
  8090. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8091. if (!caster) {
  8092. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8093. return 0;
  8094. }
  8095. if (!caster->IsPlayer()) {
  8096. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. Spawn* target = caster->GetTarget();
  8100. if (!target) {
  8101. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8105. if (!client) {
  8106. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8107. return 0;
  8108. }
  8109. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8110. if (ho) {
  8111. ho->SetTarget(target->GetID());
  8112. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8113. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8114. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8115. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8116. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8117. deque<GroupMemberInfo*>::iterator itr;
  8118. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8119. if (group)
  8120. {
  8121. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8122. deque<GroupMemberInfo*>* members = group->GetMembers();
  8123. for (itr = members->begin(); itr != members->end(); itr++) {
  8124. if ((*itr)->client)
  8125. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8126. }
  8127. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8128. }
  8129. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8130. }
  8131. else
  8132. safe_delete(ho);
  8133. }
  8134. else {
  8135. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8136. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8137. }
  8138. else
  8139. safe_delete(ho);
  8140. }
  8141. }
  8142. return 0;
  8143. }
  8144. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8145. if (!lua_interface)
  8146. return 0;
  8147. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8148. if (!spell) {
  8149. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8150. return 0;
  8151. }
  8152. int16 triggerCount = lua_interface->GetInt16Value(state);
  8153. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8154. if (!triggerCount) {
  8155. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. spell->num_triggers = triggerCount;
  8159. spell->had_triggers = true;
  8160. spell->cancel_after_all_triggers = cancel_after_triggers;
  8161. return 0;
  8162. }
  8163. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8164. if (!lua_interface)
  8165. return 0;
  8166. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8167. if (!spell) {
  8168. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8169. return 0;
  8170. }
  8171. lua_interface->SetInt32Value(state, spell->num_triggers);
  8172. return 1;
  8173. }
  8174. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8175. if (!lua_interface)
  8176. return 0;
  8177. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8178. if (!spell) {
  8179. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. int16 remove_count = lua_interface->GetInt16Value(state);
  8183. if (!remove_count)
  8184. remove_count = 1;
  8185. if (remove_count >= spell->num_triggers) {
  8186. spell->num_triggers = 0;
  8187. if (spell->cancel_after_all_triggers)
  8188. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8189. }
  8190. else {
  8191. spell->num_triggers -= remove_count;
  8192. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8193. }
  8194. return 0;
  8195. }
  8196. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8197. if (!lua_interface)
  8198. return 0;
  8199. Spawn* spawn = lua_interface->GetSpawn(state);
  8200. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8201. if (!spawn) {
  8202. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8203. return 0;
  8204. }
  8205. if (!copy_spawn) {
  8206. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8207. return 0;
  8208. }
  8209. spawn->CopySpawnAppearance(copy_spawn);
  8210. return 0;
  8211. }
  8212. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8213. Spawn* spawn = lua_interface->GetSpawn(state);
  8214. int8 type = lua_interface->GetInt8Value(state, 2);
  8215. if (!spawn) {
  8216. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8217. return 0;
  8218. }
  8219. else if (!spawn->IsEntity()) {
  8220. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8221. return 0;
  8222. }
  8223. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8224. return 1;
  8225. }
  8226. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8227. if (!lua_interface)
  8228. return 0;
  8229. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8230. int8 type = lua_interface->GetInt8Value(state);
  8231. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8232. if (!spell) {
  8233. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8234. return 0;
  8235. }
  8236. if(spell->resisted) {
  8237. return 0;
  8238. }
  8239. if (spawn) {
  8240. if (!spawn->IsEntity()) {
  8241. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8242. return 0;
  8243. }
  8244. Entity* entity = ((Entity*)spawn);
  8245. entity->AddImmunity(spell, type);
  8246. }
  8247. else {
  8248. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8249. for (int8 i = 0; i < spell->targets.size(); i++) {
  8250. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8251. if (!spawn || !spawn->IsEntity())
  8252. continue;
  8253. Entity* entity = ((Entity*)spawn);
  8254. entity->AddImmunity(spell, type);
  8255. }
  8256. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8257. }
  8258. return 0;
  8259. }
  8260. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8261. if (!lua_interface)
  8262. return 0;
  8263. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8264. int8 type = lua_interface->GetInt8Value(state);
  8265. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8266. if (!spell) {
  8267. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8268. return 0;
  8269. }
  8270. if (spawn) {
  8271. if (!spawn->IsEntity()) {
  8272. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8273. return 0;
  8274. }
  8275. Entity* entity = ((Entity*)spawn);
  8276. entity->RemoveImmunity(spell, type);
  8277. }
  8278. else {
  8279. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8280. for (int8 i = 0; i < spell->targets.size(); i++) {
  8281. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8282. if (!spawn || !spawn->IsEntity())
  8283. continue;
  8284. Entity* entity = ((Entity*)spawn);
  8285. entity->RemoveImmunity(spell, type);
  8286. }
  8287. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8288. }
  8289. return 0;
  8290. }
  8291. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8292. if (!lua_interface)
  8293. return 0;
  8294. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8295. if (!spell) {
  8296. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8297. return 0;
  8298. }
  8299. if(spell->resisted) {
  8300. return 0;
  8301. }
  8302. float snare = lua_interface->GetFloatValue(state);
  8303. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8304. // convert the val to the speed multipler value (100 - val)
  8305. float val = 100.0 - snare;
  8306. val /= 100.0;
  8307. if (spawn) {
  8308. if (!spawn->IsEntity()) {
  8309. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. ((Entity*)spawn)->SetSnareValue(spell, val);
  8313. }
  8314. else {
  8315. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8316. for (int8 i = 0; i < spell->targets.size(); i++) {
  8317. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8318. if (!spawn || !spawn->IsEntity())
  8319. continue;
  8320. ((Entity*)spawn)->SetSnareValue(spell, val);
  8321. }
  8322. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8323. }
  8324. return 0;
  8325. }
  8326. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8327. if (!lua_interface)
  8328. return 0;
  8329. Spawn* spawn = lua_interface->GetSpawn(state);
  8330. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8331. if (!spawn) {
  8332. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8333. return 0;
  8334. }
  8335. if (race_id == 0) {
  8336. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8337. return 0;
  8338. }
  8339. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8340. return 1;
  8341. }
  8342. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8343. if (!lua_interface)
  8344. return 0;
  8345. Spawn* spawn = lua_interface->GetSpawn(state);
  8346. if (!spawn) {
  8347. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8348. return 0;
  8349. }
  8350. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8351. return 1;
  8352. }
  8353. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8354. if (!lua_interface)
  8355. return 0;
  8356. Spawn* spawn = lua_interface->GetSpawn(state);
  8357. if (!spawn) {
  8358. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8359. return 0;
  8360. }
  8361. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8362. return 1;
  8363. }
  8364. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8365. if (!lua_interface)
  8366. return 0;
  8367. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8368. if (!spell) {
  8369. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. lua_interface->SetStringValue(state, spell->spell->GetName());
  8373. return 1;
  8374. }
  8375. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8376. if (!lua_interface)
  8377. return 0;
  8378. Quest* quest = lua_interface->GetQuest(state);
  8379. if (!quest) {
  8380. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8384. return 1;
  8385. }
  8386. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8387. if (!lua_interface)
  8388. return 0;
  8389. Quest* quest = lua_interface->GetQuest(state);
  8390. int32 flags = lua_interface->GetInt32Value(state, 2);
  8391. if (!quest) {
  8392. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. quest->SetQuestFlags(flags);
  8396. return 0;
  8397. }
  8398. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8399. if (!lua_interface)
  8400. return 0;
  8401. Quest* quest = lua_interface->GetQuest(state);
  8402. Spawn* player = lua_interface->GetSpawn(state, 2);
  8403. int32 step = lua_interface->GetInt32Value(state, 3);
  8404. int32 duration = lua_interface->GetInt32Value(state, 4);
  8405. string action = lua_interface->GetStringValue(state, 5);
  8406. if (!quest) {
  8407. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. if (!player) {
  8411. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8412. return 0;
  8413. }
  8414. if (!player->IsPlayer()) {
  8415. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8416. return 0;
  8417. }
  8418. if (step == 0) {
  8419. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8420. return 0;
  8421. }
  8422. if (duration == 0) {
  8423. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. if (action.length() == 0) {
  8427. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8428. return 0;
  8429. }
  8430. Client* client = player->GetZone()->GetClientBySpawn(player);
  8431. if (!client) {
  8432. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8433. return 0;
  8434. }
  8435. quest->SetTimerStep(step);
  8436. quest->AddFailedAction(step, action);
  8437. quest->SetStepTimer(duration);
  8438. client->AddQuestTimer(quest->GetQuestID());
  8439. return 0;
  8440. }
  8441. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8442. if (!lua_interface)
  8443. return 0;
  8444. Quest* quest = lua_interface->GetQuest(state);
  8445. Spawn* player = lua_interface->GetSpawn(state, 2);
  8446. if (!quest) {
  8447. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8448. return 0;
  8449. }
  8450. if (!player) {
  8451. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!player->IsPlayer()) {
  8455. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. Client* client = player->GetZone()->GetClientBySpawn(player);
  8459. if (!client) {
  8460. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8461. return 0;
  8462. }
  8463. quest->SetTimerStep(0);
  8464. quest->SetStepTimer(0);
  8465. client->RemoveQuestTimer(quest->GetQuestID());
  8466. return 0;
  8467. }
  8468. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8469. if (!lua_interface)
  8470. return 0;
  8471. Spawn* player = lua_interface->GetSpawn(state);
  8472. Quest* quest = lua_interface->GetQuest(state, 2);
  8473. int32 step = lua_interface->GetInt32Value(state, 3);
  8474. if (!player) {
  8475. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. if (!player->IsPlayer()) {
  8479. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8480. return 0;
  8481. }
  8482. if (!quest) {
  8483. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8484. return 0;
  8485. }
  8486. if (step == 0) {
  8487. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8488. return 0;
  8489. }
  8490. Client* client = player->GetZone()->GetClientBySpawn(player);
  8491. if (!client) {
  8492. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8493. return 0;
  8494. }
  8495. if (quest->RemoveQuestStep(step, client)) {
  8496. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8497. client->GetCurrentZone()->SendQuestUpdates(client);
  8498. }
  8499. else
  8500. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8501. return 0;
  8502. }
  8503. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8504. if (!lua_interface)
  8505. return 0;
  8506. Quest* quest = lua_interface->GetQuest(state, 1);
  8507. int32 step = lua_interface->GetInt32Value(state, 2);
  8508. string desc = lua_interface->GetStringValue(state, 3);
  8509. string task_group = lua_interface->GetStringValue(state, 4);
  8510. if (!quest) {
  8511. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8512. return 0;
  8513. }
  8514. if (step == 0) {
  8515. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8516. return 0;
  8517. }
  8518. QuestStep* quest_step = quest->GetQuestStep(step);
  8519. if (!quest_step) {
  8520. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8521. return 0;
  8522. }
  8523. quest_step->SetStepProgress(0);
  8524. quest_step->SetTaskGroup(task_group);
  8525. quest_step->SetDescription(desc);
  8526. return 0;
  8527. }
  8528. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8529. if (!lua_interface)
  8530. return 0;
  8531. Quest* quest = lua_interface->GetQuest(state);
  8532. int32 step = lua_interface->GetInt32Value(state, 2);
  8533. string action = lua_interface->GetStringValue(state, 3);
  8534. if (!quest) {
  8535. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. if (step == 0) {
  8539. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8540. return 0;
  8541. }
  8542. if (action.length() == 0) {
  8543. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8544. return 0;
  8545. }
  8546. quest->AddFailedAction(step, action);
  8547. return 0;
  8548. }
  8549. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8550. if (!lua_interface)
  8551. return 0;
  8552. Spawn* player = lua_interface->GetSpawn(state);
  8553. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8554. int32 step = lua_interface->GetInt32Value(state, 3);
  8555. if (!player) {
  8556. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8557. return 0;
  8558. }
  8559. if (!player->IsPlayer()) {
  8560. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8561. return 0;
  8562. }
  8563. if (quest_id == 0) {
  8564. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8565. return 0;
  8566. }
  8567. if (step == 0) {
  8568. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8569. return 0;
  8570. }
  8571. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8572. if (!quest) {
  8573. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8574. return 0;
  8575. }
  8576. quest->StepFailed(step);
  8577. return 0;
  8578. }
  8579. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8580. if (!lua_interface)
  8581. return 0;
  8582. Spawn* player = lua_interface->GetSpawn(state);
  8583. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8584. if (!player) {
  8585. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8586. return 0;
  8587. }
  8588. if (!player->IsPlayer()) {
  8589. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8590. return 0;
  8591. }
  8592. if (quest_id == 0) {
  8593. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8594. return 0;
  8595. }
  8596. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8597. if (!quest) {
  8598. lua_interface->SetInt32Value(state, 0);
  8599. return 1;
  8600. }
  8601. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8602. return 1;
  8603. }
  8604. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8605. if (!lua_interface)
  8606. return 0;
  8607. string name = lua_interface->GetStringValue(state);
  8608. string value = lua_interface->GetStringValue(state, 2);
  8609. string comment = lua_interface->GetStringValue(state, 3);
  8610. if (name.length() == 0) {
  8611. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8612. return 0;
  8613. }
  8614. if (value.length() == 0) {
  8615. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8616. return 0;
  8617. }
  8618. string varname = string("lua_").append(name);
  8619. Variable* var = variables.FindVariable(varname);
  8620. if (var)
  8621. var->SetValue(value.c_str());
  8622. else {
  8623. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8624. variables.AddVariable(var);
  8625. }
  8626. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8627. return 0;
  8628. }
  8629. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8630. if (!lua_interface)
  8631. return 0;
  8632. string name = lua_interface->GetStringValue(state);
  8633. if (name.length() == 0) {
  8634. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8635. return 0;
  8636. }
  8637. string varname = string("lua_").append(name);
  8638. Variable* var = variables.FindVariable(varname);
  8639. if (var)
  8640. lua_interface->SetStringValue(state, var->GetValue());
  8641. else
  8642. lua_interface->SetStringValue(state, "NULL");
  8643. return 1;
  8644. }
  8645. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8646. if (!lua_interface)
  8647. return 0;
  8648. Spawn* player = lua_interface->GetSpawn(state);
  8649. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8650. if (!player) {
  8651. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. if (!player->IsPlayer()) {
  8655. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8659. return 1;
  8660. }
  8661. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8662. if (!lua_interface)
  8663. return 0;
  8664. Spawn* player = lua_interface->GetSpawn(state);
  8665. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8666. if (!player) {
  8667. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8668. return 0;
  8669. }
  8670. if (!player->IsPlayer()) {
  8671. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8672. return 0;
  8673. }
  8674. Language* language = master_languages_list.GetLanguage(language_id);
  8675. if (language)
  8676. {
  8677. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8678. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8679. }
  8680. return 0;
  8681. }
  8682. int EQ2Emu_lua_IsNight(lua_State* state) {
  8683. if (!lua_interface)
  8684. return 0;
  8685. ZoneServer* zone = lua_interface->GetZone(state);
  8686. if (!zone) {
  8687. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8688. return 0;
  8689. }
  8690. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8691. return 1;
  8692. }
  8693. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8694. if (!lua_interface)
  8695. return 0;
  8696. Spawn* spawn = lua_interface->GetSpawn(state);
  8697. if (!spawn) {
  8698. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8699. return 0;
  8700. }
  8701. if (!spawn->IsWidget()) {
  8702. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8703. return 0;
  8704. }
  8705. ((Widget*)spawn)->SetMultiFloorLift(true);
  8706. if (spawn->GetZone())
  8707. spawn->GetZone()->AddTransportSpawn(spawn);
  8708. return 0;
  8709. }
  8710. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8711. if (!lua_interface)
  8712. return 0;
  8713. Spawn* player = lua_interface->GetSpawn(state);
  8714. int32 path = lua_interface->GetInt32Value(state, 2);
  8715. if (!player) {
  8716. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8717. return 0;
  8718. }
  8719. if (!player->IsPlayer()) {
  8720. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8721. return 0;
  8722. }
  8723. if (path == 0) {
  8724. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. Client* client = player->GetZone()->GetClientBySpawn(player);
  8728. if (!client) {
  8729. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. client->SendFlightAutoMount(path);
  8733. return 0;
  8734. }
  8735. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8736. if (!lua_interface)
  8737. return 0;
  8738. Spawn* player = lua_interface->GetSpawn(state);
  8739. if (!player) {
  8740. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8741. return 0;
  8742. }
  8743. if (!player->IsPlayer()) {
  8744. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8745. return 0;
  8746. }
  8747. Client* client = player->GetZone()->GetClientBySpawn(player);
  8748. if (!client) {
  8749. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8750. return 0;
  8751. }
  8752. client->EndAutoMount();
  8753. return 0;
  8754. }
  8755. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8756. if (!lua_interface)
  8757. return 0;
  8758. Spawn* player = lua_interface->GetSpawn(state);
  8759. if (!player) {
  8760. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8761. return 0;
  8762. }
  8763. if (!player->IsPlayer()) {
  8764. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8765. return 0;
  8766. }
  8767. Client* client = player->GetZone()->GetClientBySpawn(player);
  8768. if (!client) {
  8769. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8770. return 0;
  8771. }
  8772. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8773. return 1;
  8774. }
  8775. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8776. if (!lua_interface)
  8777. return 0;
  8778. Spawn* player = lua_interface->GetSpawn(state);
  8779. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8780. int32 value = lua_interface->GetInt32Value(state, 3);
  8781. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8782. if (!player) {
  8783. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8784. return 0;
  8785. }
  8786. if (!player->IsPlayer()) {
  8787. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8788. return 0;
  8789. }
  8790. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8791. return 0;
  8792. }
  8793. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8794. if (!lua_interface)
  8795. return 0;
  8796. Spawn* player = lua_interface->GetSpawn(state);
  8797. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8798. if (!player) {
  8799. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8800. return 0;
  8801. }
  8802. if (!player->IsPlayer()) {
  8803. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8804. return 0;
  8805. }
  8806. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8807. if (!hd)
  8808. return 0;
  8809. lua_interface->SetInt32Value(state, hd->Value);
  8810. lua_interface->SetInt32Value(state, hd->Value2);
  8811. return 2;
  8812. }
  8813. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8814. if (!lua_interface)
  8815. return 0;
  8816. Spawn* spawn = lua_interface->GetSpawn(state);
  8817. int32 grid = lua_interface->GetInt32Value(state, 2);
  8818. if (!spawn) {
  8819. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8820. return 0;
  8821. }
  8822. if (grid == 0) {
  8823. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8827. return 0;
  8828. }
  8829. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8830. if (!lua_interface)
  8831. return 0;
  8832. Spawn* spawn = lua_interface->GetSpawn(state);
  8833. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8834. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8835. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8836. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8837. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8838. if (!spawn) {
  8839. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8840. return 0;
  8841. }
  8842. //Add this quest to the list of required quests for this spawn
  8843. spawn->SetRequiredHistory(event_id, value1, value2);
  8844. //If private spawn value set
  8845. if (private_spawn) {
  8846. //Set the spawn to be private when not granted access via history
  8847. spawn->AddAllowAccessSpawn(spawn);
  8848. spawn->SetPrivateQuestSpawn(true);
  8849. }
  8850. //This value will override vis_flags in the vis packet
  8851. if (flag_override > 0)
  8852. spawn->SetQuestsRequiredOverride(flag_override);
  8853. return 0;
  8854. }
  8855. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8856. if (!lua_interface)
  8857. return 0;
  8858. Spawn* player = lua_interface->GetSpawn(state);
  8859. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8860. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8861. if (!player) {
  8862. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. if (!player->IsPlayer()) {
  8866. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8867. return 0;
  8868. }
  8869. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8870. return 1;
  8871. }
  8872. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8873. if (!lua_interface)
  8874. return 0;
  8875. Spawn* player = lua_interface->GetSpawn(state);
  8876. int8 level = lua_interface->GetInt8Value(state, 2);
  8877. if (!player) {
  8878. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8879. return 0;
  8880. }
  8881. if (!player->IsPlayer()) {
  8882. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8883. return 0;
  8884. }
  8885. if (level == 0) {
  8886. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8887. return 0;
  8888. }
  8889. Client* client = player->GetZone()->GetClientBySpawn(player);
  8890. if (!client) {
  8891. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8892. return 0;
  8893. }
  8894. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8895. return 0;
  8896. }
  8897. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8898. if (!lua_interface)
  8899. return 0;
  8900. Spawn* player = lua_interface->GetSpawn(state);
  8901. int32 amount = lua_interface->GetInt32Value(state, 2);
  8902. if (!player) {
  8903. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8904. return 0;
  8905. }
  8906. if (!player->IsPlayer()) {
  8907. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. if (amount == 0) {
  8911. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8912. return 0;
  8913. }
  8914. ((Player*)player)->AddCoins(amount);
  8915. return 0;
  8916. }
  8917. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8918. if (!lua_interface)
  8919. return 0;
  8920. Spawn* player = lua_interface->GetSpawn(state);
  8921. int32 amount = lua_interface->GetInt32Value(state, 2);
  8922. if (!player) {
  8923. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8924. return 0;
  8925. }
  8926. if (!player->IsPlayer()) {
  8927. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8928. return 0;
  8929. }
  8930. if (amount == 0) {
  8931. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8935. return 1;
  8936. }
  8937. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8938. if (!lua_interface)
  8939. return 0;
  8940. ZoneServer* zone = lua_interface->GetZone(state);
  8941. if (!zone) {
  8942. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8943. return 0;
  8944. }
  8945. vector<Entity*> players = zone->GetPlayers();
  8946. if (players.size() == 0)
  8947. return 0;
  8948. lua_createtable(state, players.size(), 0);
  8949. int newTable = lua_gettop(state);
  8950. for (int32 i = 0; i < players.size(); i++) {
  8951. lua_interface->SetSpawnValue(state, players.at(i));
  8952. lua_rawseti(state, newTable, i + 1);
  8953. }
  8954. return 1;
  8955. }
  8956. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8957. if (!lua_interface)
  8958. return 0;
  8959. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8960. if (!zone) {
  8961. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8965. //Map of <placement_id, location_id>
  8966. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8967. map<int32, int32>::iterator itr;
  8968. vector<Spawn*> group;
  8969. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8970. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8971. if (!location) {
  8972. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8973. return 0;
  8974. }
  8975. Spawn* spawn = 0;
  8976. if (location->entities[0]) {
  8977. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8978. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8979. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8980. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8981. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8982. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8983. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8984. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8985. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8986. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8987. if(spawn && spawn->IsOmittedByDBFlag())
  8988. {
  8989. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  8990. safe_delete(spawn);
  8991. continue;
  8992. }
  8993. if (spawn) {
  8994. const char* script = 0;
  8995. for (int x = 0; x < 3; x++) {
  8996. switch (x) {
  8997. case 0:
  8998. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8999. break;
  9000. case 1:
  9001. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9002. break;
  9003. case 2:
  9004. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9005. break;
  9006. }
  9007. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9008. spawn->SetSpawnScript(string(script));
  9009. break;
  9010. }
  9011. }
  9012. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9013. lua_interface->SetSpawnValue(state, spawn);
  9014. group.push_back(spawn);
  9015. }
  9016. else {
  9017. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9018. safe_delete(spawn);
  9019. }
  9020. }
  9021. }
  9022. if (!group.empty()) {
  9023. lua_createtable(state, group.size(), 0);
  9024. int newTable = lua_gettop(state);
  9025. for (int32 i = 0; i < group.size(); i++) {
  9026. lua_interface->SetSpawnValue(state, group[i]);
  9027. lua_rawseti(state, newTable, i + 1);
  9028. }
  9029. }
  9030. else
  9031. lua_pushnil(state);
  9032. return 1;
  9033. }
  9034. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9035. if (!lua_interface)
  9036. return 0;
  9037. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9038. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9039. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9040. if (!spawn) {
  9041. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9042. return 0;
  9043. }
  9044. if (anim_id == 0) {
  9045. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9046. return 0;
  9047. }
  9048. if (leeway == 0)
  9049. leeway = 5000;
  9050. spawn->SetSpawnAnim(anim_id);
  9051. spawn->SetSpawnAnimLeeway(leeway);
  9052. return 0;
  9053. }
  9054. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9055. if (!lua_interface)
  9056. return 0;
  9057. Spawn* player = lua_interface->GetSpawn(state);
  9058. if (!player) {
  9059. return 0;
  9060. }
  9061. Client* client = player->GetZone()->GetClientBySpawn(player);
  9062. if (!client) {
  9063. return 0;
  9064. }
  9065. lua_interface->SetInt32Value(state, client->GetVersion());
  9066. return 1;
  9067. }
  9068. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9069. if (!lua_interface)
  9070. return 0;
  9071. Item* item = lua_interface->GetItem(state);
  9072. if (!item) {
  9073. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9074. return 0;
  9075. }
  9076. lua_interface->SetInt32Value(state, item->details.item_id);
  9077. return 1;
  9078. }
  9079. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9080. if (!lua_interface)
  9081. return 0;
  9082. Spawn* spawn = lua_interface->GetSpawn(state);
  9083. if (!spawn) {
  9084. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9085. return 0;
  9086. }
  9087. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9088. return 1;
  9089. }
  9090. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9091. if (!lua_interface)
  9092. return 0;
  9093. Spawn* spawn = lua_interface->GetSpawn(state);
  9094. if (!spawn) {
  9095. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9096. return 0;
  9097. }
  9098. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9099. return 1;
  9100. }
  9101. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9102. if (!lua_interface)
  9103. return 0;
  9104. Spawn* spawn = lua_interface->GetSpawn(state);
  9105. if (!spawn) {
  9106. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9107. return 0;
  9108. }
  9109. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9110. return 1;
  9111. }
  9112. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9113. if (!lua_interface)
  9114. return 0;
  9115. Spawn* spawn = lua_interface->GetSpawn(state);
  9116. if (!spawn) {
  9117. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9118. return 0;
  9119. }
  9120. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9121. return 1;
  9122. }
  9123. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9124. if (!lua_interface)
  9125. return 0;
  9126. Spawn* spawn = lua_interface->GetSpawn(state);
  9127. float pct = lua_interface->GetFloatValue(state, 2);
  9128. if (!spawn) {
  9129. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9130. return 0;
  9131. }
  9132. if (pct == 0) {
  9133. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9134. return 0;
  9135. }
  9136. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9137. lua_interface->SetInt32Value(state, amount);
  9138. return 1;
  9139. }
  9140. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9141. if (!lua_interface)
  9142. return 0;
  9143. Spawn* spawn = lua_interface->GetSpawn(state);
  9144. float pct = lua_interface->GetFloatValue(state, 2);
  9145. if (!spawn) {
  9146. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9147. return 0;
  9148. }
  9149. if (pct == 0) {
  9150. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9151. return 0;
  9152. }
  9153. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9154. lua_interface->SetInt32Value(state, amount);
  9155. return 1;
  9156. }
  9157. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9158. if (!lua_interface)
  9159. return 0;
  9160. Spawn* spawn = lua_interface->GetSpawn(state);
  9161. if (!spawn) {
  9162. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9163. return 0;
  9164. }
  9165. if (!spawn->IsPlayer()) {
  9166. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9167. return 0;
  9168. }
  9169. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9170. return 1;
  9171. }
  9172. int EQ2Emu_lua_Evac(lua_State* state) {
  9173. if (!lua_interface)
  9174. return 0;
  9175. Spawn* target = lua_interface->GetSpawn(state);
  9176. if (target) {
  9177. float x = target->GetZone()->GetSafeX();
  9178. float y = target->GetZone()->GetSafeY();
  9179. float z = target->GetZone()->GetSafeZ();
  9180. float h = target->GetZone()->GetSafeHeading();
  9181. target->SetX(x);
  9182. target->SetY(y);
  9183. target->SetZ(z);
  9184. target->SetHeading(h);
  9185. target->SetSpawnOrigX(x);
  9186. target->SetSpawnOrigY(y);
  9187. target->SetSpawnOrigZ(z);
  9188. target->SetSpawnOrigHeading(h);
  9189. if (target->IsPlayer()) {
  9190. Client* client = target->GetZone()->GetClientBySpawn(target);
  9191. if (client) {
  9192. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9193. int numargs = lua_interface->GetNumberOfArgs(state);
  9194. if(numargs == 4) {
  9195. x = lua_interface->GetFloatValue(state,1);
  9196. y = lua_interface->GetFloatValue(state,2);
  9197. z = lua_interface->GetFloatValue(state,3);
  9198. h = lua_interface->GetFloatValue(state,4);
  9199. }
  9200. client->SetReloadingZone(true);
  9201. target->SetX(x);
  9202. target->SetY(y);
  9203. target->SetZ(z);
  9204. target->SetHeading(h);
  9205. target->SetSpawnOrigX(x);
  9206. target->SetSpawnOrigY(y);
  9207. target->SetSpawnOrigZ(z);
  9208. target->SetSpawnOrigHeading(h);
  9209. target->SetAppearancePosition(x,y,z);
  9210. client->SetZoningCoords(x,y,z,h);
  9211. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9212. if (packet)
  9213. {
  9214. packet->setDataByName("x", x);
  9215. packet->setDataByName("y", y);
  9216. packet->setDataByName("z", z);
  9217. client->QueuePacket(packet->serialize());
  9218. safe_delete(packet);
  9219. }
  9220. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9221. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9222. }
  9223. }
  9224. }
  9225. else {
  9226. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9227. if(!spell)
  9228. return 0;
  9229. ZoneServer* zone = spell->caster->GetZone();
  9230. float x = spell->caster->GetZone()->GetSafeX();
  9231. float y = spell->caster->GetZone()->GetSafeY();
  9232. float z = spell->caster->GetZone()->GetSafeZ();
  9233. float h = spell->caster->GetZone()->GetSafeHeading();
  9234. int numargs = lua_interface->GetNumberOfArgs(state);
  9235. if(numargs == 4) {
  9236. x = lua_interface->GetFloatValue(state,1);
  9237. y = lua_interface->GetFloatValue(state,2);
  9238. z = lua_interface->GetFloatValue(state,3);
  9239. h = lua_interface->GetFloatValue(state,4);
  9240. }
  9241. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9242. for (int32 i = 0; i < spell->targets.size(); i++) {
  9243. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9244. if (!target2)
  9245. continue;
  9246. if (target2->IsPlayer()) {
  9247. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9248. if (client) {
  9249. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9250. client->SetReloadingZone(true);
  9251. target2->SetX(x);
  9252. target2->SetY(y);
  9253. target2->SetZ(z);
  9254. target2->SetHeading(h);
  9255. target2->SetSpawnOrigX(x);
  9256. target2->SetSpawnOrigY(y);
  9257. target2->SetSpawnOrigZ(z);
  9258. target2->SetSpawnOrigHeading(h);
  9259. target2->SetAppearancePosition(x,y,z);
  9260. client->SetZoningCoords(x,y,z,h);
  9261. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9262. if (packet)
  9263. {
  9264. packet->setDataByName("x", x);
  9265. packet->setDataByName("y", y);
  9266. packet->setDataByName("z", z);
  9267. client->QueuePacket(packet->serialize());
  9268. safe_delete(packet);
  9269. }
  9270. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9271. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9272. }
  9273. }
  9274. }
  9275. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9276. }
  9277. return 0;
  9278. }
  9279. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9280. if (!lua_interface)
  9281. return 0;
  9282. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9283. if (!luaspell) {
  9284. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9285. return 0;
  9286. }
  9287. int8 tier = luaspell->spell->GetSpellTier();
  9288. lua_interface->SetInt32Value(state, tier);
  9289. return 1;
  9290. }
  9291. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9292. if (!lua_interface)
  9293. return 0;
  9294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9295. if (!luaspell) {
  9296. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9297. return 0;
  9298. }
  9299. int32 spell_id = luaspell->spell->GetSpellID();
  9300. lua_interface->SetInt32Value(state, spell_id);
  9301. return 1;
  9302. }
  9303. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9304. if (!lua_interface)
  9305. return 0;
  9306. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9307. if (!spawn) {
  9308. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9309. return 0;
  9310. }
  9311. if (!spawn->IsPlayer()) {
  9312. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9313. return 0;
  9314. }
  9315. ZoneServer* zone = spawn->GetZone();
  9316. if (!zone) {
  9317. return 0;
  9318. }
  9319. Client* client = zone->GetClientBySpawn(spawn);
  9320. if (!client) {
  9321. return 0;
  9322. }
  9323. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9324. return 0;
  9325. }
  9326. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9327. if (!lua_interface)
  9328. return 0;
  9329. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9330. if (!spawn) {
  9331. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9332. return 0;
  9333. }
  9334. if (!spawn->IsPlayer()) {
  9335. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9336. return 0;
  9337. }
  9338. ZoneServer* zone = spawn->GetZone();
  9339. if (!zone) {
  9340. return 0;
  9341. }
  9342. Client* client = zone->GetClientBySpawn(spawn);
  9343. if (!client) {
  9344. return 0;
  9345. }
  9346. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9347. return 0;
  9348. }
  9349. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9350. if (!lua_interface)
  9351. return 0;
  9352. Spawn* caster = lua_interface->GetSpawn(state);
  9353. Spawn* target = lua_interface->GetSpawn(state, 2);
  9354. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9355. string spell_name = lua_interface->GetStringValue(state, 4);
  9356. if (!caster) {
  9357. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9358. return 0;
  9359. }
  9360. if (!caster->IsEntity()) {
  9361. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9362. return 0;
  9363. }
  9364. if (!target) {
  9365. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9366. return 0;
  9367. }
  9368. if (!target->IsEntity()) {
  9369. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9370. return 0;
  9371. }
  9372. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9373. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9374. return 0;
  9375. }
  9376. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9377. if (!lua_interface)
  9378. return 0;
  9379. Spawn* player = lua_interface->GetSpawn(state);
  9380. int32 amount = lua_interface->GetInt32Value(state, 2);
  9381. if (player && player->IsPlayer() && amount > 0) {
  9382. ((Player*)player)->AddXP(amount);
  9383. ((Player*)player)->SetCharSheetChanged(true);
  9384. Client* client = player->GetZone()->GetClientBySpawn(player);
  9385. if (client) {
  9386. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9387. }
  9388. }
  9389. return 0;
  9390. }
  9391. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9392. if (!lua_interface)
  9393. return 0;
  9394. Spawn* player = lua_interface->GetSpawn(state);
  9395. int8 type = lua_interface->GetInt8Value(state, 2);
  9396. string text = lua_interface->GetStringValue(state, 3);
  9397. Client* client = 0;
  9398. if (player && player->IsPlayer())
  9399. client = player->GetZone()->GetClientBySpawn(player);
  9400. if (!client || text.length() == 0) {
  9401. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9402. return 0;
  9403. }
  9404. client->SimpleMessage(type, text.c_str());
  9405. return 0;
  9406. }
  9407. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9408. if (!lua_interface)
  9409. return 0;
  9410. Spawn* player = lua_interface->GetSpawn(state);
  9411. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9412. Client* client = 0;
  9413. if (player && player->IsPlayer())
  9414. client = player->GetZone()->GetClientBySpawn(player);
  9415. if (!client || !spawn) {
  9416. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9420. if (!items) {
  9421. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9422. return 0;
  9423. }
  9424. client->Loot(spawn->GetLootCoins(), items, spawn);
  9425. return 0;
  9426. }
  9427. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9428. if (!lua_interface)
  9429. return 0;
  9430. Spawn* spawnref = lua_interface->GetSpawn(state);
  9431. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9432. if (spawn_id > 0 && spawnref) {
  9433. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9434. if (spawns.size() == 0) {
  9435. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9436. return 0;
  9437. }
  9438. Spawn* spawn = 0;
  9439. int16 index = MakeRandomInt(0, spawns.size());
  9440. if (index >= spawns.size() || index < 0)
  9441. index = 0;
  9442. spawn = spawns[index];
  9443. lua_interface->SetSpawnValue(state, spawn);
  9444. return 1;
  9445. }
  9446. else {
  9447. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9448. }
  9449. return 0;
  9450. }
  9451. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9452. Spawn* player = lua_interface->GetSpawn(state);
  9453. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9454. string name = lua_interface->GetStringValue(state, 3);
  9455. float distance = lua_interface->GetFloatValue(state, 4);
  9456. string command = lua_interface->GetStringValue(state, 5);
  9457. string error_text = lua_interface->GetStringValue(state, 6);
  9458. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9459. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9460. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9461. if (distance == 0)
  9462. distance = 10.0f;
  9463. if (command.length() == 0)
  9464. command = name;
  9465. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9466. if (spawns.size() == 0) {
  9467. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9468. return 0;
  9469. }
  9470. Spawn* spawn = 0;
  9471. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9472. spawn = *itr;
  9473. if (spawn) {
  9474. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9475. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9476. }
  9477. }
  9478. }
  9479. return 0;
  9480. }
  9481. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9482. if (!lua_interface)
  9483. return 0;
  9484. Client* client = 0;
  9485. Spawn* player = lua_interface->GetSpawn(state);
  9486. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9487. if (player && player->IsPlayer() && player->GetZone())
  9488. client = player->GetZone()->GetClientBySpawn(player);
  9489. else{
  9490. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9491. return 0;
  9492. }
  9493. if (client) {
  9494. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9495. if (packet) {
  9496. packet->setDataByName("goal_num", goal_num);
  9497. client->QueuePacket(packet->serialize());
  9498. safe_delete(packet);
  9499. }
  9500. }
  9501. return 0;
  9502. }
  9503. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9504. if (!lua_interface)
  9505. return 0;
  9506. Client* client = 0;
  9507. Spawn* player = lua_interface->GetSpawn(state);
  9508. if (player && player->IsPlayer() && player->GetZone())
  9509. client = player->GetZone()->GetClientBySpawn(player);
  9510. else {
  9511. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9512. return 0;
  9513. }
  9514. if (client) {
  9515. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9516. }
  9517. return 0;
  9518. }
  9519. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9520. if (!lua_interface)
  9521. return 0;
  9522. Client* client = 0;
  9523. Spawn* player = lua_interface->GetSpawn(state);
  9524. float duration = lua_interface->GetFloatValue(state, 2);
  9525. string text = lua_interface->GetStringValue(state, 3);
  9526. string voice = lua_interface->GetStringValue(state, 4);
  9527. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9528. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9529. string signal = lua_interface->GetStringValue(state, 7);
  9530. string goal1 = lua_interface->GetStringValue(state, 8);
  9531. string task1 = lua_interface->GetStringValue(state, 9);
  9532. string goal2 = lua_interface->GetStringValue(state, 10);
  9533. string task2 = lua_interface->GetStringValue(state, 11);
  9534. string goal3 = lua_interface->GetStringValue(state, 12);
  9535. string task3 = lua_interface->GetStringValue(state, 13);
  9536. string goal4 = lua_interface->GetStringValue(state, 14);
  9537. string task4 = lua_interface->GetStringValue(state, 15);
  9538. if (!player) {
  9539. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9540. return 0;
  9541. }
  9542. if (!player->IsPlayer()) {
  9543. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9544. return 0;
  9545. }
  9546. else
  9547. client = ((Player*)player)->GetClient();
  9548. if (!client) {
  9549. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9550. return 0;
  9551. }
  9552. if (text.length() == 0) {
  9553. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9554. return 0;
  9555. }
  9556. if (duration >= 0 && duration < 2)
  9557. duration = 2;
  9558. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9559. if (packet) {
  9560. packet->setDataByName("open_seconds_max", duration);
  9561. packet->setDataByName("text", text.c_str());
  9562. packet->setDataByName("voice", voice.c_str());
  9563. int8 num_goals = 1;
  9564. if (task2.length() > 0)
  9565. num_goals++;
  9566. if (task3.length() > 0)
  9567. num_goals++;
  9568. if (task4.length() > 0)
  9569. num_goals++;
  9570. packet->setArrayLengthByName("num_goals", num_goals);
  9571. for (int8 i = 0; i < num_goals; i++) {
  9572. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9573. }
  9574. if (goal1.length() > 0)
  9575. packet->setArrayDataByName("goal_text", goal1.c_str());
  9576. if (goal2.length() > 0)
  9577. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9578. if (goal3.length() > 0)
  9579. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9580. if (goal4.length() > 0)
  9581. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9582. packet->setSubArrayDataByName("task_text", task1.c_str());
  9583. if (task2.length() > 0)
  9584. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9585. if (task3.length() > 0)
  9586. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9587. if (task4.length() > 0)
  9588. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9589. packet->setDataByName("complete_sound", "click");
  9590. packet->setDataByName("signal", signal.c_str());
  9591. packet->setDataByName("voice_key1", voice_key1);
  9592. packet->setDataByName("voice_key2", voice_key2);
  9593. client->QueuePacket(packet->serialize());
  9594. safe_delete(packet);
  9595. }
  9596. return 0;
  9597. }
  9598. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9599. if (!lua_interface)
  9600. return 0;
  9601. Client* client = 0;
  9602. Spawn* player = lua_interface->GetSpawn(state);
  9603. string window = lua_interface->GetStringValue(state, 2);
  9604. int8 show = lua_interface->GetInt8Value(state, 3);
  9605. if (!player) {
  9606. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9607. return 0;
  9608. }
  9609. if (!player->IsPlayer()) {
  9610. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9611. return 0;
  9612. }
  9613. else
  9614. client = ((Player*)player)->GetClient();
  9615. if (!client) {
  9616. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9617. return 0;
  9618. }
  9619. if (window.length() == 0) {
  9620. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9621. return 0;
  9622. }
  9623. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9624. if (packet) {
  9625. packet->setDataByName("window", window.c_str());
  9626. packet->setDataByName("show", show);
  9627. client->QueuePacket(packet->serialize());
  9628. safe_delete(packet);
  9629. }
  9630. return 0;
  9631. }
  9632. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9633. //See GameEvents.txt for options that can be used for this function
  9634. if (!lua_interface)
  9635. return 0;
  9636. Client* client = 0;
  9637. Spawn* player = lua_interface->GetSpawn(state);
  9638. string event_name = lua_interface->GetStringValue(state, 2);
  9639. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9640. if (!player || !player->IsPlayer()) {
  9641. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9642. return 0;
  9643. }
  9644. if (player->GetZone())
  9645. client = player->GetZone()->GetClientBySpawn(player);
  9646. if (!client) {
  9647. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9648. return 0;
  9649. }
  9650. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9651. if (packet) {
  9652. packet->setDataByName("event_name", event_name.c_str());
  9653. packet->setDataByName("enabled", enabled);
  9654. client->QueuePacket(packet->serialize());
  9655. safe_delete(packet);
  9656. }
  9657. return 0;
  9658. }
  9659. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9660. if (!lua_interface)
  9661. return 0;
  9662. Spawn* player = lua_interface->GetSpawn(state);
  9663. if (player && player->IsPlayer()) {
  9664. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9665. return 1;
  9666. }
  9667. return 0;
  9668. }
  9669. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9670. if (!lua_interface)
  9671. return 0;
  9672. Spawn* player = lua_interface->GetSpawn(state);
  9673. int8 step = lua_interface->GetInt8Value(state, 2);
  9674. if (player && player->IsPlayer() && step > 0) {
  9675. ((Player*)player)->SetTutorialStep(step);
  9676. }
  9677. return 0;
  9678. }
  9679. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9680. if (!lua_interface)
  9681. return 0;
  9682. Client* client = 0;
  9683. Spawn* player = lua_interface->GetSpawn(state);
  9684. string window = lua_interface->GetStringValue(state, 2);
  9685. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9686. if (!player) {
  9687. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9688. return 0;
  9689. }
  9690. if (!player->IsPlayer()) {
  9691. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9692. return 0;
  9693. }
  9694. else
  9695. client = ((Player*)player)->GetClient();
  9696. if (!client) {
  9697. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9698. return 0;
  9699. }
  9700. if (window.length() == 0) {
  9701. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9702. return 0;
  9703. }
  9704. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9705. if (packet) {
  9706. packet->setDataByName("window", window.c_str());
  9707. packet->setDataByName("flash_seconds", flash_seconds);
  9708. client->QueuePacket(packet->serialize());
  9709. safe_delete(packet);
  9710. }
  9711. return 0;
  9712. }
  9713. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9714. if (!lua_interface)
  9715. return 0;
  9716. Spawn* spawn = lua_interface->GetSpawn(state);
  9717. Spawn* target = lua_interface->GetSpawn(state, 2);
  9718. if (spawn && target)
  9719. return spawn->CheckLoS(target);
  9720. return 0;
  9721. }
  9722. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9723. if (!lua_interface)
  9724. return 0;
  9725. Spawn* spawn = lua_interface->GetSpawn(state);
  9726. float x = lua_interface->GetFloatValue(state, 2);
  9727. float y = lua_interface->GetFloatValue(state, 3);
  9728. float z = lua_interface->GetFloatValue(state, 4);
  9729. if (spawn)
  9730. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9731. return 0;
  9732. }
  9733. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9734. if (!lua_interface)
  9735. return 0;
  9736. ZoneServer* zone = lua_interface->GetZone(state);
  9737. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9738. if (zone)
  9739. zone->SetExpansionFlag(xpackFlag);
  9740. return 0;
  9741. }
  9742. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9743. if (!lua_interface)
  9744. return 0;
  9745. ZoneServer* zone = lua_interface->GetZone(state);
  9746. if (zone) {
  9747. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9748. return 1;
  9749. }
  9750. return 0;
  9751. }
  9752. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9753. if (!lua_interface)
  9754. return 0;
  9755. ZoneServer* zone = lua_interface->GetZone(state);
  9756. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9757. if (zone)
  9758. zone->SetHolidayFlag(holidayFlag);
  9759. return 0;
  9760. }
  9761. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9762. if (!lua_interface)
  9763. return 0;
  9764. ZoneServer* zone = lua_interface->GetZone(state);
  9765. if (zone) {
  9766. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9767. return 1;
  9768. }
  9769. return 0;
  9770. }
  9771. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9772. if (!lua_interface)
  9773. return 0;
  9774. Spawn* player = lua_interface->GetSpawn(state);
  9775. ZoneServer* zone = player->GetZone();
  9776. bool canbind = lua_interface->GetInt32Value(state, 2);
  9777. if (zone)
  9778. zone->SetCanBind(canbind);
  9779. return 0;
  9780. }
  9781. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9782. if (!lua_interface)
  9783. return 0;
  9784. Spawn* player = lua_interface->GetSpawn(state);
  9785. ZoneServer* zone = player->GetZone();
  9786. if (zone) {
  9787. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9788. return 1;
  9789. }
  9790. return 0;
  9791. }
  9792. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  9793. if (!lua_interface)
  9794. return 0;
  9795. Spawn* player = lua_interface->GetSpawn(state);
  9796. ZoneServer* zone = player->GetZone();
  9797. bool cangate = lua_interface->GetInt32Value(state, 2);
  9798. if (zone)
  9799. zone->SetCanGate(cangate);
  9800. return 0;
  9801. }
  9802. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  9803. if (!lua_interface)
  9804. return 0;
  9805. Spawn* player = lua_interface->GetSpawn(state);
  9806. ZoneServer* zone = player->GetZone();
  9807. if (zone) {
  9808. lua_interface->SetInt32Value(state, zone->GetCanGate());
  9809. return 1;
  9810. }
  9811. return 0;
  9812. }
  9813. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9814. if (!lua_interface)
  9815. return 0;
  9816. Spawn* spawn = lua_interface->GetSpawn(state);
  9817. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9818. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9819. float distance = lua_interface->GetFloatValue(state, 4);
  9820. string in_range_function = lua_interface->GetStringValue(state, 5);
  9821. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9822. if (spawn && distance > 0 && in_range_function.length() > 0)
  9823. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9824. return 0;
  9825. }
  9826. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9827. if (!lua_interface)
  9828. return 0;
  9829. Spawn* spawn = lua_interface->GetSpawn(state);
  9830. Spawn* target = lua_interface->GetSpawn(state, 2);
  9831. if (spawn && target)
  9832. {
  9833. if (spawn->IsPlayer() && target->IsEntity())
  9834. {
  9835. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9836. return 1;
  9837. }
  9838. else if (spawn->IsEntity() && target->IsEntity())
  9839. {
  9840. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9841. return 1;
  9842. }
  9843. }
  9844. return 0;
  9845. }
  9846. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9847. if (!lua_interface)
  9848. return 0;
  9849. Spawn* spawn = lua_interface->GetSpawn(state);
  9850. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9851. if (spawn && spawn->IsEntity())
  9852. {
  9853. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9854. if (spawn->IsPlayer())
  9855. {
  9856. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9857. if (client)
  9858. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9859. }
  9860. }
  9861. return 0;
  9862. }
  9863. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9864. if (!lua_interface)
  9865. return 0;
  9866. Spawn* spawn = lua_interface->GetSpawn(state);
  9867. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9868. if (spawn && spawn->IsEntity())
  9869. {
  9870. ((Entity*)spawn)->SetSeeHideSpell(val);
  9871. if (spawn->IsPlayer())
  9872. {
  9873. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9874. if (client)
  9875. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9876. }
  9877. }
  9878. return 0;
  9879. }
  9880. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9881. {
  9882. if (!lua_interface)
  9883. return 0;
  9884. Spawn* player = lua_interface->GetSpawn(state);
  9885. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9886. string command = lua_interface->GetStringValue(state, 3);
  9887. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9888. lua_interface->ResetFunctionStack(state);
  9889. if (spawn && player && player->IsPlayer())
  9890. {
  9891. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9892. bool res = false;
  9893. if (cmd)
  9894. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9895. lua_interface->SetBooleanValue(state, res);
  9896. return 1;
  9897. }
  9898. return 0;
  9899. }
  9900. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9901. {
  9902. if (!lua_interface)
  9903. return 0;
  9904. Spawn* spawn = lua_interface->GetSpawn(state);
  9905. int32 charID = lua_interface->GetInt32Value(state, 2);
  9906. string command = lua_interface->GetStringValue(state, 3);
  9907. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9908. lua_interface->ResetFunctionStack(state);
  9909. if (spawn && charID)
  9910. {
  9911. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9912. bool res = false;
  9913. if (cmd)
  9914. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9915. lua_interface->SetBooleanValue(state, res);
  9916. return 1;
  9917. }
  9918. return 0;
  9919. }
  9920. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9921. {
  9922. if (!lua_interface)
  9923. return 0;
  9924. Spawn* spawn = lua_interface->GetSpawn(state);
  9925. string command = lua_interface->GetStringValue(state, 2);
  9926. lua_interface->ResetFunctionStack(state);
  9927. if (spawn && command.length() > 0)
  9928. spawn->RemovePrimaryEntityCommand(command.c_str());
  9929. return 0;
  9930. }
  9931. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9932. if (!lua_interface)
  9933. return 0;
  9934. Spawn* spawn = lua_interface->GetSpawn(state);
  9935. float distance = lua_interface->GetFloatValue(state, 2);
  9936. string command = lua_interface->GetStringValue(state, 3);
  9937. Spawn* player = lua_interface->GetSpawn(state, 4);
  9938. lua_interface->ResetFunctionStack(state);
  9939. if (spawn) {
  9940. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9941. }
  9942. return 0;
  9943. }
  9944. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9945. if (!lua_interface)
  9946. return 0;
  9947. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9948. Spawn* spawn = lua_interface->GetSpawn(state);
  9949. Spawn* player = lua_interface->GetSpawn(state, 2);
  9950. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9951. lua_interface->ResetFunctionStack(state);
  9952. if (spawn && player && transport_id && player->IsPlayer()) {
  9953. Client* client = 0;
  9954. if (player && player->IsPlayer())
  9955. client = player->GetZone()->GetClientBySpawn(player);
  9956. if (!client)
  9957. return 0;
  9958. vector<TransportDestination*> destinations;
  9959. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9960. if (destinations.size())
  9961. {
  9962. client->SetTemporaryTransportID(transport_id);
  9963. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9964. }
  9965. else
  9966. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9967. }
  9968. return 0;
  9969. }
  9970. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9971. if (!lua_interface)
  9972. return 0;
  9973. Spawn* player = lua_interface->GetSpawn(state);
  9974. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9975. lua_interface->ResetFunctionStack(state);
  9976. if (player && player->IsPlayer()) {
  9977. Client* client = 0;
  9978. if (player && player->IsPlayer())
  9979. client = player->GetZone()->GetClientBySpawn(player);
  9980. if (!client)
  9981. return 0;
  9982. client->SetTemporaryTransportID(transport_id);
  9983. }
  9984. return 0;
  9985. }
  9986. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9987. if (!lua_interface)
  9988. return 0;
  9989. Spawn* player = lua_interface->GetSpawn(state);
  9990. lua_interface->ResetFunctionStack(state);
  9991. if (player && player->IsPlayer()) {
  9992. Client* client = 0;
  9993. if (player && player->IsPlayer())
  9994. client = player->GetZone()->GetClientBySpawn(player);
  9995. if (!client)
  9996. return 0;
  9997. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9998. return 1;
  9999. }
  10000. return 0;
  10001. }
  10002. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10003. if (!lua_interface)
  10004. return 0;
  10005. Spawn* spawn = lua_interface->GetSpawn(state);
  10006. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10007. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10008. if (!spawn) {
  10009. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10010. return 0;
  10011. }
  10012. if (!spawn->IsEntity()) {
  10013. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10014. return 0;
  10015. }
  10016. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10017. {
  10018. 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);
  10019. return 0;
  10020. }
  10021. lua_interface->ResetFunctionStack(state);
  10022. if (spell && spell->targets.size() > 0) {
  10023. ZoneServer* zone = spell->caster->GetZone();
  10024. for (int8 i = 0; i < spell->targets.size(); i++) {
  10025. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10026. if (target && target->IsEntity()) {
  10027. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10028. if (target->IsPlayer())
  10029. ((Player*)target)->SetCharSheetChanged(true);
  10030. }
  10031. }
  10032. }
  10033. else {
  10034. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10035. if (spawn->IsPlayer())
  10036. ((Player*)spawn)->SetCharSheetChanged(true);
  10037. }
  10038. return 0;
  10039. }
  10040. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10041. if (!lua_interface)
  10042. return 0;
  10043. Spawn* spawn = lua_interface->GetSpawn(state);
  10044. lua_interface->ResetFunctionStack(state);
  10045. if (!spawn) {
  10046. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10047. return 0;
  10048. }
  10049. if (!spawn->IsEntity()) {
  10050. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10051. return 0;
  10052. }
  10053. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10054. return 1;
  10055. }
  10056. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10057. if (!lua_interface)
  10058. return 0;
  10059. int32 spell_id = lua_interface->GetInt32Value(state);
  10060. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10061. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10062. if (spell_id > 0) {
  10063. if (spell_tier == 0)
  10064. spell_tier = 1;
  10065. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10066. LuaSpell* lua_spell = 0;
  10067. if(custom_lua_script.size() > 0)
  10068. {
  10069. // attempt to load the custom script since it isn't already loaded
  10070. // we will re-obtain the lua_spell further below
  10071. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10072. {
  10073. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  10074. lua_interface->LoadLuaSpell(custom_lua_script);
  10075. }
  10076. }
  10077. else
  10078. custom_lua_script = spell->GetSpellData()->lua_script;
  10079. if (!lua_spell && lua_interface)
  10080. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10081. if (!lua_spell)
  10082. {
  10083. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10084. return 0;
  10085. }
  10086. lua_spell->spell = new Spell(spell);
  10087. lua_interface->AddCustomSpell(lua_spell);
  10088. lua_interface->SetSpellValue(state, lua_spell);
  10089. return 1;
  10090. }
  10091. return 0;
  10092. }
  10093. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10094. if (!lua_interface)
  10095. return 0;
  10096. LuaSpell* spell = lua_interface->GetSpell(state);
  10097. string field = lua_interface->GetStringValue(state, 2);
  10098. if (!spell) {
  10099. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10100. return 0;
  10101. }
  10102. if (!spell->spell || !spell->spell->GetSpellData()) {
  10103. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10104. return 0;
  10105. }
  10106. boost::to_lower(field);
  10107. return spell->spell->GetSpellData(state, field);
  10108. }
  10109. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10110. if (!lua_interface)
  10111. return 0;
  10112. LuaSpell* spell = lua_interface->GetSpell(state);
  10113. string field = lua_interface->GetStringValue(state, 2);
  10114. int8 fieldArg = 3; // field value after the initial set
  10115. if (!spell) {
  10116. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10117. return 0;
  10118. }
  10119. if (!spell->spell || !spell->spell->GetSpellData()) {
  10120. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10121. return 0;
  10122. }
  10123. boost::to_lower(field);
  10124. bool valSet = false;
  10125. spell->spell->SetSpellData(state, field, fieldArg);
  10126. return valSet;
  10127. }
  10128. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10129. if (!lua_interface)
  10130. return 0;
  10131. LuaSpell* spell = lua_interface->GetSpell(state);
  10132. int8 idx = lua_interface->GetInt32Value(state, 2);
  10133. if (!spell) {
  10134. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10135. return 0;
  10136. }
  10137. if (!spell->spell || !spell->spell->GetSpellData()) {
  10138. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10139. return 0;
  10140. }
  10141. if (spell->spell->lua_data.size() <= idx)
  10142. {
  10143. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10144. return 0;
  10145. }
  10146. bool setVal = true;
  10147. LUAData* data = spell->spell->lua_data[idx];
  10148. switch (data->type)
  10149. {
  10150. case 0:
  10151. {
  10152. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10153. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10154. data->int_value = value;
  10155. data->int_value2 = value2;
  10156. break;
  10157. }
  10158. case 1:
  10159. {
  10160. float value = lua_interface->GetFloatValue(state, 3);
  10161. float value2 = lua_interface->GetFloatValue(state, 4);
  10162. data->float_value = value;
  10163. data->float_value2 = value2;
  10164. break;
  10165. }
  10166. case 2:
  10167. {
  10168. bool value = lua_interface->GetBooleanValue(state, 3);
  10169. data->bool_value = value;
  10170. break;
  10171. }
  10172. case 3:
  10173. {
  10174. string value = lua_interface->GetStringValue(state, 3);
  10175. string value2 = lua_interface->GetStringValue(state, 4);
  10176. data->string_value = value;
  10177. data->string_value2 = value2;
  10178. break;
  10179. }
  10180. default:
  10181. setVal = false;
  10182. }
  10183. return setVal;
  10184. }
  10185. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10186. if (!lua_interface)
  10187. return 0;
  10188. LuaSpell* spell = lua_interface->GetSpell(state);
  10189. int8 idx = lua_interface->GetInt32Value(state, 2);
  10190. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10191. if (!spell) {
  10192. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10193. return 0;
  10194. }
  10195. if (!spell->spell || !spell->spell->GetSpellData()) {
  10196. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10197. return 0;
  10198. }
  10199. if (spell->spell->lua_data.size() <= idx)
  10200. {
  10201. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10202. return 0;
  10203. }
  10204. bool setVal = true;
  10205. LUAData* data = spell->spell->lua_data[idx];
  10206. switch (data->type)
  10207. {
  10208. case 0:
  10209. {
  10210. if(!secondfield)
  10211. lua_interface->SetSInt32Value(state, data->int_value);
  10212. else
  10213. lua_interface->SetSInt32Value(state, data->int_value2);
  10214. break;
  10215. }
  10216. case 1:
  10217. {
  10218. if (!secondfield)
  10219. lua_interface->SetFloatValue(state, data->float_value);
  10220. else
  10221. lua_interface->SetFloatValue(state, data->float_value2);
  10222. break;
  10223. }
  10224. case 2:
  10225. {
  10226. lua_interface->SetBooleanValue(state, data->bool_value);
  10227. break;
  10228. }
  10229. case 3:
  10230. {
  10231. if (!secondfield)
  10232. lua_interface->SetStringValue(state, data->string_value.c_str());
  10233. else
  10234. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10235. break;
  10236. }
  10237. default:
  10238. setVal = false;
  10239. }
  10240. return setVal;
  10241. }
  10242. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10243. if (!lua_interface)
  10244. return 0;
  10245. LuaSpell* spell = lua_interface->GetSpell(state);
  10246. int8 idx = lua_interface->GetInt32Value(state, 2);
  10247. string field = lua_interface->GetStringValue(state, 3);
  10248. boost::to_lower(field);
  10249. if (!spell) {
  10250. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10251. return 0;
  10252. }
  10253. if (!spell->spell || !spell->spell->GetSpellData()) {
  10254. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10255. return 0;
  10256. }
  10257. if (spell->spell->effects.size() <= idx)
  10258. {
  10259. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10260. return 0;
  10261. }
  10262. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10263. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10264. if (field == "description")
  10265. effect->description = string(lua_interface->GetStringValue(state, 4));
  10266. else if (field == "bullet")
  10267. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10268. else if (field == "percentage")
  10269. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10270. else // no match
  10271. return 0;
  10272. return 1;
  10273. }
  10274. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10275. if (!lua_interface)
  10276. return 0;
  10277. LuaSpell* spell = lua_interface->GetSpell(state);
  10278. int8 idx = lua_interface->GetInt32Value(state, 2);
  10279. string field = lua_interface->GetStringValue(state, 3);
  10280. boost::to_lower(field);
  10281. if (!spell) {
  10282. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10283. return 0;
  10284. }
  10285. if (!spell->spell || !spell->spell->GetSpellData()) {
  10286. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10287. return 0;
  10288. }
  10289. if (spell->spell->effects.size() <= idx)
  10290. {
  10291. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10292. return 0;
  10293. }
  10294. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10295. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10296. if (field == "description")
  10297. lua_interface->SetStringValue(state, effect->description.c_str());
  10298. else if (field == "bullet")
  10299. lua_interface->SetInt32Value(state, effect->subbullet);
  10300. else if (field == "percentage")
  10301. lua_interface->SetInt32Value(state, effect->percentage);
  10302. else // no match
  10303. return 0;
  10304. return 1;
  10305. }
  10306. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10307. if (!lua_interface)
  10308. return 0;
  10309. LuaSpell* spell = lua_interface->GetSpell(state);
  10310. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10311. Spawn* target = lua_interface->GetSpawn(state, 3);
  10312. if (!target) {
  10313. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10314. return 0;
  10315. }
  10316. if (!target->IsEntity()) {
  10317. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10318. return 0;
  10319. }
  10320. if (!spell) {
  10321. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10322. return 0;
  10323. }
  10324. if (caster && !caster->IsEntity()) {
  10325. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10326. return 0;
  10327. }
  10328. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10329. return 0;
  10330. }
  10331. int EQ2Emu_lua_InWater(lua_State* state) {
  10332. if (!lua_interface)
  10333. return 0;
  10334. Spawn* spawn = lua_interface->GetSpawn(state);
  10335. lua_interface->ResetFunctionStack(state);
  10336. if (spawn) {
  10337. lua_interface->SetBooleanValue(state, spawn->InWater());
  10338. return 1;
  10339. }
  10340. return 0;
  10341. }
  10342. int EQ2Emu_lua_InLava(lua_State* state) {
  10343. if (!lua_interface)
  10344. return 0;
  10345. Spawn* spawn = lua_interface->GetSpawn(state);
  10346. lua_interface->ResetFunctionStack(state);
  10347. if (spawn) {
  10348. lua_interface->SetBooleanValue(state, spawn->InLava());
  10349. return 1;
  10350. }
  10351. return 0;
  10352. }
  10353. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10354. if (!lua_interface)
  10355. return 0;
  10356. Spawn* attacker = lua_interface->GetSpawn(state);
  10357. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10358. int8 type = lua_interface->GetInt8Value(state, 3);
  10359. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10360. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10361. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10362. string spell_name = lua_interface->GetStringValue(state, 7);
  10363. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10364. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10365. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10366. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10367. lua_interface->ResetFunctionStack(state);
  10368. if (!attacker) {
  10369. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10370. return 0;
  10371. }
  10372. if (!attacker->IsEntity()) {
  10373. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10374. return 0;
  10375. }
  10376. if (!victim) {
  10377. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10378. return 0;
  10379. }
  10380. if (!victim->IsEntity()) {
  10381. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10382. return 0;
  10383. }
  10384. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10385. return 0;
  10386. }
  10387. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10388. if (!lua_interface)
  10389. return 0;
  10390. Spawn* spawn = lua_interface->GetSpawn(state);
  10391. lua_interface->ResetFunctionStack(state);
  10392. if (spawn) {
  10393. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10394. return 1;
  10395. }
  10396. return 0;
  10397. }
  10398. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10399. if (!lua_interface)
  10400. return 0;
  10401. Spawn* spawn = lua_interface->GetSpawn(state);
  10402. bool invul = lua_interface->GetBooleanValue(state, 2);
  10403. lua_interface->ResetFunctionStack(state);
  10404. if (spawn) {
  10405. spawn->SetInvulnerable(invul);
  10406. }
  10407. return 0;
  10408. }
  10409. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10410. if (!lua_interface)
  10411. return 0;
  10412. string category = lua_interface->GetStringValue(state);
  10413. string name = lua_interface->GetStringValue(state, 2);
  10414. lua_interface->ResetFunctionStack(state);
  10415. Rule *ret = 0;
  10416. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10417. lua_interface->SetBooleanValue(state, ret->GetBool());
  10418. return 1;
  10419. }
  10420. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10421. return 0;
  10422. }
  10423. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10424. if (!lua_interface)
  10425. return 0;
  10426. string category = lua_interface->GetStringValue(state);
  10427. string name = lua_interface->GetStringValue(state, 2);
  10428. lua_interface->ResetFunctionStack(state);
  10429. Rule *ret = 0;
  10430. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10431. lua_interface->SetInt32Value(state, ret->GetInt32());
  10432. return 1;
  10433. }
  10434. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10435. return 0;
  10436. }
  10437. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10438. if (!lua_interface)
  10439. return 0;
  10440. string category = lua_interface->GetStringValue(state);
  10441. string name = lua_interface->GetStringValue(state, 2);
  10442. lua_interface->ResetFunctionStack(state);
  10443. Rule *ret = 0;
  10444. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10445. lua_interface->SetFloatValue(state, ret->GetFloat());
  10446. return 1;
  10447. }
  10448. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10449. return 0;
  10450. }
  10451. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10452. if (!lua_interface)
  10453. return 0;
  10454. Spawn* spawn = lua_interface->GetSpawn(state);
  10455. string type = lua_interface->GetStringValue(state, 2);
  10456. lua_interface->ResetFunctionStack(state);
  10457. if (spawn) {
  10458. int res = 1;
  10459. boost::to_lower(type);
  10460. if(type == "assigned_aa")
  10461. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10462. else if ( type == "unassigned_aa")
  10463. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10464. else if ( type == "assigned_tradeskill_aa")
  10465. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10466. else if ( type == "unassigned_tradeskill_aa")
  10467. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10468. else if ( type == "assigned_prestige_aa")
  10469. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10470. else if ( type == "unassigned_prestige_aa")
  10471. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10472. else if ( type == "assigned_tradeskill_prestige_aa")
  10473. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10474. else if ( type == "unassigned_tradeskill_prestige_aa")
  10475. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10476. else
  10477. res = 0;
  10478. return res;
  10479. }
  10480. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10481. return 0;
  10482. }
  10483. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10484. if (!lua_interface)
  10485. return 0;
  10486. Spawn* spawn = lua_interface->GetSpawn(state);
  10487. string type = lua_interface->GetStringValue(state, 2);
  10488. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10489. lua_interface->ResetFunctionStack(state);
  10490. if (spawn) {
  10491. boost::to_lower(type);
  10492. if(type == "assigned_aa")
  10493. spawn->SetAssignedAA((sint16)value);
  10494. else if ( type == "unassigned_aa")
  10495. spawn->SetUnassignedAA((sint16)value);
  10496. else if ( type == "assigned_tradeskill_aa")
  10497. spawn->SetTradeskillAA((sint16)value);
  10498. else if ( type == "unassigned_tradeskill_aa")
  10499. spawn->SetUnassignedTradeskillAA((sint16)value);
  10500. else if ( type == "assigned_prestige_aa")
  10501. spawn->SetPrestigeAA((sint16)value);
  10502. else if ( type == "unassigned_prestige_aa")
  10503. spawn->SetUnassignedPrestigeAA((sint16)value);
  10504. else if ( type == "assigned_tradeskill_prestige_aa")
  10505. spawn->SetTradeskillPrestigeAA((sint16)value);
  10506. else if ( type == "unassigned_tradeskill_prestige_aa")
  10507. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10508. if(spawn->IsPlayer())
  10509. ((Player*)spawn)->SetCharSheetChanged(true);
  10510. }
  10511. return 0;
  10512. }
  10513. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10514. if (!lua_interface)
  10515. return 0;
  10516. string titleName = lua_interface->GetStringValue(state);
  10517. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10518. lua_interface->ResetFunctionStack(state);
  10519. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10520. lua_interface->SetSInt32Value(state, index);
  10521. return 1;
  10522. }
  10523. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10524. if (!lua_interface)
  10525. return 0;
  10526. Spawn* spawn = lua_interface->GetSpawn(state);
  10527. string titleName = lua_interface->GetStringValue(state, 2);
  10528. lua_interface->ResetFunctionStack(state);
  10529. if(!spawn->IsPlayer())
  10530. {
  10531. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10532. lua_interface->SetSInt32Value(state, -1);
  10533. return 1;
  10534. }
  10535. Player* player = (Player*)spawn;
  10536. // check if player already has the title, don't need to add twice
  10537. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10538. if ( playerHasTitle)
  10539. {
  10540. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10541. return 1;
  10542. }
  10543. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10544. if(!title)
  10545. {
  10546. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10547. lua_interface->SetSInt32Value(state, -1);
  10548. return 1;
  10549. }
  10550. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10551. if(returnIdx < 0)
  10552. {
  10553. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10554. }
  10555. lua_interface->SetSInt32Value(state, returnIdx);
  10556. player->GetClient()->SendTitleUpdate();
  10557. return 1;
  10558. }
  10559. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10560. if (!lua_interface)
  10561. return 0;
  10562. Spawn* spawn = lua_interface->GetSpawn(state);
  10563. string titleName = lua_interface->GetStringValue(state, 2);
  10564. lua_interface->ResetFunctionStack(state);
  10565. if(!spawn->IsPlayer())
  10566. {
  10567. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10568. return 0;
  10569. }
  10570. Player* player = (Player*)spawn;
  10571. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10572. if(!title)
  10573. {
  10574. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10575. return 0;
  10576. }
  10577. if(title->GetPrefix())
  10578. {
  10579. 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());
  10580. return 0;
  10581. }
  10582. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10583. player->GetClient()->SendTitleUpdate();
  10584. return 1;
  10585. }
  10586. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10587. if (!lua_interface)
  10588. return 0;
  10589. Spawn* spawn = lua_interface->GetSpawn(state);
  10590. string titleName = lua_interface->GetStringValue(state, 2);
  10591. lua_interface->ResetFunctionStack(state);
  10592. if(!spawn->IsPlayer())
  10593. {
  10594. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10595. return 0;
  10596. }
  10597. Player* player = (Player*)spawn;
  10598. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10599. if(!title)
  10600. {
  10601. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10602. return 0;
  10603. }
  10604. if(!title->GetPrefix())
  10605. {
  10606. 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());
  10607. return 0;
  10608. }
  10609. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10610. player->GetClient()->SendTitleUpdate();
  10611. return 1;
  10612. }
  10613. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10614. if (!lua_interface)
  10615. return 0;
  10616. Spawn* spawn = lua_interface->GetSpawn(state);
  10617. lua_interface->ResetFunctionStack(state);
  10618. if(!spawn->IsPlayer())
  10619. {
  10620. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10621. return 0;
  10622. }
  10623. Player* player = (Player*)spawn;
  10624. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10625. player->GetClient()->SendTitleUpdate();
  10626. return 1;
  10627. }
  10628. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10629. if (!lua_interface)
  10630. return 0;
  10631. Spawn* spawn = lua_interface->GetSpawn(state);
  10632. lua_interface->ResetFunctionStack(state);
  10633. if(!spawn->IsPlayer())
  10634. {
  10635. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10636. return 0;
  10637. }
  10638. Player* player = (Player*)spawn;
  10639. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10640. player->GetClient()->SendTitleUpdate();
  10641. return 1;
  10642. }
  10643. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10644. if (!lua_interface)
  10645. return 0;
  10646. Spawn* spawn = lua_interface->GetSpawn(state);
  10647. string field = lua_interface->GetStringValue(state, 2);
  10648. lua_interface->ResetFunctionStack(state);
  10649. if(!spawn || !spawn->IsEntity())
  10650. {
  10651. 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));
  10652. return 0;
  10653. }
  10654. Entity* ent = (Entity*)spawn;
  10655. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10656. return 1;
  10657. }
  10658. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10659. if (!lua_interface)
  10660. return 0;
  10661. Spawn* spawn = lua_interface->GetSpawn(state);
  10662. string field = lua_interface->GetStringValue(state, 2);
  10663. lua_interface->ResetFunctionStack(state);
  10664. if(!spawn || !spawn->IsEntity())
  10665. {
  10666. 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));
  10667. return 0;
  10668. }
  10669. Entity* ent = (Entity*)spawn;
  10670. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10671. return 1;
  10672. }
  10673. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10674. if (!lua_interface)
  10675. return 0;
  10676. Spawn* spawn = lua_interface->GetSpawn(state);
  10677. string field = lua_interface->GetStringValue(state, 2);
  10678. lua_interface->ResetFunctionStack(state);
  10679. if(!spawn || !spawn->IsEntity())
  10680. {
  10681. 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));
  10682. return 0;
  10683. }
  10684. Entity* ent = (Entity*)spawn;
  10685. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10686. return 1;
  10687. }
  10688. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10689. if (!lua_interface)
  10690. return 0;
  10691. Spawn* spawn = lua_interface->GetSpawn(state);
  10692. string field = lua_interface->GetStringValue(state, 2);
  10693. lua_interface->ResetFunctionStack(state);
  10694. if(!spawn || !spawn->IsEntity())
  10695. {
  10696. 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));
  10697. return 0;
  10698. }
  10699. Entity* ent = (Entity*)spawn;
  10700. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10701. return 1;
  10702. }
  10703. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10704. if (!lua_interface)
  10705. return 0;
  10706. Spawn* spawn = lua_interface->GetSpawn(state);
  10707. string field = lua_interface->GetStringValue(state, 2);
  10708. string value = lua_interface->GetStringValue(state, 3);
  10709. lua_interface->ResetFunctionStack(state);
  10710. if(!spawn || !spawn->IsEntity())
  10711. {
  10712. 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));
  10713. return 0;
  10714. }
  10715. Entity* ent = (Entity*)spawn;
  10716. bool set_ = ent->SetInfoStructString(field, value);
  10717. lua_interface->SetBooleanValue(state, set_);
  10718. return 1;
  10719. }
  10720. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. Spawn* spawn = lua_interface->GetSpawn(state);
  10724. string field = lua_interface->GetStringValue(state, 2);
  10725. int64 value = lua_interface->GetInt64Value(state, 3);
  10726. lua_interface->ResetFunctionStack(state);
  10727. if(!spawn || !spawn->IsEntity())
  10728. {
  10729. 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));
  10730. return 0;
  10731. }
  10732. Entity* ent = (Entity*)spawn;
  10733. bool set_ = ent->SetInfoStructUInt(field, value);
  10734. lua_interface->SetBooleanValue(state, set_);
  10735. return 1;
  10736. }
  10737. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10738. if (!lua_interface)
  10739. return 0;
  10740. Spawn* spawn = lua_interface->GetSpawn(state);
  10741. string field = lua_interface->GetStringValue(state, 2);
  10742. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10743. lua_interface->ResetFunctionStack(state);
  10744. if(!spawn || !spawn->IsEntity())
  10745. {
  10746. 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));
  10747. return 0;
  10748. }
  10749. Entity* ent = (Entity*)spawn;
  10750. bool set_ = ent->SetInfoStructSInt(field, value);
  10751. lua_interface->SetBooleanValue(state, set_);
  10752. return 1;
  10753. }
  10754. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10755. if (!lua_interface)
  10756. return 0;
  10757. Spawn* spawn = lua_interface->GetSpawn(state);
  10758. string field = lua_interface->GetStringValue(state, 2);
  10759. float value = lua_interface->GetFloatValue(state, 3);
  10760. lua_interface->ResetFunctionStack(state);
  10761. if(!spawn || !spawn->IsEntity())
  10762. {
  10763. 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));
  10764. return 0;
  10765. }
  10766. Entity* ent = (Entity*)spawn;
  10767. bool set_ = ent->SetInfoStructFloat(field, value);
  10768. lua_interface->SetBooleanValue(state, set_);
  10769. return 1;
  10770. }
  10771. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10772. if (!lua_interface)
  10773. return 0;
  10774. Spawn* spawn = lua_interface->GetSpawn(state);
  10775. bool value = lua_interface->GetBooleanValue(state, 2);
  10776. lua_interface->ResetFunctionStack(state);
  10777. if(!spawn || !spawn->IsPlayer())
  10778. {
  10779. 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));
  10780. return 0;
  10781. }
  10782. ((Player*)spawn)->SetCharSheetChanged(value);
  10783. return 0;
  10784. }
  10785. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10786. if (!lua_interface)
  10787. return 0;
  10788. Spawn* spawn = lua_interface->GetSpawn(state);
  10789. std::string fromName = lua_interface->GetStringValue(state, 2);
  10790. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10791. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10792. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10793. int32 copper = lua_interface->GetInt32Value(state, 6);
  10794. int32 silver = lua_interface->GetInt32Value(state, 7);
  10795. int32 gold = lua_interface->GetInt32Value(state, 8);
  10796. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10797. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10798. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10799. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10800. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10801. lua_interface->ResetFunctionStack(state);
  10802. if(!spawn || !spawn->IsPlayer())
  10803. {
  10804. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10805. lua_interface->SetBooleanValue(state, false);
  10806. return 1;
  10807. }
  10808. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10809. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10810. lua_interface->SetBooleanValue(state, true);
  10811. return 1;
  10812. }
  10813. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10814. if (!lua_interface)
  10815. return 0;
  10816. int32 char_id = lua_interface->GetInt32Value(state);
  10817. std::string fromName = lua_interface->GetStringValue(state, 2);
  10818. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10819. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10820. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10821. int32 copper = lua_interface->GetInt32Value(state, 6);
  10822. int32 silver = lua_interface->GetInt32Value(state, 7);
  10823. int32 gold = lua_interface->GetInt32Value(state, 8);
  10824. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10825. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10826. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10827. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10828. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10829. lua_interface->ResetFunctionStack(state);
  10830. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10831. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10832. lua_interface->SetBooleanValue(state, true);
  10833. return 1;
  10834. }
  10835. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10836. Spawn* widget;
  10837. if (lua_interface) {
  10838. widget = lua_interface->GetSpawn(state);
  10839. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10840. lua_interface->ResetFunctionStack(state);
  10841. if (widget && widget->IsWidget())
  10842. {
  10843. ((Widget*)widget)->OpenDoor();
  10844. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10845. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10846. }
  10847. else
  10848. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10849. }
  10850. return 0;
  10851. }
  10852. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10853. Spawn* widget;
  10854. if (lua_interface) {
  10855. widget = lua_interface->GetSpawn(state);
  10856. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10857. lua_interface->ResetFunctionStack(state);
  10858. if (widget && widget->IsWidget())
  10859. {
  10860. ((Widget*)widget)->CloseDoor();
  10861. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10862. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10863. }
  10864. else
  10865. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10866. }
  10867. return 0;
  10868. }
  10869. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10870. if (!lua_interface)
  10871. return 0;
  10872. Spawn* widget = lua_interface->GetSpawn(state);
  10873. lua_interface->ResetFunctionStack(state);
  10874. if (widget && widget->IsWidget())
  10875. {
  10876. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10877. return 1;
  10878. }
  10879. return 0;
  10880. }
  10881. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10882. if (!lua_interface)
  10883. return 0;
  10884. sint32 min = lua_interface->GetSInt32Value(state);
  10885. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10886. lua_interface->ResetFunctionStack(state);
  10887. sint32 result = MakeRandomInt(min, max);
  10888. lua_interface->SetSInt32Value(state, result);
  10889. return 1;
  10890. }
  10891. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10892. if (!lua_interface)
  10893. return 0;
  10894. float min = lua_interface->GetFloatValue(state);
  10895. float max = lua_interface->GetFloatValue(state, 2);
  10896. lua_interface->ResetFunctionStack(state);
  10897. float result = MakeRandomFloat(min, max);
  10898. lua_interface->SetFloatValue(state, result);
  10899. return 1;
  10900. }
  10901. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10902. if (!lua_interface)
  10903. return 0;
  10904. Spawn* spawn = lua_interface->GetSpawn(state);
  10905. int32 value = lua_interface->GetInt32Value(state, 2);
  10906. lua_interface->ResetFunctionStack(state);
  10907. if(!spawn)
  10908. {
  10909. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10910. lua_interface->SetBooleanValue(state, false);
  10911. return 1;
  10912. }
  10913. spawn->AddIconValue(value);
  10914. lua_interface->SetBooleanValue(state, true);
  10915. return 1;
  10916. }
  10917. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10918. if (!lua_interface)
  10919. return 0;
  10920. Spawn* spawn = lua_interface->GetSpawn(state);
  10921. int32 value = lua_interface->GetInt32Value(state, 2);
  10922. lua_interface->ResetFunctionStack(state);
  10923. if(!spawn)
  10924. {
  10925. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10926. lua_interface->SetBooleanValue(state, false);
  10927. return 1;
  10928. }
  10929. spawn->RemoveIconValue(value);
  10930. lua_interface->SetBooleanValue(state, true);
  10931. return 1;
  10932. }
  10933. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10934. Spawn* npc = lua_interface->GetSpawn(state);
  10935. lua_interface->ResetFunctionStack(state);
  10936. if (npc && npc->IsNPC()) {
  10937. NPC* shard = (NPC*)npc;
  10938. int32 shardid = shard->GetShardID();
  10939. lua_interface->SetInt32Value(state, shardid);
  10940. return 1;
  10941. }
  10942. lua_interface->SetInt32Value(state, 0);
  10943. return 1;
  10944. }
  10945. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10946. Spawn* npc = lua_interface->GetSpawn(state);
  10947. lua_interface->ResetFunctionStack(state);
  10948. if (npc && npc->IsNPC()) {
  10949. NPC* shard = (NPC*)npc;
  10950. int32 charid = shard->GetShardCharID();
  10951. lua_interface->SetInt32Value(state, charid);
  10952. return 1;
  10953. }
  10954. lua_interface->SetInt32Value(state, 0);
  10955. return 1;
  10956. }
  10957. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10958. Spawn* npc = lua_interface->GetSpawn(state);
  10959. lua_interface->ResetFunctionStack(state);
  10960. if (npc && npc->IsNPC()) {
  10961. NPC* shard = (NPC*)npc;
  10962. int64 timestamp = shard->GetShardCreatedTimestamp();
  10963. lua_interface->SetSInt64Value(state, timestamp);
  10964. return 1;
  10965. }
  10966. lua_interface->SetSInt64Value(state, 0);
  10967. return 1;
  10968. }
  10969. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10970. if (!lua_interface)
  10971. return 0;
  10972. int32 shardid = lua_interface->GetInt32Value(state);
  10973. lua_interface->ResetFunctionStack(state);
  10974. if(shardid < 1)
  10975. lua_interface->SetBooleanValue(state, false);
  10976. else
  10977. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10978. return 1;
  10979. }
  10980. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10981. if (!lua_interface)
  10982. return 0;
  10983. Spawn* spawn = lua_interface->GetSpawn(state);
  10984. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10985. if (spawn) {
  10986. spawn->PauseMovement(delay_in_ms);
  10987. }
  10988. lua_interface->ResetFunctionStack(state);
  10989. return 0;
  10990. }
  10991. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10992. if (!lua_interface)
  10993. return 0;
  10994. Spawn* spawn = lua_interface->GetSpawn(state);
  10995. if (spawn) {
  10996. spawn->StopMovement();
  10997. }
  10998. lua_interface->ResetFunctionStack(state);
  10999. return 0;
  11000. }
  11001. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11002. Player* player = (Player*)lua_interface->GetSpawn(state);
  11003. int8 level = lua_interface->GetInt8Value(state, 2);
  11004. lua_interface->ResetFunctionStack(state);
  11005. if (player && player->IsPlayer() && level > 0) {
  11006. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11007. return 1;
  11008. }
  11009. return 0;
  11010. }
  11011. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11012. Player* player = (Player*)lua_interface->GetSpawn(state);
  11013. int8 level = lua_interface->GetInt8Value(state, 2);
  11014. lua_interface->ResetFunctionStack(state);
  11015. if (player && player->IsPlayer() && level > 0) {
  11016. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11017. return 1;
  11018. }
  11019. return 0;
  11020. }
  11021. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11022. ZoneServer* zone = lua_interface->GetZone(state);
  11023. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11024. lua_interface->ResetFunctionStack(state);
  11025. if (zone) {
  11026. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11027. if (spawn) {
  11028. lua_interface->SetSpawnValue(state, spawn);
  11029. return 1;
  11030. }
  11031. }
  11032. return 0;
  11033. }
  11034. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11035. if (!lua_interface)
  11036. return 0;
  11037. Spawn* spawn = lua_interface->GetSpawn(state);
  11038. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11039. lua_interface->ResetFunctionStack(state);
  11040. bool res = false;
  11041. if(spawn && spawn->IsTransportSpawn())
  11042. {
  11043. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11044. spawn->SetRailID(rail_id);
  11045. res = true;
  11046. }
  11047. else if (!spawn) {
  11048. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11049. }
  11050. else if(!spawn->IsTransportSpawn()) {
  11051. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11052. }
  11053. lua_interface->SetBooleanValue(state, res);
  11054. return 1;
  11055. }
  11056. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11057. if (!lua_interface)
  11058. return 0;
  11059. ZoneServer* zone = lua_interface->GetZone(state);
  11060. lua_interface->ResetFunctionStack(state);
  11061. if (zone) {
  11062. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11063. return 1;
  11064. }
  11065. return 0;
  11066. }
  11067. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11068. if (!lua_interface)
  11069. return 0;
  11070. Spawn* spawn = lua_interface->GetSpawn(state);
  11071. lua_interface->ResetFunctionStack(state);
  11072. if (spawn) {
  11073. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11074. return 1;
  11075. }
  11076. return 0;
  11077. }
  11078. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11079. if (!lua_interface)
  11080. return 0;
  11081. Spawn* player = lua_interface->GetSpawn(state);
  11082. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11083. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11084. lua_interface->ResetFunctionStack(state);
  11085. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11086. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11087. }
  11088. else if(!zoneID) {
  11089. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11090. }
  11091. else
  11092. {
  11093. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11094. return 1;
  11095. }
  11096. return 0;
  11097. }
  11098. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11099. if (!lua_interface)
  11100. return 0;
  11101. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11102. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11103. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11104. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11105. lua_interface->ResetFunctionStack(state);
  11106. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11107. world.GetWorldTimeStruct()->year = newYear;
  11108. world.GetWorldTimeStruct()->month = newMonth;
  11109. world.GetWorldTimeStruct()->hour = newHour;
  11110. world.GetWorldTimeStruct()->minute = newMinute;
  11111. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11112. return 0;
  11113. }
  11114. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11115. if (!lua_interface)
  11116. return 0;
  11117. lua_interface->ResetFunctionStack(state);
  11118. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11119. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11120. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11121. return 1;
  11122. }
  11123. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11124. if (!lua_interface)
  11125. return 0;
  11126. lua_interface->ResetFunctionStack(state);
  11127. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11128. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11129. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11130. return 1;
  11131. }
  11132. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11133. if (!lua_interface)
  11134. return 0;
  11135. lua_interface->ResetFunctionStack(state);
  11136. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11137. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11138. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11139. return 1;
  11140. }
  11141. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11142. if (!lua_interface)
  11143. return 0;
  11144. lua_interface->ResetFunctionStack(state);
  11145. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11146. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11147. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11148. return 1;
  11149. }
  11150. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11151. if (!lua_interface)
  11152. return 0;
  11153. lua_interface->ResetFunctionStack(state);
  11154. world.SendTimeUpdate();
  11155. return 0;
  11156. }
  11157. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11158. bool update_result = false;
  11159. Faction* faction = 0;
  11160. Player* player = (Player*)lua_interface->GetSpawn(state);
  11161. Client* client = player->GetZone()->GetClientBySpawn(player);
  11162. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11163. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11164. lua_interface->ResetFunctionStack(state);
  11165. if (player && player->IsPlayer() && faction_id > 0) {
  11166. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11167. if(hasfaction == 0) {
  11168. //they do not have the faction. Lets get the default value and feed it in.
  11169. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11170. //add the default faction for the player.
  11171. player->SetFactionValue(faction_id, defaultfaction);
  11172. }
  11173. if(increase >= 0) {
  11174. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11175. faction = master_faction_list.GetFaction(faction_id);
  11176. if(faction && update_result)
  11177. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11178. else if(faction)
  11179. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11180. lua_interface->SetBooleanValue(state, true);
  11181. return 1;
  11182. }
  11183. if(increase < 0){
  11184. //change the negative to a positive, since thats how decreasefaction() likes it.
  11185. increase *= -1;
  11186. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11187. faction = master_faction_list.GetFaction(faction_id);
  11188. if(faction && update_result)
  11189. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11190. else if(faction)
  11191. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11192. lua_interface->SetBooleanValue(state, true);
  11193. return 1;
  11194. }
  11195. }
  11196. lua_interface->SetBooleanValue(state, false);
  11197. return 1;
  11198. }
  11199. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11200. bool hascoin = 0;
  11201. Player* player = (Player*)lua_interface->GetSpawn(state);
  11202. int32 coins = lua_interface->GetInt32Value(state, 2);
  11203. lua_interface->ResetFunctionStack(state);
  11204. if (player && player->IsPlayer()) {
  11205. hascoin = player->HasCoins(coins);
  11206. if(hascoin == 0) {
  11207. lua_interface->SetBooleanValue(state, false);
  11208. return 1;
  11209. }
  11210. if(hascoin == 1) {
  11211. lua_interface->SetBooleanValue(state, true);
  11212. return 1;
  11213. }
  11214. }
  11215. }
  11216. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11217. int32 loot_tier = 0;
  11218. Spawn* spawn = lua_interface->GetSpawn(state);
  11219. lua_interface->ResetFunctionStack(state);
  11220. if (spawn) {
  11221. loot_tier = spawn->GetLootTier();
  11222. lua_interface->SetInt32Value(state, loot_tier);
  11223. return 1;
  11224. }
  11225. return 0;
  11226. }
  11227. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11228. if (!lua_interface)
  11229. return 0;
  11230. Spawn* spawn = lua_interface->GetSpawn(state);
  11231. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11232. lua_interface->ResetFunctionStack(state);
  11233. if (spawn) {
  11234. spawn->SetLootTier(loot_tier);
  11235. lua_interface->SetBooleanValue(state, true);
  11236. return 1;
  11237. }
  11238. lua_interface->SetBooleanValue(state, false);
  11239. return 1;
  11240. }
  11241. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11242. int32 loot_drop_type = 0;
  11243. Spawn* spawn = lua_interface->GetSpawn(state);
  11244. lua_interface->ResetFunctionStack(state);
  11245. if (spawn) {
  11246. loot_drop_type = spawn->GetLootDropType();
  11247. lua_interface->SetInt32Value(state, loot_drop_type);
  11248. return 1;
  11249. }
  11250. return 0;
  11251. }
  11252. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11253. if (!lua_interface)
  11254. return 0;
  11255. Spawn* spawn = lua_interface->GetSpawn(state);
  11256. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11257. lua_interface->ResetFunctionStack(state);
  11258. if (spawn) {
  11259. spawn->SetLootDropType(loot_drop_type);
  11260. lua_interface->SetBooleanValue(state, true);
  11261. return 1;
  11262. }
  11263. lua_interface->SetBooleanValue(state, false);
  11264. return 1;
  11265. }