LuaFunctions.cpp 454 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 561 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. if(spawn->GetSpawnGroupID() == new_group_id) {
  685. lua_interface->SetBooleanValue(state, false);
  686. return 1;
  687. }
  688. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  689. lua_interface->SetBooleanValue(state, true);
  690. return 1;
  691. }
  692. lua_interface->SetBooleanValue(state, false);
  693. return 1;
  694. }
  695. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. lua_interface->ResetFunctionStack(state);
  698. if (spawn) {
  699. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. lua_interface->ResetFunctionStack(state);
  707. if (spawn) {
  708. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  709. return 1;
  710. }
  711. return 0;
  712. }
  713. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  714. Player* player = (Player*)lua_interface->GetSpawn(state);
  715. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  716. lua_interface->ResetFunctionStack(state);
  717. if (player && player->IsPlayer() && faction_id > 0) {
  718. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. int32 value = lua_interface->GetInt32Value(state, 2);
  728. lua_interface->ResetFunctionStack(state);
  729. if (spawn) {
  730. spawn->SetFactionID(value);
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. lua_interface->ResetFunctionStack(state);
  737. if (spawn) {
  738. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. int EQ2Emu_lua_GetGender(lua_State* state) {
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. lua_interface->ResetFunctionStack(state);
  746. if (spawn) {
  747. lua_interface->SetInt32Value(state, spawn->GetGender());
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. int EQ2Emu_lua_GetTarget(lua_State* state) {
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. lua_interface->ResetFunctionStack(state);
  755. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  756. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  757. return 1;
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Spawn* spawn = lua_interface->GetSpawn(state);
  765. string mp3_string = lua_interface->GetStringValue(state, 2);
  766. int32 key1 = lua_interface->GetInt32Value(state, 3);
  767. int32 key2 = lua_interface->GetInt32Value(state, 4);
  768. Spawn* player = lua_interface->GetSpawn(state, 5);
  769. lua_interface->ResetFunctionStack(state);
  770. if (spawn && mp3_string.length() > 0) {
  771. Client* client = 0;
  772. if (player && player->IsPlayer())
  773. client = ((Player*)player)->GetClient();
  774. if (client) {
  775. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  776. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  777. }
  778. else
  779. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  780. }
  781. return 0;
  782. }
  783. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  784. if (!lua_interface)
  785. return 0;
  786. Spawn* spawn = lua_interface->GetSpawn(state);
  787. lua_interface->ResetFunctionStack(state);
  788. if (spawn) {
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  790. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  791. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  792. return 3;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. lua_interface->ResetFunctionStack(state);
  803. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  804. return 1;
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* spawn = lua_interface->GetSpawn(state);
  813. if (spawn && spawn->IsEntity()) {
  814. int32 item_id = lua_interface->GetInt32Value(state, 2);
  815. int16 charges = lua_interface->GetInt16Value(state, 3);
  816. if (charges == 0)
  817. charges = 1;
  818. ((Entity*)spawn)->AddLootItem(item_id, charges);
  819. }
  820. lua_interface->ResetFunctionStack(state);
  821. return 0;
  822. }
  823. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Spawn* spawn = lua_interface->GetSpawn(state);
  827. if (spawn && spawn->IsEntity()) {
  828. int32 item_id = lua_interface->GetInt32Value(state, 2);
  829. Item* item = spawn->LootItem(item_id);
  830. lua_interface->SetLuaUserDataStale(item);
  831. safe_delete(item);
  832. }
  833. lua_interface->ResetFunctionStack(state);
  834. return 0;
  835. }
  836. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  837. if (!lua_interface)
  838. return 0;
  839. Spawn* spawn = lua_interface->GetSpawn(state);
  840. if (spawn) {
  841. int32 val = lua_interface->GetInt32Value(state, 2);
  842. spawn->AddLootCoins(val);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_GiveLoot(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. if (entity && player && player->IsPlayer()) {
  853. int32 coins = lua_interface->GetInt32Value(state, 3);
  854. vector<Item*>* items = 0;
  855. int i = 0;
  856. int32 item_id = 0;
  857. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  858. if (items == 0)
  859. items = new vector<Item*>;
  860. if (master_item_list.GetItem(item_id))
  861. items->push_back(master_item_list.GetItem(item_id));
  862. i++;
  863. }
  864. Client* client = 0;
  865. client = ((Player*)player)->GetClient();
  866. if (client)
  867. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  868. if(coins > 0)
  869. entity->AddLootCoins(coins);
  870. safe_delete(items);
  871. }
  872. lua_interface->ResetFunctionStack(state);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. Spawn* entity = lua_interface->GetSpawn(state);
  879. Spawn* player = lua_interface->GetSpawn(state, 2);
  880. int32 item_id = lua_interface->GetInt32Value(state, 3);
  881. lua_interface->ResetFunctionStack(state);
  882. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  883. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  889. if (!lua_interface)
  890. return 0;
  891. Spawn* entity = lua_interface->GetSpawn(state);
  892. Spawn* player = lua_interface->GetSpawn(state, 2);
  893. lua_interface->ResetFunctionStack(state);
  894. if (entity && player && player->IsPlayer()) {
  895. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. lua_interface->SetLuaUserDataStale(conversation);
  905. safe_delete(conversation);
  906. lua_interface->ResetFunctionStack(state);
  907. conversation = new vector<ConversationOption>();
  908. lua_interface->SetConversationValue(state, conversation);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  915. if (conversation) {
  916. ConversationOption conv_option;
  917. conv_option.option = lua_interface->GetStringValue(state, 2);
  918. conv_option.function = lua_interface->GetStringValue(state, 3);
  919. if (conv_option.option.length() > 0)
  920. conversation->push_back(conv_option);
  921. }
  922. lua_interface->ResetFunctionStack(state);
  923. return 0;
  924. }
  925. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  926. if (!lua_interface)
  927. return 0;
  928. Spawn* npc = lua_interface->GetSpawn(state);
  929. Spawn* player = lua_interface->GetSpawn(state, 2);
  930. lua_interface->ResetFunctionStack(state);
  931. if (npc && player && player->IsPlayer() && player->GetZone()) {
  932. Client* client = ((Player*)player)->GetClient();
  933. if (client) {
  934. int32 conversation_id = client->GetConversationID(npc, 0);
  935. client->CloseDialog(conversation_id);
  936. }
  937. }
  938. return 0;
  939. }
  940. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  941. if (!lua_interface)
  942. return 0;
  943. Item* item = lua_interface->GetItem(state);
  944. Spawn* player = lua_interface->GetSpawn(state, 2);
  945. lua_interface->ResetFunctionStack(state);
  946. if (item && player && player->IsPlayer() && player->GetZone()) {
  947. Client* client = ((Player*)player)->GetClient();
  948. if (client) {
  949. int32 conversation_id = client->GetConversationID(0, item);
  950. client->CloseDialog(conversation_id);
  951. }
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  959. Spawn* spawn = 0;
  960. Item* item = 0;
  961. int8 type = lua_interface->GetInt8Value(state, 2);
  962. if (type == 1 || type == 3)
  963. spawn = lua_interface->GetSpawn(state, 3);
  964. else if (type == 2 || type == 4)
  965. item = lua_interface->GetItem(state, 3);
  966. Spawn* player = lua_interface->GetSpawn(state, 4);
  967. string text = lua_interface->GetStringValue(state, 5);
  968. string mp3 = lua_interface->GetStringValue(state, 6);
  969. int32 key1 = lua_interface->GetInt32Value(state, 7);
  970. int32 key2 = lua_interface->GetInt32Value(state, 8);
  971. int8 language = lua_interface->GetInt8Value(state, 9);
  972. int numargs = lua_interface->GetNumberOfArgs(state);
  973. int8 can_close = 1;
  974. if(numargs > 9)
  975. can_close = lua_interface->GetInt32Value(state, 10);
  976. lua_interface->ResetFunctionStack(state);
  977. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  978. Client* client = ((Player*)player)->GetClient();
  979. if (client) {
  980. if (spawn) {
  981. // Need to do this so the function works the same as it did before
  982. if (type == 1)
  983. type++;
  984. if (mp3.length() > 0)
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  986. else
  987. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  988. }
  989. else {
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  994. }
  995. }
  996. }
  997. lua_interface->SetLuaUserDataStale(conversation);
  998. safe_delete(conversation);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1005. Spawn* source = lua_interface->GetSpawn(state, 2);
  1006. Spawn* player = lua_interface->GetSpawn(state, 3);
  1007. string text = lua_interface->GetStringValue(state, 4);
  1008. string mp3 = lua_interface->GetStringValue(state, 5);
  1009. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1010. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1011. int8 language = lua_interface->GetInt32Value(state, 8);
  1012. int numargs = lua_interface->GetNumberOfArgs(state);
  1013. int8 can_close = 1;
  1014. if(numargs > 8)
  1015. can_close = lua_interface->GetInt32Value(state, 9);
  1016. lua_interface->ResetFunctionStack(state);
  1017. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1018. Client* client = ((Player*)player)->GetClient();
  1019. if (mp3.length() > 0)
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1021. else
  1022. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1023. lua_interface->SetLuaUserDataStale(conversation);
  1024. safe_delete(conversation);
  1025. }
  1026. else
  1027. 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);
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. float distance = lua_interface->GetFloatValue(state, 2);
  1035. string in_range_function = lua_interface->GetStringValue(state, 3);
  1036. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1037. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1038. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1039. return 0;
  1040. }
  1041. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1042. ZoneServer* zone = lua_interface->GetZone(state);
  1043. float x = lua_interface->GetFloatValue(state, 2);
  1044. float y = lua_interface->GetFloatValue(state, 3);
  1045. float z = lua_interface->GetFloatValue(state, 4);
  1046. float max_variation = lua_interface->GetFloatValue(state, 5);
  1047. string in_range_function = lua_interface->GetStringValue(state, 6);
  1048. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1049. lua_interface->ResetFunctionStack(state);
  1050. if (zone && in_range_function.length() > 0)
  1051. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1052. return 0;
  1053. }
  1054. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1055. if (!lua_interface)
  1056. return 0;
  1057. Spawn* spawn = lua_interface->GetSpawn(state);
  1058. if (spawn && spawn->IsEntity()) {
  1059. int32 val = lua_interface->GetInt32Value(state, 2);
  1060. ((Entity*)spawn)->SetLootCoins(val);
  1061. }
  1062. lua_interface->ResetFunctionStack(state);
  1063. return 0;
  1064. }
  1065. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1066. if (!lua_interface)
  1067. return 0;
  1068. Spawn* spawn = lua_interface->GetSpawn(state);
  1069. lua_interface->ResetFunctionStack(state);
  1070. if (spawn && spawn->IsEntity()) {
  1071. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. float x = lua_interface->GetFloatValue(state, 2);
  1081. float y = lua_interface->GetFloatValue(state, 3);
  1082. float z = lua_interface->GetFloatValue(state, 4);
  1083. float speed = lua_interface->GetFloatValue(state, 5);
  1084. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1085. string function = lua_interface->GetStringValue(state, 7);
  1086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1087. float heading = lua_interface->GetFloatValue(state, 8);
  1088. if (spawn) {
  1089. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1090. spawn->GetZone()->AddMovementNPC(spawn);
  1091. }
  1092. lua_interface->ResetFunctionStack(state);
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. Spawn* spawn = lua_interface->GetSpawn(state);
  1099. lua_interface->ResetFunctionStack(state);
  1100. if (spawn) {
  1101. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. lua_interface->ResetFunctionStack(state);
  1111. if (spawn && spawn->IsPlayer()) {
  1112. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1113. return 1;
  1114. }
  1115. lua_interface->SetInt32Value(state, 0);
  1116. return 1;
  1117. }
  1118. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. Spawn* target = lua_interface->GetSpawn(state, 2);
  1123. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1124. bool reset_action_state = true;
  1125. if(num_args > 2)
  1126. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1127. if (spawn && target) {
  1128. if (spawn->IsEntity())
  1129. // ((Entity*)spawn)->FaceTarget(target);
  1130. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1131. }
  1132. lua_interface->ResetFunctionStack(state);
  1133. return 0;
  1134. }
  1135. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1136. if (!lua_interface)
  1137. return 0;
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. float x = lua_interface->GetFloatValue(state, 2);
  1140. float y = lua_interface->GetFloatValue(state, 3);
  1141. float z = lua_interface->GetFloatValue(state, 4);
  1142. float speed = lua_interface->GetFloatValue(state, 5);
  1143. string lua_function = lua_interface->GetStringValue(state, 6);
  1144. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1145. if (spawn) {
  1146. if (speed == 0)
  1147. speed = spawn->GetSpeed();
  1148. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. lua_interface->ResetFunctionStack(state);
  1158. if (spawn) {
  1159. spawn->ClearRunningLocations();
  1160. }
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_Say(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. Spawn* spawn = lua_interface->GetSpawn(state);
  1167. string message = lua_interface->GetStringValue(state, 2);
  1168. Spawn* player = lua_interface->GetSpawn(state, 3);
  1169. float dist = lua_interface->GetFloatValue(state, 4);
  1170. int32 language = lua_interface->GetInt32Value(state, 5);
  1171. if (spawn && message.length() > 0) {
  1172. Client* client = 0;
  1173. if (player && player->IsPlayer())
  1174. client = ((Player*)player)->GetClient();
  1175. if (client)
  1176. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. else
  1178. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1179. }
  1180. lua_interface->ResetFunctionStack(state);
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_Shout(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. string message = lua_interface->GetStringValue(state, 2);
  1188. Spawn* player = lua_interface->GetSpawn(state, 3);
  1189. float dist = lua_interface->GetFloatValue(state, 4);
  1190. int32 language = lua_interface->GetInt32Value(state, 5);
  1191. if (spawn && message.length() > 0) {
  1192. Client* client = 0;
  1193. if (player && player->IsPlayer())
  1194. client = ((Player*)player)->GetClient();
  1195. if (client)
  1196. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. else
  1198. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1199. }
  1200. lua_interface->ResetFunctionStack(state);
  1201. return 0;
  1202. }
  1203. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1204. if (!lua_interface)
  1205. return 0;
  1206. Spawn* spawn = lua_interface->GetSpawn(state);
  1207. string message = lua_interface->GetStringValue(state, 2);
  1208. Spawn* player = lua_interface->GetSpawn(state, 3);
  1209. float dist = lua_interface->GetFloatValue(state, 4);
  1210. int32 language = lua_interface->GetInt32Value(state, 5);
  1211. if (spawn && message.length() > 0) {
  1212. Client* client = 0;
  1213. if (player && player->IsPlayer())
  1214. client = ((Player*)player)->GetClient();
  1215. if (client)
  1216. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. else
  1218. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1219. }
  1220. lua_interface->ResetFunctionStack(state);
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_Emote(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. string message = lua_interface->GetStringValue(state, 2);
  1228. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1229. Spawn* player = lua_interface->GetSpawn(state, 4);
  1230. char* to = 0;
  1231. if (spawn2)
  1232. to = spawn2->GetName();
  1233. if (spawn && message.length() > 0) {
  1234. Client* client = 0;
  1235. if (player && player->IsPlayer())
  1236. client = ((Player*)player)->GetClient();
  1237. if (client)
  1238. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. else
  1240. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1241. }
  1242. lua_interface->ResetFunctionStack(state);
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if(!luaspell || luaspell->resisted) {
  1250. lua_interface->ResetFunctionStack(state);
  1251. return 0;
  1252. }
  1253. Spawn* caster = luaspell->caster;
  1254. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1255. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1256. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1257. Spawn* target = lua_interface->GetSpawn(state, 4);
  1258. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1259. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1260. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1261. lua_interface->ResetFunctionStack(state);
  1262. boost::to_lower(heal_type);
  1263. if (caster && caster->IsEntity()) {
  1264. bool success = false;
  1265. luaspell->resisted = false;
  1266. if (target) {
  1267. float distance = caster->GetDistance(target, true);
  1268. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1269. success = true;
  1270. }
  1271. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1272. Spawn* target = 0;
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1277. float distance = caster->GetDistance(target, true);
  1278. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1279. }
  1280. }
  1281. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1282. success = true;
  1283. }
  1284. if (success) {
  1285. if (caster->GetZone())
  1286. caster->GetZone()->TriggerCharSheetTimer();
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1295. if(!luaspell || luaspell->resisted) {
  1296. lua_interface->ResetFunctionStack(state);
  1297. return 0;
  1298. }
  1299. Spawn* caster = luaspell->caster;
  1300. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1301. float percentage = lua_interface->GetFloatValue(state, 2);
  1302. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1303. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1304. Spawn* target = lua_interface->GetSpawn(state, 5);
  1305. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1306. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1307. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1308. lua_interface->ResetFunctionStack(state);
  1309. boost::to_lower(heal_type);
  1310. int32 min_heal = 0, max_heal = 0;
  1311. if (caster && caster->IsEntity() && target) {
  1312. if(percentage <= 0.0f)
  1313. {
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1315. return 0;
  1316. }
  1317. if(heal_type == "power")
  1318. {
  1319. if(current_value)
  1320. {
  1321. if(caster_value)
  1322. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1323. else
  1324. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1325. }
  1326. else
  1327. {
  1328. if(caster_value)
  1329. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1330. else
  1331. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if(current_value)
  1337. {
  1338. if(caster_value)
  1339. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1340. else
  1341. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1342. }
  1343. else
  1344. {
  1345. if(caster_value)
  1346. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1347. else
  1348. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1349. }
  1350. }
  1351. bool success = false;
  1352. luaspell->resisted = false;
  1353. if (target) {
  1354. float distance = caster->GetDistance(target, true);
  1355. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1356. success = true;
  1357. }
  1358. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1359. Spawn* target = 0;
  1360. ZoneServer* zone = luaspell->caster->GetZone();
  1361. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1362. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1363. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1364. float distance = caster->GetDistance(target, true);
  1365. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1366. }
  1367. }
  1368. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1369. success = true;
  1370. }
  1371. if (success) {
  1372. if (caster->GetZone())
  1373. caster->GetZone()->TriggerCharSheetTimer();
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_AddItem(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1383. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1384. lua_interface->ResetFunctionStack(state);
  1385. // default of 1 quantity to add
  1386. if (quantity == 0)
  1387. quantity = 1;
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = ((Player*)spawn)->GetClient();
  1390. if (client && item_id > 0) {
  1391. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1392. return 1;
  1393. }
  1394. }
  1395. lua_interface->SetBooleanValue(state, false);
  1396. return 1;
  1397. }
  1398. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1399. if (!lua_interface)
  1400. return 0;
  1401. Spawn* spawn = lua_interface->GetSpawn(state);
  1402. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1403. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1404. string location = lua_interface->GetStringValue(state, 4);
  1405. int16 item_count = lua_interface->GetInt16Value(state,5);
  1406. //devn00b: if we dont have a count, assume 1 item.
  1407. if(!item_count) {
  1408. item_count = 1;
  1409. }
  1410. lua_interface->ResetFunctionStack(state);
  1411. if (spawn && spawn->IsPlayer()) {
  1412. Client* client = ((Player*)spawn)->GetClient();
  1413. if (client && item_id > 0) {
  1414. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1415. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1416. else
  1417. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1418. if (send_messages) {
  1419. Item* item = master_item_list.GetItem(item_id);
  1420. if (item) {
  1421. if(item_count > 1) {
  1422. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1423. string popup_text1 = "You receive "+ item_count;
  1424. string popup_text2 = " " + item->name;
  1425. string popup_text = popup_text1 + popup_text2;
  1426. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1427. // return 1;
  1428. } else {
  1429. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1430. string popup_text = "You receive " + item->name;
  1431. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1432. }
  1433. }
  1434. }
  1435. return 1;
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1442. Spawn* spawn = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. // default of 1 to remove
  1447. if (quantity == 0)
  1448. quantity = 1;
  1449. Client* client;
  1450. Item* item;
  1451. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1452. if ((client = ((Player*)spawn)->GetClient())) {
  1453. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1454. if (client->RemoveItem(item, quantity)) {
  1455. lua_interface->SetBooleanValue(state, true);
  1456. return 1;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. lua_interface->SetBooleanValue(state, false);
  1462. return 1;
  1463. }
  1464. int EQ2Emu_lua_HasItem(lua_State* state) {
  1465. Spawn* player = lua_interface->GetSpawn(state);
  1466. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1467. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (player && player->IsPlayer()) {
  1470. bool hasItem = false;
  1471. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1472. if (!hasItem)
  1473. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1474. lua_interface->SetBooleanValue(state, hasItem);
  1475. return 1;
  1476. }
  1477. lua_interface->SetBooleanValue(state, false);
  1478. return 1;
  1479. }
  1480. int EQ2Emu_lua_Spawn(lua_State* state) {
  1481. if (!lua_interface)
  1482. return 0;
  1483. ZoneServer* zone = lua_interface->GetZone(state);
  1484. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1485. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1486. float x = lua_interface->GetFloatValue(state, 4);
  1487. float y = lua_interface->GetFloatValue(state, 5);
  1488. float z = lua_interface->GetFloatValue(state, 6);
  1489. float heading = lua_interface->GetFloatValue(state, 7);
  1490. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1491. Spawn* spawn = zone->GetSpawn(spawn_id);
  1492. if (!spawn)
  1493. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1494. else {
  1495. spawn->SetX(x);
  1496. spawn->SetZ(z);
  1497. spawn->SetY(y,true,true);
  1498. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1499. spawn->SetHeading(heading);
  1500. if (restricted_npc)
  1501. spawn->AddAllowAccessSpawn(spawn);
  1502. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1503. bool scriptActive = false;
  1504. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1505. scriptActive = true;
  1506. spawn->SetSpawnScript(string(spawn_script));
  1507. }
  1508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1509. zone->AddSpawn(spawn);
  1510. if (scriptActive) {
  1511. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1512. }
  1513. lua_interface->ResetFunctionStack(state);
  1514. lua_interface->SetSpawnValue(state, spawn);
  1515. return 1;
  1516. }
  1517. }
  1518. else {
  1519. string output = "Invalid paramaters to LUA Spawn command: \n";
  1520. if (!zone)
  1521. output = output.append("\t").append("Missing zone reference. \n");
  1522. if (spawn_id == 0)
  1523. output = output.append("\t").append("Missing spawn_id.");
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1525. }
  1526. lua_interface->ResetFunctionStack(state);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. ZoneServer* zone = lua_interface->GetZone(state);
  1533. lua_interface->ResetFunctionStack(state);
  1534. if (zone) {
  1535. lua_interface->SetStringValue(state, zone->GetZoneName());
  1536. return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1541. if (!lua_interface)
  1542. return 0;
  1543. ZoneServer* zone = lua_interface->GetZone(state);
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_GetZone(lua_State* state) {
  1552. if (!lua_interface)
  1553. return 0;
  1554. int32 zone_id = lua_interface->GetInt32Value(state);
  1555. ZoneChangeDetails zone_details;
  1556. std::string zone_name;
  1557. ZoneServer* zone = nullptr;
  1558. if(zone_id < 1) {
  1559. zone_name = lua_interface->GetStringValue(state);
  1560. }
  1561. bool zone_avail = zone_list.GetZone(&zone_details, zone_id, zone_name, true, false, false, false);
  1562. if (zone_avail) {
  1563. zone = (ZoneServer*)zone_details.zonePtr;
  1564. }
  1565. else {
  1566. Spawn* spawn = lua_interface->GetSpawn(state);
  1567. if (spawn)
  1568. zone = spawn->GetZone();
  1569. }
  1570. lua_interface->ResetFunctionStack(state);
  1571. if (zone) {
  1572. lua_interface->SetZoneValue(state, zone);
  1573. return 1;
  1574. }
  1575. return 0;
  1576. }
  1577. int EQ2Emu_lua_AddHate(lua_State* state) {
  1578. Spawn* entity = lua_interface->GetSpawn(state);
  1579. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1580. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1581. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1582. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1583. lua_interface->ResetFunctionStack(state);
  1584. if(luaspell && luaspell->resisted) {
  1585. return 0;
  1586. }
  1587. if (entity && entity->IsEntity() && amount != 0) {
  1588. if (luaspell && luaspell->caster) {
  1589. ZoneServer* zone = luaspell->caster->GetZone();
  1590. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1591. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1592. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1593. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1594. entity->CheckEncounterState((Entity*)spawn);
  1595. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1596. if (send_packet)
  1597. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1598. }
  1599. }
  1600. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1601. }
  1602. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1603. entity->CheckEncounterState((Entity*)npc);
  1604. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1605. }
  1606. }
  1607. lua_interface->ResetFunctionStack(state);
  1608. return 0;
  1609. }
  1610. int EQ2Emu_lua_Zone(lua_State* state) {
  1611. if (!lua_interface)
  1612. return 0;
  1613. ZoneServer* zone = lua_interface->GetZone(state);
  1614. Spawn* player = lua_interface->GetSpawn(state, 2);
  1615. Client* client = 0;
  1616. if (player && player->IsPlayer())
  1617. client = ((Player*)player)->GetClient();
  1618. float x = lua_interface->GetFloatValue(state, 3);
  1619. float y = lua_interface->GetFloatValue(state, 4);
  1620. float z = lua_interface->GetFloatValue(state, 5);
  1621. float heading = lua_interface->GetFloatValue(state, 6);
  1622. lua_interface->ResetFunctionStack(state);
  1623. if (zone && client) {
  1624. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1625. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1626. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1627. {
  1628. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1629. return 0;
  1630. }
  1631. if (x != 0 || y != 0 || z != 0) {
  1632. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1633. player->SetX(x);
  1634. player->SetY(y);
  1635. player->SetZ(z);
  1636. player->SetHeading(heading);
  1637. client->Zone(zone->GetZoneName(), false);
  1638. }
  1639. else
  1640. client->Zone(zone->GetZoneName());
  1641. }
  1642. else
  1643. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* spawn = lua_interface->GetSpawn(state);
  1650. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1651. lua_interface->ResetFunctionStack(state);
  1652. if (spawn && spawn2)
  1653. spawn->AddAllowAccessSpawn(spawn2);
  1654. lua_interface->ResetFunctionStack(state);
  1655. return 0;
  1656. }
  1657. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1658. if (!lua_interface)
  1659. return 0;
  1660. Spawn* target = lua_interface->GetSpawn(state);
  1661. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1662. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1663. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1664. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1665. lua_interface->ResetFunctionStack(state);
  1666. if (!target) {
  1667. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1668. return 0;
  1669. }
  1670. if (!target->IsEntity()) {
  1671. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1672. return 0;
  1673. }
  1674. if (spell_id <= 0) {
  1675. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1676. return 0;
  1677. }
  1678. if (caster && !caster->IsEntity()) {
  1679. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1680. return 0;
  1681. }
  1682. if (spell_tier == 0)
  1683. spell_tier = 1;
  1684. if (!caster)
  1685. caster = target;
  1686. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1687. return 0;
  1688. }
  1689. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1690. if (!lua_interface)
  1691. return 0;
  1692. Spawn* target = lua_interface->GetSpawn(state);
  1693. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1694. if(!luaspell || luaspell->resisted) {
  1695. lua_interface->ResetFunctionStack(state);
  1696. lua_interface->SetBooleanValue(state, false);
  1697. return 1;
  1698. }
  1699. Spawn* caster = luaspell->caster;
  1700. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1701. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1702. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1703. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1704. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1705. //lua_interface->ResetFunctionStack(state);
  1706. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1707. vector<int16> faction_req;
  1708. vector<int16> race_req;
  1709. int32 class_req = 0;
  1710. int32 i = 0;
  1711. int8 f = 0;
  1712. int8 r = 0;
  1713. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1714. if (class_id < 100) {
  1715. class_req += pow(2.0, double(class_id - 1));
  1716. }
  1717. else if (class_id > 100 && class_id < 1000) {
  1718. race_req.push_back(class_id);
  1719. r++;
  1720. }
  1721. else {
  1722. faction_req.push_back(class_id);
  1723. f++;
  1724. }
  1725. i++;
  1726. }
  1727. lua_interface->ResetFunctionStack(state);
  1728. if (caster && caster->IsEntity()) {
  1729. bool race_match = false;
  1730. bool success = false;
  1731. luaspell->resisted = false;
  1732. if (luaspell->targets.size() > 0) {
  1733. ZoneServer* zone = luaspell->caster->GetZone();
  1734. Spawn* target = 0;
  1735. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1736. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1737. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1738. if (race_req.size() > 0) {
  1739. for (int8 i = 0; i < race_req.size(); i++) {
  1740. if(race_req[i] == target->GetRace() ||
  1741. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1742. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1743. race_match = true;
  1744. }
  1745. }
  1746. }
  1747. else
  1748. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1749. if (race_match == true) {
  1750. float distance = caster->GetDistance(target, true);
  1751. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1752. }
  1753. }
  1754. }
  1755. success = true;
  1756. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1757. }
  1758. else if (target) {
  1759. //check class and race/faction here
  1760. if (race_req.size() > 0) {
  1761. for (int8 i = 0; i < race_req.size(); i++) {
  1762. if(race_req[i] == target->GetRace() ||
  1763. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1764. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1765. race_match = true;
  1766. }
  1767. }
  1768. }
  1769. else
  1770. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1771. if (race_match == true) {
  1772. float distance = caster->GetDistance(target, true);
  1773. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1774. success = true;
  1775. }
  1776. }
  1777. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1778. if (success) {
  1779. Spell* spell = luaspell->spell;
  1780. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1781. ((Player*)caster)->InCombat(true);
  1782. if (caster->GetZone())
  1783. caster->GetZone()->TriggerCharSheetTimer();
  1784. }
  1785. }
  1786. }
  1787. else {
  1788. lua_interface->SetBooleanValue(state, false);
  1789. }
  1790. return 1;
  1791. }
  1792. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1793. if (!lua_interface)
  1794. return 0;
  1795. Spawn* target = lua_interface->GetSpawn(state);
  1796. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1797. if(!luaspell || luaspell->resisted) {
  1798. lua_interface->ResetFunctionStack(state);
  1799. lua_interface->SetBooleanValue(state, false);
  1800. return 1;
  1801. }
  1802. Spawn* caster = luaspell->caster;
  1803. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1804. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1805. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1806. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1807. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1808. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1809. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1810. //lua_interface->ResetFunctionStack(state);
  1811. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1812. vector<int16> faction_req;
  1813. vector<int16> race_req;
  1814. int32 class_req = 0;
  1815. int32 i = 0;
  1816. int8 f = 0;
  1817. int8 r = 0;
  1818. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1819. if (class_id < 100) {
  1820. class_req += pow(2.0, double(class_id - 1));
  1821. }
  1822. else if (class_id > 100 && class_id < 1000) {
  1823. race_req.push_back(class_id);
  1824. r++;
  1825. }
  1826. else {
  1827. faction_req.push_back(class_id);
  1828. f++;
  1829. }
  1830. i++;
  1831. }
  1832. lua_interface->ResetFunctionStack(state);
  1833. if (caster && caster->IsEntity()) {
  1834. bool race_match = false;
  1835. bool success = false;
  1836. luaspell->resisted = false;
  1837. if (luaspell->targets.size() > 0) {
  1838. ZoneServer* zone = luaspell->caster->GetZone();
  1839. Spawn* target = 0;
  1840. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1841. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1842. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1843. if (race_req.size() > 0) {
  1844. for (int8 i = 0; i < race_req.size(); i++) {
  1845. if(race_req[i] == target->GetRace() ||
  1846. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1847. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1848. race_match = true;
  1849. }
  1850. }
  1851. }
  1852. else
  1853. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1854. if (race_match == true) {
  1855. float distance = caster->GetDistance(target, true);
  1856. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1857. }
  1858. }
  1859. }
  1860. success = true;
  1861. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1862. }
  1863. else if (target) {
  1864. //check class and race/faction here
  1865. if (race_req.size() > 0) {
  1866. for (int8 i = 0; i < race_req.size(); i++) {
  1867. if(race_req[i] == target->GetRace() ||
  1868. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1869. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1870. race_match = true;
  1871. }
  1872. }
  1873. }
  1874. else
  1875. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1876. if (race_match == true) {
  1877. float distance = caster->GetDistance(target, true);
  1878. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1879. success = true;
  1880. }
  1881. }
  1882. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1883. if (success) {
  1884. Spell* spell = luaspell->spell;
  1885. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1886. ((Player*)caster)->InCombat(true);
  1887. if (caster->GetZone())
  1888. caster->GetZone()->TriggerCharSheetTimer();
  1889. }
  1890. }
  1891. }
  1892. else {
  1893. lua_interface->SetBooleanValue(state, false);
  1894. }
  1895. return 1;
  1896. }
  1897. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1898. if (!lua_interface)
  1899. return 0;
  1900. Spawn* spawn = lua_interface->GetSpawn(state);
  1901. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1902. lua_interface->ResetFunctionStack(state);
  1903. if (spawn && value != 0) {
  1904. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1905. spawn->SetPower(spawn->GetTotalPower());
  1906. else
  1907. spawn->SetPower(spawn->GetPower() + value);
  1908. }
  1909. return 0;
  1910. }
  1911. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1912. if (!lua_interface)
  1913. return 0;
  1914. Spawn* spawn = lua_interface->GetSpawn(state);
  1915. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1916. lua_interface->ResetFunctionStack(state);
  1917. if (spawn && value != 0) {
  1918. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1919. spawn->SetHP(spawn->GetTotalHP());
  1920. else
  1921. spawn->SetHP(spawn->GetHP() + value);
  1922. }
  1923. return 0;
  1924. }
  1925. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1926. if (!lua_interface)
  1927. return 0;
  1928. Spawn* spawn = lua_interface->GetSpawn(state);
  1929. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1930. lua_interface->ResetFunctionStack(state);
  1931. if (spawn && value != 0) {
  1932. spawn->SetTotalPower(value);
  1933. spawn->SetTotalPowerBaseInstance(value);
  1934. }
  1935. return 0;
  1936. }
  1937. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1938. if (!lua_interface)
  1939. return 0;
  1940. Spawn* spawn = lua_interface->GetSpawn(state);
  1941. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1942. lua_interface->ResetFunctionStack(state);
  1943. if (spawn && value != 0) {
  1944. spawn->SetTotalHP(value);
  1945. spawn->SetTotalHPBaseInstance(value);
  1946. }
  1947. return 0;
  1948. }
  1949. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1950. if (!lua_interface)
  1951. return 0;
  1952. Spawn* spawn = lua_interface->GetSpawn(state);
  1953. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1954. lua_interface->ResetFunctionStack(state);
  1955. if (spawn) {
  1956. spawn->SetHP(value);
  1957. if (value > spawn->GetTotalHPBase())
  1958. spawn->SetTotalHP(value);
  1959. }
  1960. return 0;
  1961. }
  1962. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1963. if (!lua_interface)
  1964. return 0;
  1965. Spawn* spawn = lua_interface->GetSpawn(state);
  1966. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1967. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1968. lua_interface->ResetFunctionStack(state);
  1969. if (spawn && spawn->IsEntity() && value > 0)
  1970. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1971. if (spawn && spawn->IsPlayer())
  1972. ((Player*)spawn)->SetCharSheetChanged(true);
  1973. return 0;
  1974. }
  1975. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1976. if (!lua_interface)
  1977. return 0;
  1978. Spawn* spawn = lua_interface->GetSpawn(state);
  1979. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1980. lua_interface->ResetFunctionStack(state);
  1981. if (spawn && spawn->IsEntity() && value > 0)
  1982. ((Entity*)spawn)->SetTotalHPBase(value);
  1983. return 0;
  1984. }
  1985. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1986. if (!lua_interface)
  1987. return 0;
  1988. Spawn* spawn = lua_interface->GetSpawn(state);
  1989. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1990. lua_interface->ResetFunctionStack(state);
  1991. if (spawn && value > 0) {
  1992. spawn->SetPower(value);
  1993. if (value > spawn->GetTotalPowerBase())
  1994. spawn->SetTotalPower(value);
  1995. }
  1996. return 0;
  1997. }
  1998. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1999. if (!lua_interface)
  2000. return 0;
  2001. Spawn* spawn = lua_interface->GetSpawn(state);
  2002. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2003. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2004. lua_interface->ResetFunctionStack(state);
  2005. if (spawn && spawn->IsEntity() && value > 0)
  2006. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2007. return 0;
  2008. }
  2009. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2010. if (!lua_interface)
  2011. return 0;
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2014. lua_interface->ResetFunctionStack(state);
  2015. if (spawn && spawn->IsEntity() && value > 0)
  2016. ((Entity*)spawn)->SetTotalPowerBase(value);
  2017. return 0;
  2018. }
  2019. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2020. if (!lua_interface)
  2021. return 0;
  2022. Spawn* spawn = lua_interface->GetSpawn(state);
  2023. float x = lua_interface->GetFloatValue(state, 2);
  2024. float y = lua_interface->GetFloatValue(state, 3);
  2025. float z = lua_interface->GetFloatValue(state, 4);
  2026. float heading = lua_interface->GetFloatValue(state, 5);
  2027. lua_interface->ResetFunctionStack(state);
  2028. if (spawn) {
  2029. spawn->SetX(x);
  2030. spawn->SetY(y);
  2031. spawn->SetZ(z);
  2032. if (heading != 0)
  2033. spawn->SetHeading(heading);
  2034. spawn->SetSpawnOrigX(spawn->GetX());
  2035. spawn->SetSpawnOrigY(spawn->GetY());
  2036. spawn->SetSpawnOrigZ(spawn->GetZ());
  2037. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2038. if (spawn->IsPlayer()) {
  2039. Client* client = ((Player*)spawn)->GetClient();
  2040. if (client) {
  2041. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2042. client->QueuePacket(packet);
  2043. }
  2044. }
  2045. }
  2046. return 0;
  2047. }
  2048. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2049. if (!lua_interface)
  2050. return 0;
  2051. Spawn* spawn = lua_interface->GetSpawn(state);
  2052. float value = lua_interface->GetFloatValue(state, 2);
  2053. lua_interface->ResetFunctionStack(state);
  2054. if (spawn) {
  2055. spawn->SetHeading(value);
  2056. if (spawn->IsPlayer()) {
  2057. Client* client = ((Player*)spawn)->GetClient();
  2058. if (client) {
  2059. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2060. client->QueuePacket(packet);
  2061. }
  2062. }
  2063. }
  2064. return 0;
  2065. }
  2066. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2067. if (!lua_interface)
  2068. return 0;
  2069. Spawn* spawn = lua_interface->GetSpawn(state);
  2070. int16 value = lua_interface->GetInt16Value(state, 2);
  2071. lua_interface->ResetFunctionStack(state);
  2072. if (spawn)
  2073. spawn->SetModelType(value);
  2074. return 0;
  2075. }
  2076. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2077. if (!lua_interface)
  2078. return 0;
  2079. Spawn* spawn = lua_interface->GetSpawn(state);
  2080. int8 value = lua_interface->GetInt8Value(state, 2);
  2081. lua_interface->ResetFunctionStack(state);
  2082. if (spawn) {
  2083. if (spawn->IsPlayer())
  2084. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2085. else
  2086. spawn->SetAdventureClass(value);
  2087. }
  2088. return 0;
  2089. }
  2090. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2091. if (!lua_interface)
  2092. return 0;
  2093. Spawn* spawn = lua_interface->GetSpawn(state);
  2094. int8 value = lua_interface->GetInt8Value(state, 2);
  2095. lua_interface->ResetFunctionStack(state);
  2096. if (spawn) {
  2097. spawn->SetTradeskillClass(value);
  2098. if (spawn->IsEntity()) {
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2100. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2101. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2102. }
  2103. if (spawn->IsPlayer())
  2104. ((Player*)spawn)->SetCharSheetChanged(true);
  2105. }
  2106. return 0;
  2107. }
  2108. int EQ2Emu_lua_SetMount(lua_State* state) {
  2109. if (!lua_interface)
  2110. return 0;
  2111. Spawn* spawn = lua_interface->GetSpawn(state);
  2112. int16 value = lua_interface->GetInt16Value(state, 2);
  2113. lua_interface->ResetFunctionStack(state);
  2114. if (spawn && spawn->IsEntity()) {
  2115. ((Entity*)spawn)->SetMount(value);
  2116. EQ2_Color color;
  2117. color.red = 255;
  2118. color.green = 255;
  2119. color.blue = 255;
  2120. ((Entity*)spawn)->SetMountColor(&color);
  2121. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2122. }
  2123. return 0;
  2124. }
  2125. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2126. if (!lua_interface)
  2127. return 0;
  2128. Spawn* spawn = lua_interface->GetSpawn(state);
  2129. EQ2_Color mount_color;
  2130. EQ2_Color saddle_color;
  2131. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2132. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2133. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2134. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2135. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2136. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2137. lua_interface->ResetFunctionStack(state);
  2138. if (spawn && spawn->IsEntity()) {
  2139. ((Entity*)spawn)->SetMountColor(&mount_color);
  2140. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2141. }
  2142. return 0;
  2143. }
  2144. int EQ2Emu_lua_GetMount(lua_State* state) {
  2145. if (!lua_interface)
  2146. return 0;
  2147. Spawn* spawn = lua_interface->GetSpawn(state);
  2148. lua_interface->ResetFunctionStack(state);
  2149. if (spawn && spawn->IsEntity()) {
  2150. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2151. return 1;
  2152. }
  2153. return 0;
  2154. }
  2155. int EQ2Emu_lua_GetRace(lua_State* state) {
  2156. if (!lua_interface)
  2157. return 0;
  2158. Spawn* spawn = lua_interface->GetSpawn(state);
  2159. lua_interface->ResetFunctionStack(state);
  2160. if (spawn)
  2161. {
  2162. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2163. lua_interface->SetInt32Value(state, spawn->GetRace());
  2164. return 1;
  2165. }
  2166. return 0;
  2167. }
  2168. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2169. if (!lua_interface)
  2170. return 0;
  2171. Spawn* spawn = lua_interface->GetSpawn(state);
  2172. lua_interface->ResetFunctionStack(state);
  2173. if (spawn) {
  2174. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2175. return 1;
  2176. }
  2177. return 0;
  2178. }
  2179. int EQ2Emu_lua_GetClass(lua_State* state) {
  2180. Spawn* spawn = lua_interface->GetSpawn(state);
  2181. lua_interface->ResetFunctionStack(state);
  2182. if (spawn) {
  2183. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2189. Spawn* spawn = lua_interface->GetSpawn(state);
  2190. lua_interface->ResetFunctionStack(state);
  2191. if (spawn) {
  2192. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2193. return 1;
  2194. }
  2195. return 0;
  2196. }
  2197. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2198. if (!lua_interface)
  2199. return 0;
  2200. Spawn* spawn = lua_interface->GetSpawn(state);
  2201. float value = lua_interface->GetFloatValue(state, 2);
  2202. lua_interface->ResetFunctionStack(state);
  2203. if (spawn) {
  2204. spawn->SetSpeed(value);
  2205. if(spawn->IsEntity())
  2206. ((Entity*)spawn)->SetSpeed(value);
  2207. if (spawn->IsPlayer()) {
  2208. Client* client = ((Player*)spawn)->GetClient();
  2209. if (client) {
  2210. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2211. if (packet) {
  2212. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2213. packet->setDataByName("speed", value);
  2214. packet->setDataByName("size", 0.51);
  2215. EQ2Packet* app = packet->serialize();
  2216. client->QueuePacket(app);
  2217. safe_delete(packet);
  2218. }
  2219. }
  2220. }
  2221. }
  2222. return 0;
  2223. }
  2224. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2225. if (!lua_interface)
  2226. return 0;
  2227. Spawn* spawn = lua_interface->GetSpawn(state);
  2228. const int16 type = lua_interface->GetInt16Value(state, 2);
  2229. const float value = lua_interface->GetFloatValue(state, 3);
  2230. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2231. lua_interface->ResetFunctionStack(state);
  2232. if(!luaspell || luaspell->resisted) {
  2233. return 0;
  2234. }
  2235. int64 class_req = 0;
  2236. int32 class_id = 0;
  2237. vector<int16> faction_req;
  2238. vector<int16> race_req;
  2239. int32 i = 0;
  2240. int8 f = 0;
  2241. int8 r = 0;
  2242. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2243. if (class_id < 100) {
  2244. class_req += pow(2.0, double(class_id - 1));
  2245. }
  2246. else if (class_id > 100 && class_id < 1000) {
  2247. race_req.push_back(class_id);
  2248. r++;
  2249. }
  2250. else {
  2251. faction_req.push_back(class_id);
  2252. f++;
  2253. }
  2254. i++;
  2255. }
  2256. if (value != 0 && type >= 0) {
  2257. if (luaspell && luaspell->spell && luaspell->caster) {
  2258. ZoneServer* zone = luaspell->caster->GetZone();
  2259. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2260. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2261. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2262. if (target) {
  2263. if (target->IsPlayer()) {
  2264. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2265. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2266. if (((Player*)target)->GetGroupMemberInfo())
  2267. ((Player*)target)->UpdateGroupMemberInfo();
  2268. ((Player*)target)->SetCharSheetChanged(true);
  2269. }
  2270. else if (target->IsNPC())
  2271. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2272. else
  2273. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2274. }
  2275. }
  2276. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2277. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2278. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2279. }
  2280. else if (spawn && spawn->IsEntity()) {
  2281. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2282. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2283. if (spawn->IsPlayer())
  2284. ((Player*)spawn)->SetCharSheetChanged(true);
  2285. }
  2286. else
  2287. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2288. }
  2289. else
  2290. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2291. return 0;
  2292. }
  2293. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2294. if (!lua_interface)
  2295. return 0;
  2296. Spawn* spawn = lua_interface->GetSpawn(state);
  2297. int16 type = lua_interface->GetInt16Value(state, 2);
  2298. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2299. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2300. lua_interface->ResetFunctionStack(state);
  2301. if (!spawn) {
  2302. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2303. return 0;
  2304. }
  2305. if (!spawn->IsEntity()) {
  2306. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2307. return 0;
  2308. }
  2309. if (value == 0) {
  2310. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2311. return 0;
  2312. }
  2313. if (!luaspell || !luaspell->spell) {
  2314. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2315. return 0;
  2316. }
  2317. if(luaspell->resisted) {
  2318. return 0;
  2319. }
  2320. int32 class_req = 0;
  2321. vector<int16> faction_req;
  2322. vector<int16> race_req;
  2323. int32 class_id = 0;
  2324. int32 i = 0;
  2325. int8 f = 0;
  2326. int8 r = 0;
  2327. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2328. if (class_id < 100) {
  2329. class_req += pow(2.0, double(class_id - 1));
  2330. }
  2331. else if (class_id > 100 && class_id < 1000) {
  2332. race_req.push_back(class_id);
  2333. r++;
  2334. }
  2335. else {
  2336. faction_req.push_back(class_id);
  2337. f++;
  2338. }
  2339. i++;
  2340. }
  2341. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2342. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2343. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2344. if (spawn->IsPlayer())
  2345. ((Player*)spawn)->SetCharSheetChanged(true);
  2346. return 0;
  2347. }
  2348. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2349. if (!lua_interface)
  2350. return 0;
  2351. Spawn* spawn = lua_interface->GetSpawn(state);
  2352. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2353. if (!spawn) {
  2354. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2355. return 0;
  2356. }
  2357. if (!spawn->IsEntity()) {
  2358. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2359. return 0;
  2360. }
  2361. if (!luaspell || !luaspell->spell) {
  2362. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2363. return 0;
  2364. }
  2365. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2366. if (spawn->IsPlayer())
  2367. ((Player*)spawn)->SetCharSheetChanged(true);
  2368. return 0;
  2369. }
  2370. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2371. if (!lua_interface)
  2372. return 0;
  2373. Spawn* spawn = lua_interface->GetSpawn(state);
  2374. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2375. lua_interface->ResetFunctionStack(state);
  2376. if (luaspell && luaspell->spell) {
  2377. ZoneServer* zone = nullptr;
  2378. if (luaspell->caster != nullptr)
  2379. zone = luaspell->caster->GetZone();
  2380. if(!zone && spawn) {
  2381. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2382. }
  2383. Spawn* target = 0;
  2384. if(zone) {
  2385. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2386. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2387. target = zone->GetSpawnByID(luaspell->targets[i]);
  2388. if (target && target->IsEntity()) {
  2389. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2390. if (target->IsPlayer())
  2391. ((Player*)target)->SetCharSheetChanged(true);
  2392. }
  2393. }
  2394. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2395. }
  2396. else {
  2397. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn ? spawn->GetName() : "N/A");
  2398. }
  2399. }
  2400. else if (spawn && spawn->IsEntity()) {
  2401. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2402. if (spawn->IsPlayer())
  2403. ((Player*)spawn)->SetCharSheetChanged(true);
  2404. }
  2405. return 0;
  2406. }
  2407. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2408. if (!lua_interface)
  2409. return 0;
  2410. Spawn* spawn = lua_interface->GetSpawn(state);
  2411. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2412. float value = lua_interface->GetFloatValue(state, 3);
  2413. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2414. if (value != 0) {
  2415. int32 spell_id = 0;
  2416. if (luaspell && luaspell->spell && luaspell->caster) {
  2417. if(luaspell->resisted) {
  2418. lua_interface->ResetFunctionStack(state);
  2419. return 0;
  2420. }
  2421. spell_id = luaspell->spell->GetSpellID();
  2422. ZoneServer* zone = luaspell->caster->GetZone();
  2423. Spawn* target = 0;
  2424. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2425. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2426. target = zone->GetSpawnByID(luaspell->targets[i]);
  2427. if (target && target->Alive()) {
  2428. if (target->IsPlayer()) {
  2429. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2430. Client* client = ((Player*)target)->GetClient();
  2431. if (client) {
  2432. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2433. if (packet)
  2434. client->QueuePacket(packet);
  2435. }
  2436. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2437. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2438. }
  2439. else if (target->IsNPC()) {
  2440. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2443. }
  2444. else
  2445. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2446. }
  2447. }
  2448. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2449. }
  2450. else if (spawn) {
  2451. if (spawn->IsPlayer()) {
  2452. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2453. Client* client = ((Player*)spawn)->GetClient();
  2454. if (client) {
  2455. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2456. if (packet)
  2457. client->QueuePacket(packet);
  2458. }
  2459. }
  2460. else if (spawn->IsNPC())
  2461. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2462. else
  2463. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2464. }
  2465. }
  2466. else
  2467. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2468. return 0;
  2469. }
  2470. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2471. if (!lua_interface)
  2472. return 0;
  2473. Spawn* spawn = lua_interface->GetSpawn(state);
  2474. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2475. lua_interface->ResetFunctionStack(state);
  2476. int32 spell_id = 0;
  2477. if (luaspell && luaspell->spell && luaspell->caster) {
  2478. if(luaspell->resisted) {
  2479. return 0;
  2480. }
  2481. spell_id = luaspell->spell->GetSpellID();
  2482. ZoneServer* zone = luaspell->caster->GetZone();
  2483. Spawn* target = 0;
  2484. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2485. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2486. target = zone->GetSpawnByID(luaspell->targets[i]);
  2487. if (target) {
  2488. if (target->IsPlayer()) {
  2489. ((Player*)target)->RemoveSkillBonus(spell_id);
  2490. Client* client = ((Player*)target)->GetClient();
  2491. if (client) {
  2492. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2493. if (packet)
  2494. client->QueuePacket(packet);
  2495. }
  2496. }
  2497. else if (target->IsNPC())
  2498. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2499. else
  2500. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2501. }
  2502. }
  2503. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2504. }
  2505. else if (spawn) {
  2506. if (spawn->IsPlayer()) {
  2507. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2508. Client* client = ((Player*)spawn)->GetClient();
  2509. if (client) {
  2510. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2511. if (packet)
  2512. client->QueuePacket(packet);
  2513. }
  2514. }
  2515. else if (spawn->IsNPC())
  2516. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2517. else
  2518. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2519. }
  2520. return 0;
  2521. }
  2522. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2523. if (!lua_interface)
  2524. return 0;
  2525. Spawn* spawn = lua_interface->GetSpawn(state);
  2526. int8 type = lua_interface->GetInt32Value(state, 2);
  2527. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2528. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2529. lua_interface->ResetFunctionStack(state);
  2530. if(!luaspell || luaspell->resisted) {
  2531. return 0;
  2532. }
  2533. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2534. ZoneServer* zone = luaspell->caster->GetZone();
  2535. Spawn* target = 0;
  2536. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2537. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2538. target = zone->GetSpawnByID(luaspell->targets[i]);
  2539. if (target && target->IsEntity()) {
  2540. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2541. ((Entity*)target)->AddMezSpell(luaspell);
  2542. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2543. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2544. if (target->IsNPC())
  2545. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2546. }
  2547. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2548. ((Entity*)target)->AddStifleSpell(luaspell);
  2549. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2550. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2551. if (target->IsNPC())
  2552. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2553. }
  2554. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2555. ((Entity*)target)->AddDazeSpell(luaspell);
  2556. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2557. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2558. if (target->IsNPC())
  2559. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2560. }
  2561. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2562. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2563. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2564. ((Entity*)target)->AddStunSpell(luaspell);
  2565. if (target->IsNPC())
  2566. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2567. }
  2568. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2569. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2570. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2571. ((Entity*)target)->AddRootSpell(luaspell);
  2572. if (target->IsNPC())
  2573. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2574. }
  2575. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2576. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2577. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2578. ((Entity*)target)->AddFearSpell(luaspell);
  2579. if (target->IsNPC())
  2580. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2581. }
  2582. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2583. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2584. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2585. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2586. }
  2587. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2588. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2589. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2590. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2591. }
  2592. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2593. ((Entity*)target)->AddSnareSpell(luaspell);
  2594. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2595. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2596. if (target->IsNPC())
  2597. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2598. }
  2599. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2600. ((Entity*)target)->AddFlightSpell(luaspell);
  2601. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2602. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2603. }
  2604. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2605. ((Entity*)target)->AddGlideSpell(luaspell);
  2606. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2607. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2608. }
  2609. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2610. ((Entity*)target)->AddSafefallSpell(luaspell);
  2611. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2612. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2613. }
  2614. else
  2615. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2616. }
  2617. else
  2618. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2619. }
  2620. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2621. }
  2622. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2623. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2624. ((Entity*)spawn)->AddMezSpell(luaspell);
  2625. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2626. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2627. }
  2628. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2629. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2630. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2631. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2632. }
  2633. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2634. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2635. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2636. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2637. }
  2638. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2639. ((Entity*)spawn)->AddStunSpell(luaspell);
  2640. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2641. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2642. }
  2643. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2644. ((Entity*)spawn)->AddRootSpell(luaspell);
  2645. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2646. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2647. }
  2648. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2649. ((Entity*)spawn)->AddFearSpell(luaspell);
  2650. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2651. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2652. }
  2653. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2654. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2655. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2656. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2657. }
  2658. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2659. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2660. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2661. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2662. }
  2663. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2664. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2665. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2666. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2667. }
  2668. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2669. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2670. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2671. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2672. }
  2673. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2674. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2675. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2676. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2677. }
  2678. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2679. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2680. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2681. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2682. }
  2683. else
  2684. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2685. }
  2686. else
  2687. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2688. return 0;
  2689. }
  2690. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. int8 type = lua_interface->GetInt8Value(state, 2);
  2695. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2696. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2697. lua_interface->ResetFunctionStack(state);
  2698. if (spawn && spawn->IsEntity()) {
  2699. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2700. ZoneServer* zone = luaspell->caster->GetZone();
  2701. Spawn* target = 0;
  2702. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2703. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2704. target = zone->GetSpawnByID(luaspell->targets[i]);
  2705. if (target) {
  2706. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2707. ((Entity*)target)->RemoveMezSpell(luaspell);
  2708. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2709. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2710. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2711. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2712. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2713. ((Entity*)target)->RemoveStunSpell(luaspell);
  2714. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2715. ((Entity*)target)->RemoveRootSpell(luaspell);
  2716. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2717. ((Entity*)target)->RemoveFearSpell(luaspell);
  2718. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2719. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2720. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2721. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2722. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2723. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2724. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2725. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2726. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2727. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2728. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2729. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2730. else
  2731. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2732. }
  2733. }
  2734. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2735. }
  2736. else if (only_remove_spawn) {
  2737. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2738. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2739. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2740. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2741. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2742. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2743. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2744. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2745. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2746. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2747. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2748. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2749. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2750. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2751. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2752. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2753. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2754. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2755. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2756. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2757. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2758. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2759. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2760. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2761. else
  2762. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2763. }
  2764. }
  2765. return 0;
  2766. }
  2767. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2768. if (!lua_interface)
  2769. return 0;
  2770. Spawn* spawn = lua_interface->GetSpawn(state);
  2771. int8 type = lua_interface->GetInt8Value(state, 2);
  2772. lua_interface->ResetFunctionStack(state);
  2773. bool hasEffect = false;
  2774. if (!spawn)
  2775. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2776. else if (!spawn->IsEntity())
  2777. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2778. else if (type < CONTROL_MAX_EFFECTS)
  2779. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2780. else
  2781. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2782. lua_interface->SetBooleanValue(state, hasEffect);
  2783. return 1;
  2784. }
  2785. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2786. if (!lua_interface)
  2787. return 0;
  2788. Spawn* spawn = lua_interface->GetSpawn(state);
  2789. float distance = 0.0f;
  2790. lua_interface->ResetFunctionStack(state);
  2791. if (!spawn)
  2792. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2793. else if (!spawn->IsNPC())
  2794. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2795. else
  2796. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2797. lua_interface->SetFloatValue(state, distance);
  2798. return 1;
  2799. }
  2800. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. float distance = 0.0f;
  2805. lua_interface->ResetFunctionStack(state);
  2806. if (!spawn)
  2807. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2808. else if (!spawn->IsNPC())
  2809. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2810. else
  2811. distance = ((NPC*)spawn)->GetAggroRadius();
  2812. lua_interface->SetFloatValue(state, distance);
  2813. return 1;
  2814. }
  2815. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2816. if (!lua_interface)
  2817. return 0;
  2818. Spawn* spawn = lua_interface->GetSpawn(state);
  2819. float distance = lua_interface->GetFloatValue(state, 2);
  2820. bool override_ = lua_interface->GetBooleanValue(state, 3);
  2821. bool result = false;
  2822. lua_interface->ResetFunctionStack(state);
  2823. if (!spawn)
  2824. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2825. else if (!spawn->IsNPC())
  2826. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2827. else
  2828. {
  2829. ((NPC*)spawn)->SetAggroRadius(distance, override_);
  2830. result = true;
  2831. }
  2832. lua_interface->SetBooleanValue(state, result);
  2833. return 1;
  2834. }
  2835. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. int16 value = lua_interface->GetInt16Value(state, 2);
  2840. lua_interface->ResetFunctionStack(state);
  2841. if (spawn && spawn->IsEntity()) {
  2842. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2843. if (spawn->IsPlayer())
  2844. ((Player*)spawn)->SetCharSheetChanged(true);
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. int16 value = lua_interface->GetInt16Value(state, 2);
  2853. lua_interface->ResetFunctionStack(state);
  2854. if (spawn && spawn->IsEntity()) {
  2855. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2856. if (spawn->IsPlayer())
  2857. ((Player*)spawn)->SetCharSheetChanged(true);
  2858. }
  2859. return 0;
  2860. }
  2861. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2862. if (!lua_interface)
  2863. return 0;
  2864. Spawn* spawn = lua_interface->GetSpawn(state);
  2865. int16 value = lua_interface->GetInt16Value(state, 2);
  2866. lua_interface->ResetFunctionStack(state);
  2867. if (spawn && spawn->IsEntity()) {
  2868. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2869. if (spawn->IsPlayer())
  2870. ((Player*)spawn)->SetCharSheetChanged(true);
  2871. }
  2872. return 0;
  2873. }
  2874. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2875. if (!lua_interface)
  2876. return 0;
  2877. Spawn* spawn = lua_interface->GetSpawn(state);
  2878. int16 value = lua_interface->GetInt16Value(state, 2);
  2879. lua_interface->ResetFunctionStack(state);
  2880. if (spawn && spawn->IsEntity()) {
  2881. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2882. if (spawn->IsPlayer())
  2883. ((Player*)spawn)->SetCharSheetChanged(true);
  2884. }
  2885. return 0;
  2886. }
  2887. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2888. if (!lua_interface)
  2889. return 0;
  2890. Spawn* spawn = lua_interface->GetSpawn(state);
  2891. int16 value = lua_interface->GetInt16Value(state, 2);
  2892. lua_interface->ResetFunctionStack(state);
  2893. if (spawn && spawn->IsEntity()) {
  2894. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2895. if (spawn->IsPlayer())
  2896. ((Player*)spawn)->SetCharSheetChanged(true);
  2897. }
  2898. return 0;
  2899. }
  2900. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2901. if (!lua_interface)
  2902. return 0;
  2903. Spawn* spawn = lua_interface->GetSpawn(state);
  2904. int8 value = lua_interface->GetInt8Value(state, 2);
  2905. lua_interface->ResetFunctionStack(state);
  2906. if (spawn && spawn->IsEntity()) {
  2907. ((Entity*)spawn)->SetDeity(value);
  2908. if (spawn->IsPlayer())
  2909. ((Player*)spawn)->SetCharSheetChanged(true);
  2910. }
  2911. lua_interface->ResetFunctionStack(state);
  2912. return 0;
  2913. }
  2914. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2915. if (!lua_interface)
  2916. return 0;
  2917. Spawn* spawn = lua_interface->GetSpawn(state);
  2918. lua_interface->ResetFunctionStack(state);
  2919. if (spawn && spawn->IsEntity()) {
  2920. int8 deity = ((Entity*)spawn)->GetDeity();
  2921. lua_interface->SetInt32Value(state, deity);
  2922. return 1;
  2923. }
  2924. return 0;
  2925. }
  2926. int EQ2Emu_lua_SetInt(lua_State* state) {
  2927. if (!lua_interface)
  2928. return 0;
  2929. Spawn* spawn = lua_interface->GetSpawn(state);
  2930. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2931. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2932. lua_interface->ResetFunctionStack(state);
  2933. if (spawn && spawn->IsEntity()) {
  2934. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2935. if (spawn->IsPlayer())
  2936. ((Player*)spawn)->SetCharSheetChanged(true);
  2937. }
  2938. return 0;
  2939. }
  2940. int EQ2Emu_lua_SetWis(lua_State* state) {
  2941. if (!lua_interface)
  2942. return 0;
  2943. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2944. Spawn* spawn = lua_interface->GetSpawn(state);
  2945. float value = lua_interface->GetFloatValue(state, 2);
  2946. lua_interface->ResetFunctionStack(state);
  2947. if (spawn && spawn->IsEntity()) {
  2948. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2949. if (spawn->IsPlayer())
  2950. ((Player*)spawn)->SetCharSheetChanged(true);
  2951. }
  2952. return 0;
  2953. }
  2954. int EQ2Emu_lua_SetSta(lua_State* state) {
  2955. if (!lua_interface)
  2956. return 0;
  2957. Spawn* spawn = lua_interface->GetSpawn(state);
  2958. float value = lua_interface->GetFloatValue(state, 2);
  2959. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2960. lua_interface->ResetFunctionStack(state);
  2961. if (spawn && spawn->IsEntity()) {
  2962. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2963. if (spawn->IsPlayer())
  2964. ((Player*)spawn)->SetCharSheetChanged(true);
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_SetStr(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Spawn* spawn = lua_interface->GetSpawn(state);
  2972. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2973. float value = lua_interface->GetFloatValue(state, 2);
  2974. lua_interface->ResetFunctionStack(state);
  2975. if (spawn && spawn->IsEntity()) {
  2976. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2977. if (spawn->IsPlayer())
  2978. ((Player*)spawn)->SetCharSheetChanged(true);
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2987. float value = lua_interface->GetFloatValue(state, 2);
  2988. lua_interface->ResetFunctionStack(state);
  2989. if (spawn && spawn->IsEntity()) {
  2990. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2991. if (spawn->IsPlayer())
  2992. ((Player*)spawn)->SetCharSheetChanged(true);
  2993. }
  2994. return 0;
  2995. }
  2996. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2997. if (!lua_interface)
  2998. return 0;
  2999. Spawn* spawn = lua_interface->GetSpawn(state);
  3000. lua_interface->ResetFunctionStack(state);
  3001. if (spawn) {
  3002. lua_interface->SetInt32Value(state, spawn->GetHP());
  3003. return 1;
  3004. }
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Spawn* spawn = lua_interface->GetSpawn(state);
  3011. lua_interface->ResetFunctionStack(state);
  3012. if (spawn) {
  3013. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  3014. return 1;
  3015. }
  3016. return 0;
  3017. }
  3018. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  3019. if (!lua_interface)
  3020. return 0;
  3021. Spawn* spawn = lua_interface->GetSpawn(state);
  3022. lua_interface->ResetFunctionStack(state);
  3023. if (spawn) {
  3024. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  3025. return 1;
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_GetName(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Spawn* spawn = lua_interface->GetSpawn(state);
  3033. lua_interface->ResetFunctionStack(state);
  3034. if (spawn) {
  3035. lua_interface->SetStringValue(state, spawn->GetName());
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. lua_interface->ResetFunctionStack(state);
  3043. if (spawn) {
  3044. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3045. return 1;
  3046. }
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3050. Spawn* spawn = lua_interface->GetSpawn(state);
  3051. lua_interface->ResetFunctionStack(state);
  3052. if (spawn) {
  3053. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3054. return 1;
  3055. }
  3056. return 0;
  3057. }
  3058. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3059. if (!lua_interface)
  3060. return 0;
  3061. Spawn* spawn = lua_interface->GetSpawn(state);
  3062. lua_interface->ResetFunctionStack(state);
  3063. if (spawn) {
  3064. lua_interface->SetInt32Value(state, spawn->GetPower());
  3065. return 1;
  3066. }
  3067. return 0;
  3068. }
  3069. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3070. if (!lua_interface)
  3071. return 0;
  3072. Spawn* spawn = lua_interface->GetSpawn(state);
  3073. lua_interface->ResetFunctionStack(state);
  3074. if (spawn) {
  3075. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3076. return 1;
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Spawn* spawn = lua_interface->GetSpawn(state);
  3084. lua_interface->ResetFunctionStack(state);
  3085. if (spawn) {
  3086. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3087. return 1;
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Spawn* spawn = lua_interface->GetSpawn(state);
  3095. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3096. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3097. lua_interface->ResetFunctionStack(state);
  3098. if (spawn && spawn2) {
  3099. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3100. lua_interface->SetFloatValue(state, distance);
  3101. return 1;
  3102. }
  3103. return 0;
  3104. }
  3105. int EQ2Emu_lua_GetX(lua_State* state) {
  3106. if (!lua_interface)
  3107. return 0;
  3108. Spawn* spawn = lua_interface->GetSpawn(state);
  3109. lua_interface->ResetFunctionStack(state);
  3110. if (spawn) {
  3111. lua_interface->SetFloatValue(state, spawn->GetX());
  3112. return 1;
  3113. }
  3114. return 0;
  3115. }
  3116. int EQ2Emu_lua_GetY(lua_State* state) {
  3117. if (!lua_interface)
  3118. return 0;
  3119. Spawn* spawn = lua_interface->GetSpawn(state);
  3120. lua_interface->ResetFunctionStack(state);
  3121. if (spawn) {
  3122. lua_interface->SetFloatValue(state, spawn->GetY());
  3123. return 1;
  3124. }
  3125. return 0;
  3126. }
  3127. int EQ2Emu_lua_GetZ(lua_State* state) {
  3128. if (!lua_interface)
  3129. return 0;
  3130. Spawn* spawn = lua_interface->GetSpawn(state);
  3131. lua_interface->ResetFunctionStack(state);
  3132. if (spawn) {
  3133. lua_interface->SetFloatValue(state, spawn->GetZ());
  3134. return 1;
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3139. if (!lua_interface)
  3140. return 0;
  3141. Spawn* spawn = lua_interface->GetSpawn(state);
  3142. lua_interface->ResetFunctionStack(state);
  3143. if (spawn) {
  3144. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3145. return 1;
  3146. }
  3147. return 0;
  3148. }
  3149. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3150. if (!lua_interface)
  3151. return 0;
  3152. Spawn* spawn = lua_interface->GetSpawn(state);
  3153. lua_interface->ResetFunctionStack(state);
  3154. if (spawn) {
  3155. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3156. return 1;
  3157. }
  3158. return 0;
  3159. }
  3160. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3161. if (!lua_interface)
  3162. return 0;
  3163. Spawn* spawn = lua_interface->GetSpawn(state);
  3164. lua_interface->ResetFunctionStack(state);
  3165. if (spawn) {
  3166. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3167. return 1;
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Spawn* spawn = lua_interface->GetSpawn(state);
  3175. lua_interface->ResetFunctionStack(state);
  3176. if (spawn && spawn->IsEntity()) {
  3177. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3178. return 1;
  3179. }
  3180. return 0;
  3181. }
  3182. int EQ2Emu_lua_GetInt(lua_State* state) {
  3183. if (!lua_interface)
  3184. return 0;
  3185. Spawn* spawn = lua_interface->GetSpawn(state);
  3186. lua_interface->ResetFunctionStack(state);
  3187. if (spawn && spawn->IsEntity()) {
  3188. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3189. return 1;
  3190. }
  3191. return 0;
  3192. }
  3193. int EQ2Emu_lua_GetWis(lua_State* state) {
  3194. if (!lua_interface)
  3195. return 0;
  3196. Spawn* spawn = lua_interface->GetSpawn(state);
  3197. lua_interface->ResetFunctionStack(state);
  3198. if (spawn && spawn->IsEntity()) {
  3199. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3200. return 1;
  3201. }
  3202. return 0;
  3203. }
  3204. int EQ2Emu_lua_GetSta(lua_State* state) {
  3205. if (!lua_interface)
  3206. return 0;
  3207. Spawn* spawn = lua_interface->GetSpawn(state);
  3208. lua_interface->ResetFunctionStack(state);
  3209. if (spawn && spawn->IsEntity()) {
  3210. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3211. return 1;
  3212. }
  3213. return 0;
  3214. }
  3215. int EQ2Emu_lua_GetStr(lua_State* state) {
  3216. if (!lua_interface)
  3217. return 0;
  3218. Spawn* spawn = lua_interface->GetSpawn(state);
  3219. lua_interface->ResetFunctionStack(state);
  3220. if (spawn && spawn->IsEntity()) {
  3221. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3222. return 1;
  3223. }
  3224. return 0;
  3225. }
  3226. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3227. if (!lua_interface)
  3228. return 0;
  3229. Spawn* spawn = lua_interface->GetSpawn(state);
  3230. lua_interface->ResetFunctionStack(state);
  3231. if (spawn && spawn->IsEntity()) {
  3232. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3233. return 1;
  3234. }
  3235. return 0;
  3236. }
  3237. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3238. if (!lua_interface)
  3239. return 0;
  3240. Spawn* spawn = lua_interface->GetSpawn(state);
  3241. lua_interface->ResetFunctionStack(state);
  3242. if (spawn && spawn->IsEntity()) {
  3243. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3244. return 1;
  3245. }
  3246. return 0;
  3247. }
  3248. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3249. if (!lua_interface)
  3250. return 0;
  3251. Spawn* spawn = lua_interface->GetSpawn(state);
  3252. lua_interface->ResetFunctionStack(state);
  3253. if (spawn && spawn->IsEntity()) {
  3254. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3255. return 1;
  3256. }
  3257. return 0;
  3258. }
  3259. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3260. if (!lua_interface)
  3261. return 0;
  3262. Spawn* spawn = lua_interface->GetSpawn(state);
  3263. lua_interface->ResetFunctionStack(state);
  3264. if (spawn && spawn->IsEntity()) {
  3265. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3266. return 1;
  3267. }
  3268. return 0;
  3269. }
  3270. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3271. if (!lua_interface)
  3272. return 0;
  3273. Spawn* spawn = lua_interface->GetSpawn(state);
  3274. lua_interface->ResetFunctionStack(state);
  3275. if (spawn && spawn->IsEntity()) {
  3276. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3277. return 1;
  3278. }
  3279. return 0;
  3280. }
  3281. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3282. if (!lua_interface)
  3283. return 0;
  3284. Spawn* spawn = lua_interface->GetSpawn(state);
  3285. lua_interface->ResetFunctionStack(state);
  3286. if (spawn && spawn->IsEntity()) {
  3287. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3288. return 1;
  3289. }
  3290. return 0;
  3291. }
  3292. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3293. if (!lua_interface)
  3294. return 0;
  3295. Spawn* player = lua_interface->GetSpawn(state);
  3296. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3297. int32 step = lua_interface->GetInt32Value(state, 3);
  3298. lua_interface->ResetFunctionStack(state);
  3299. if (!player || !player->IsPlayer()) {
  3300. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3301. return 0;
  3302. }
  3303. if (quest_id <= 0) {
  3304. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3305. return 0;
  3306. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3307. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3308. return 0;
  3309. }
  3310. if (step > 0) {
  3311. Client* client = ((Player*)player)->GetClient();
  3312. if (client)
  3313. client->AddPendingQuestUpdate(quest_id, step);
  3314. } else {
  3315. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3316. }
  3317. return 0;
  3318. }
  3319. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3320. Spawn* player = lua_interface->GetSpawn(state);
  3321. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3322. int32 step = lua_interface->GetInt32Value(state, 3);
  3323. int32 progress = lua_interface->GetInt32Value(state, 4);
  3324. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3325. Client* client = ((Player*)player)->GetClient();
  3326. if (client)
  3327. client->AddPendingQuestUpdate(quest_id, step, progress);
  3328. }
  3329. return 0;
  3330. }
  3331. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3332. if (!lua_interface)
  3333. return 0;
  3334. Spawn* player = lua_interface->GetSpawn(state);
  3335. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3336. if (player && player->IsPlayer() && quest_id > 0) {
  3337. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3338. return 1;
  3339. }
  3340. return 0;
  3341. }
  3342. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3343. if (!lua_interface)
  3344. return 0;
  3345. Spawn* player = lua_interface->GetSpawn(state);
  3346. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3347. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3348. lua_interface->ResetFunctionStack(state);
  3349. if (player && player->IsPlayer() && quest_id > 0) {
  3350. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3351. return 1;
  3352. }
  3353. return 0;
  3354. }
  3355. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3356. if (!lua_interface)
  3357. return 0;
  3358. Spawn* player = lua_interface->GetSpawn(state);
  3359. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3360. lua_interface->ResetFunctionStack(state);
  3361. if (player && player->IsPlayer() && quest_id > 0) {
  3362. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3363. return 1;
  3364. }
  3365. return 0;
  3366. }
  3367. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3368. if (!lua_interface)
  3369. return 0;
  3370. Quest* quest = lua_interface->GetQuest(state);
  3371. string name = lua_interface->GetStringValue(state, 2);
  3372. string type = lua_interface->GetStringValue(state, 3);
  3373. string zone = lua_interface->GetStringValue(state, 4);
  3374. int16 level = lua_interface->GetInt16Value(state, 5);
  3375. string description = lua_interface->GetStringValue(state, 6);
  3376. lua_interface->ResetFunctionStack(state);
  3377. bool load = true;
  3378. if (!quest) {
  3379. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3380. load = false;
  3381. }
  3382. if (load && name.length() == 0) {
  3383. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3384. load = false;
  3385. }
  3386. if (load && type.length() == 0) {
  3387. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3388. load = false;
  3389. }
  3390. if (load && zone.length() == 0) {
  3391. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3392. load = false;
  3393. }
  3394. if (load && description.length() == 0) {
  3395. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3396. load = false;
  3397. }
  3398. if (load && level == 0) {
  3399. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3400. load = false;
  3401. }
  3402. if (load)
  3403. quest->RegisterQuest(name, type, zone, level, description);
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int8 level = lua_interface->GetInt16Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest) {
  3413. quest->SetPrereqLevel(level);
  3414. }
  3415. return 0;
  3416. }
  3417. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3418. if (!lua_interface)
  3419. return 0;
  3420. Quest* quest = lua_interface->GetQuest(state);
  3421. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3422. lua_interface->ResetFunctionStack(state);
  3423. if (quest) {
  3424. quest->AddPrereqQuest(quest_id);
  3425. }
  3426. return 0;
  3427. }
  3428. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3429. if (!lua_interface)
  3430. return 0;
  3431. Quest* quest = lua_interface->GetQuest(state);
  3432. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3433. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3434. lua_interface->ResetFunctionStack(state);
  3435. if (quest) {
  3436. if (quantity == 0)
  3437. quantity = 1;
  3438. Item* master_item = master_item_list.GetItem(item_id);
  3439. if (master_item) {
  3440. Item* item = new Item(master_item);
  3441. item->details.count = quantity;
  3442. quest->AddPrereqItem(item);
  3443. }
  3444. }
  3445. return 0;
  3446. }
  3447. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3448. if (!lua_interface)
  3449. return 0;
  3450. Spawn* player = lua_interface->GetSpawn(state);
  3451. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3452. lua_interface->ResetFunctionStack(state);
  3453. if(!player || !player->IsPlayer()) {
  3454. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3455. return 0;
  3456. }
  3457. if (quest_id > 0) {
  3458. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3459. return 1;
  3460. } else {
  3461. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3462. }
  3463. return 0;
  3464. }
  3465. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3466. if (!lua_interface)
  3467. return 0;
  3468. Quest* quest = lua_interface->GetQuest(state);
  3469. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3470. lua_interface->ResetFunctionStack(state);
  3471. if (quest && spawn_id > 0)
  3472. quest->SetQuestReturnNPC(spawn_id);
  3473. return 0;
  3474. }
  3475. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3476. if (!lua_interface)
  3477. return 0;
  3478. Spawn* spawn = lua_interface->GetSpawn(state);
  3479. int32 time = lua_interface->GetInt32Value(state, 2);
  3480. string function = lua_interface->GetStringValue(state, 3);
  3481. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3482. Spawn* player = lua_interface->GetSpawn(state, 5);
  3483. lua_interface->ResetFunctionStack(state);
  3484. if (!spawn) {
  3485. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3486. return 0;
  3487. }
  3488. if (time <= 0) {
  3489. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3490. return 0;
  3491. }
  3492. if (function.length() == 0) {
  3493. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3494. return 0;
  3495. }
  3496. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3497. if ( time < 10)
  3498. time = 10;
  3499. timer->timer = Timer::GetCurrentTime2() + time;
  3500. timer->function = function;
  3501. timer->spawn = spawn->GetID();
  3502. timer->player = player ? player->GetID() : 0;
  3503. if (max_count == 0)
  3504. max_count = 1;
  3505. timer->max_count = max_count;
  3506. timer->current_count = 0;
  3507. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3508. return 0;
  3509. }
  3510. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3511. if (!lua_interface)
  3512. return 0;
  3513. Spawn* spawn = lua_interface->GetSpawn(state);
  3514. string function = lua_interface->GetStringValue(state, 2);
  3515. lua_interface->ResetFunctionStack(state);
  3516. if (!spawn) {
  3517. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3518. return 0;
  3519. }
  3520. if(!spawn->GetZone()) {
  3521. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3522. return 0;
  3523. }
  3524. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3525. return 0;
  3526. }
  3527. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3528. if (!lua_interface)
  3529. return 0;
  3530. Spawn* player = lua_interface->GetSpawn(state);
  3531. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3532. lua_interface->ResetFunctionStack(state);
  3533. if (player && player->IsPlayer() && quest_id > 0) {
  3534. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3535. return 1;
  3536. }
  3537. return 0;
  3538. }
  3539. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3540. if (!lua_interface)
  3541. return 0;
  3542. Spawn* player = lua_interface->GetSpawn(state);
  3543. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3544. lua_interface->ResetFunctionStack(state);
  3545. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3546. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3547. if (quest)
  3548. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3549. return 1;
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Spawn* player = lua_interface->GetSpawn(state);
  3557. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (player && player->IsPlayer() && quest_id > 0) {
  3560. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3561. return 1;
  3562. }
  3563. return 0;
  3564. }
  3565. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3566. if (!lua_interface)
  3567. return 0;
  3568. Spawn* npc = lua_interface->GetSpawn(state);
  3569. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3570. lua_interface->ResetFunctionStack(state);
  3571. if (npc && !npc->IsPlayer() && quest_id > 0)
  3572. npc->AddProvidedQuest(quest_id);
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Spawn* npc = lua_interface->GetSpawn(state);
  3579. Spawn* player = lua_interface->GetSpawn(state, 2);
  3580. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3581. bool forced = lua_interface->GetBooleanValue(state, 4);
  3582. lua_interface->ResetFunctionStack(state);
  3583. /* NPC is allowed to be null */
  3584. if (player && player->IsPlayer() && quest_id > 0) {
  3585. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3586. if (master_quest) {
  3587. Client* client = ((Player*)player)->GetClient();
  3588. if (!client) {
  3589. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3590. }
  3591. Quest* quest = new Quest(master_quest);
  3592. if (!quest) {
  3593. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3594. }
  3595. if (client && quest) {
  3596. if (npc)
  3597. quest->SetQuestGiver(npc->GetDatabaseID());
  3598. else
  3599. quest->SetQuestGiver(0);
  3600. client->AddPendingQuest(quest, forced);
  3601. }
  3602. }
  3603. else {
  3604. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3605. }
  3606. }
  3607. else {
  3608. 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);
  3609. }
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3617. lua_interface->ResetFunctionStack(state);
  3618. if (quest) {
  3619. quest->AddPrereqClass(class_id);
  3620. }
  3621. return 0;
  3622. }
  3623. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3624. if (!lua_interface)
  3625. return 0;
  3626. Quest* quest = lua_interface->GetQuest(state);
  3627. int8 race = lua_interface->GetInt8Value(state, 2);
  3628. lua_interface->ResetFunctionStack(state);
  3629. if (quest) {
  3630. quest->AddPrereqRace(race);
  3631. }
  3632. return 0;
  3633. }
  3634. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3635. if (!lua_interface)
  3636. return 0;
  3637. Quest* quest = lua_interface->GetQuest(state);
  3638. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3639. lua_interface->ResetFunctionStack(state);
  3640. if (quest) {
  3641. quest->AddPrereqModelType(model_type);
  3642. }
  3643. return 0;
  3644. }
  3645. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3646. if (!lua_interface)
  3647. return 0;
  3648. Quest* quest = lua_interface->GetQuest(state);
  3649. int8 level = lua_interface->GetInt8Value(state, 2);
  3650. lua_interface->ResetFunctionStack(state);
  3651. if (!quest) {
  3652. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3653. return 0;
  3654. }
  3655. quest->SetPrereqTSLevel(level);
  3656. return 0;
  3657. }
  3658. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3659. if (!lua_interface)
  3660. return 0;
  3661. Quest* quest = lua_interface->GetQuest(state);
  3662. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3663. lua_interface->ResetFunctionStack(state);
  3664. if (!quest) {
  3665. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3666. return 0;
  3667. }
  3668. quest->AddPrereqTradeskillClass(class_id);
  3669. return 0;
  3670. }
  3671. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3672. if (!lua_interface)
  3673. return 0;
  3674. Quest* quest = lua_interface->GetQuest(state);
  3675. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3676. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3677. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3678. lua_interface->ResetFunctionStack(state);
  3679. if (quest) {
  3680. quest->AddPrereqFaction(faction_id, min, max);
  3681. }
  3682. return 0;
  3683. }
  3684. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3685. if (!lua_interface)
  3686. return 0;
  3687. Quest* quest = lua_interface->GetQuest(state);
  3688. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3689. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3690. lua_interface->ResetFunctionStack(state);
  3691. if (quest) {
  3692. if (quantity == 0)
  3693. quantity = 1;
  3694. Item* master_item = master_item_list.GetItem(item_id);
  3695. if (master_item) {
  3696. Item* item = new Item(master_item);
  3697. item->details.count = quantity;
  3698. quest->AddSelectableRewardItem(item);
  3699. }
  3700. }
  3701. return 0;
  3702. }
  3703. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3704. if (!lua_interface)
  3705. return 0;
  3706. Quest* quest = lua_interface->GetQuest(state);
  3707. if (quest) {
  3708. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3709. vector<Item*>* items = quest->GetRewardItems();
  3710. if (items) {
  3711. vector<Item*>::iterator itr;
  3712. for (itr = items->begin(); itr != items->end(); itr++) {
  3713. if (*itr && (*itr)->details.item_id == item_id) {
  3714. lua_interface->SetBooleanValue(state, true);
  3715. return 1;
  3716. }
  3717. }
  3718. }
  3719. }
  3720. lua_interface->SetBooleanValue(state, false);
  3721. return 1;
  3722. }
  3723. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3724. if (!lua_interface)
  3725. return 0;
  3726. Quest* quest = lua_interface->GetQuest(state);
  3727. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3728. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3729. lua_interface->ResetFunctionStack(state);
  3730. if (quest) {
  3731. if (quantity == 0)
  3732. quantity = 1;
  3733. Item* master_item = master_item_list.GetItem(item_id);
  3734. if (master_item) {
  3735. Item* item = new Item(master_item);
  3736. item->details.count = quantity;
  3737. quest->AddRewardItem(item);
  3738. }
  3739. }
  3740. return 0;
  3741. }
  3742. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3743. if (!lua_interface)
  3744. return 0;
  3745. Quest* quest = lua_interface->GetQuest(state);
  3746. int32 copper = lua_interface->GetInt32Value(state, 2);
  3747. int32 silver = lua_interface->GetInt32Value(state, 3);
  3748. int32 gold = lua_interface->GetInt32Value(state, 4);
  3749. int32 plat = lua_interface->GetInt32Value(state, 5);
  3750. lua_interface->ResetFunctionStack(state);
  3751. if (quest) {
  3752. quest->AddRewardCoins(copper, silver, gold, plat);
  3753. }
  3754. return 0;
  3755. }
  3756. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3757. if (!lua_interface)
  3758. return 0;
  3759. Quest* quest = lua_interface->GetQuest(state);
  3760. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3761. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3762. lua_interface->ResetFunctionStack(state);
  3763. if (quest && faction_id > 0 && amount != 0)
  3764. quest->AddRewardFaction(faction_id, amount);
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Quest* quest = lua_interface->GetQuest(state);
  3771. int32 status = lua_interface->GetInt32Value(state, 2);
  3772. lua_interface->ResetFunctionStack(state);
  3773. if (quest) {
  3774. quest->SetRewardStatus(status);
  3775. }
  3776. return 0;
  3777. }
  3778. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3779. if (!lua_interface)
  3780. return 0;
  3781. Quest* quest = lua_interface->GetQuest(state);
  3782. int32 status = lua_interface->GetInt32Value(state, 2);
  3783. lua_interface->ResetFunctionStack(state);
  3784. if (quest) {
  3785. quest->SetStatusTmpReward(status);
  3786. }
  3787. return 0;
  3788. }
  3789. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3790. if (!lua_interface)
  3791. return 0;
  3792. Quest* quest = lua_interface->GetQuest(state);
  3793. int64 coins = lua_interface->GetInt64Value(state, 2);
  3794. lua_interface->ResetFunctionStack(state);
  3795. if (quest) {
  3796. quest->SetCoinTmpReward(coins);
  3797. }
  3798. return 0;
  3799. }
  3800. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3801. if (!lua_interface)
  3802. return 0;
  3803. Quest* quest = lua_interface->GetQuest(state);
  3804. string comment = lua_interface->GetStringValue(state, 2);
  3805. lua_interface->ResetFunctionStack(state);
  3806. if (quest) {
  3807. quest->SetRewardComment(comment);
  3808. }
  3809. return 0;
  3810. }
  3811. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3812. if (!lua_interface)
  3813. return 0;
  3814. Quest* quest = lua_interface->GetQuest(state);
  3815. int32 exp = lua_interface->GetInt32Value(state, 2);
  3816. lua_interface->ResetFunctionStack(state);
  3817. if (quest) {
  3818. quest->SetRewardXP(exp);
  3819. }
  3820. return 0;
  3821. }
  3822. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3823. Quest* quest = lua_interface->GetQuest(state);
  3824. int32 step = lua_interface->GetInt32Value(state, 2);
  3825. string description = lua_interface->GetStringValue(state, 3);
  3826. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3827. float percentage = lua_interface->GetFloatValue(state, 5);
  3828. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3829. int16 icon = lua_interface->GetInt16Value(state, 7);
  3830. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3831. if (quest) {
  3832. const char* taskgroup = 0;
  3833. if (str_taskgroup.length() > 0)
  3834. taskgroup = str_taskgroup.c_str();
  3835. int32 id = 0;
  3836. vector<int32>* ids = 0;
  3837. int i = 0;
  3838. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3839. if (ids == 0)
  3840. ids = new vector<int32>;
  3841. ids->push_back(id);
  3842. i++;
  3843. }
  3844. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3845. if (quest_step && icon && quantity > 0)
  3846. quest_step->SetIcon(icon);
  3847. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3848. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3849. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3850. }
  3851. }
  3852. lua_interface->ResetFunctionStack(state);
  3853. return 0;
  3854. }
  3855. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3856. {
  3857. if (!lua_interface)
  3858. return 0;
  3859. Quest* quest = lua_interface->GetQuest(state);
  3860. int32 step = lua_interface->GetInt32Value(state, 2);
  3861. string description = lua_interface->GetStringValue(state, 3);
  3862. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3863. float percentage = lua_interface->GetFloatValue(state, 5);
  3864. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3865. int16 icon = lua_interface->GetInt16Value(state, 7);
  3866. if (quest) {
  3867. const char* taskgroup = 0;
  3868. if (str_taskgroup.length() > 0)
  3869. taskgroup = str_taskgroup.c_str();
  3870. int32 id = 0;
  3871. vector<int32>* ids = 0;
  3872. int i = 0;
  3873. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3874. if (ids == 0)
  3875. ids = new vector<int32>;
  3876. ids->push_back(id);
  3877. i++;
  3878. }
  3879. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3880. if (quest_step && icon > 0 && quantity > 0)
  3881. quest_step->SetIcon(icon);
  3882. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3883. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3884. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3885. }
  3886. safe_delete(ids);
  3887. }
  3888. lua_interface->ResetFunctionStack(state);
  3889. return 0;
  3890. }
  3891. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3892. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3893. }
  3894. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3895. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3896. }
  3897. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3898. if (!lua_interface)
  3899. return 0;
  3900. Quest* quest = lua_interface->GetQuest(state);
  3901. int32 step = lua_interface->GetInt32Value(state, 2);
  3902. string description = lua_interface->GetStringValue(state, 3);
  3903. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3904. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3905. int16 icon = lua_interface->GetInt16Value(state, 6);
  3906. if (quest) {
  3907. const char* taskgroup = 0;
  3908. if (str_taskgroup.length() > 0)
  3909. taskgroup = str_taskgroup.c_str();
  3910. int32 npc_id = 0;
  3911. vector<int32>* ids = 0;
  3912. int i = 0;
  3913. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3914. if (ids == 0)
  3915. ids = new vector<int32>;
  3916. ids->push_back(npc_id);
  3917. i++;
  3918. }
  3919. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3920. if (quest_step && icon > 0)
  3921. quest_step->SetIcon(icon);
  3922. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3923. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3924. if(client)
  3925. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3926. }
  3927. safe_delete(ids);
  3928. }
  3929. lua_interface->ResetFunctionStack(state);
  3930. return 0;
  3931. }
  3932. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3933. if (!lua_interface)
  3934. return 0;
  3935. Quest* quest = lua_interface->GetQuest(state);
  3936. int32 step = lua_interface->GetInt32Value(state, 2);
  3937. string description = lua_interface->GetStringValue(state, 3);
  3938. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3939. float percentage = lua_interface->GetFloatValue(state, 5);
  3940. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3941. int16 icon = lua_interface->GetInt16Value(state, 7);
  3942. if (quest) {
  3943. const char* taskgroup = 0;
  3944. if (str_taskgroup.length() > 0)
  3945. taskgroup = str_taskgroup.c_str();
  3946. int32 item_id = 0;
  3947. vector<int32>* ids = 0;
  3948. int i = 0;
  3949. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3950. if (ids == 0)
  3951. ids = new vector<int32>;
  3952. ids->push_back(item_id);
  3953. i++;
  3954. }
  3955. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3956. if (quest_step && icon > 0 && quantity > 0)
  3957. quest_step->SetIcon(icon);
  3958. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3959. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3960. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3961. }
  3962. safe_delete(ids);
  3963. }
  3964. lua_interface->ResetFunctionStack(state);
  3965. return 0;
  3966. }
  3967. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3968. if (!lua_interface)
  3969. return 0;
  3970. Quest* quest = lua_interface->GetQuest(state);
  3971. int32 step = lua_interface->GetInt32Value(state, 2);
  3972. string description = lua_interface->GetStringValue(state, 3);
  3973. float max_variation = lua_interface->GetFloatValue(state, 4);
  3974. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3975. int16 icon = lua_interface->GetInt16Value(state, 6);
  3976. if (quest) {
  3977. const char* taskgroup = 0;
  3978. if (str_taskgroup.length() > 0)
  3979. taskgroup = str_taskgroup.c_str();
  3980. vector<Location>* locations = 0;
  3981. int8 i = 7;
  3982. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3983. while (true) {
  3984. Location loc;
  3985. loc.x = lua_interface->GetFloatValue(state, i);
  3986. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3987. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3988. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3989. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3990. break;
  3991. if (locations == 0)
  3992. locations = new vector<Location>;
  3993. locations->push_back(loc);
  3994. i += 4;
  3995. }
  3996. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3997. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3998. if (quest_step && icon > 0)
  3999. quest_step->SetIcon(icon);
  4000. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4001. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4002. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4003. }
  4004. }
  4005. lua_interface->ResetFunctionStack(state);
  4006. return 0;
  4007. }
  4008. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  4009. if (!lua_interface)
  4010. return 0;
  4011. Quest* quest = lua_interface->GetQuest(state);
  4012. int32 step = lua_interface->GetInt32Value(state, 2);
  4013. string description = lua_interface->GetStringValue(state, 3);
  4014. float max_variation = lua_interface->GetFloatValue(state, 4);
  4015. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  4016. int16 icon = lua_interface->GetInt16Value(state, 6);
  4017. if (quest) {
  4018. const char* taskgroup = 0;
  4019. if (str_taskgroup.length() > 0)
  4020. taskgroup = str_taskgroup.c_str();
  4021. vector<Location>* locations = 0;
  4022. int8 i = 7;
  4023. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4024. while (true) {
  4025. Location loc;
  4026. loc.x = lua_interface->GetFloatValue(state, i);
  4027. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4028. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4029. loc.zone_id = 0;
  4030. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4031. break;
  4032. if (locations == 0)
  4033. locations = new vector<Location>;
  4034. locations->push_back(loc);
  4035. i += 3;
  4036. }
  4037. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4038. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4039. if (quest_step && icon > 0)
  4040. quest_step->SetIcon(icon);
  4041. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4042. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4043. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4044. }
  4045. }
  4046. lua_interface->ResetFunctionStack(state);
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Quest* quest = lua_interface->GetQuest(state);
  4053. int32 step = lua_interface->GetInt32Value(state, 2);
  4054. string description = lua_interface->GetStringValue(state, 3);
  4055. float max_variation = lua_interface->GetFloatValue(state, 4);
  4056. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  4057. int16 icon = lua_interface->GetInt16Value(state, 6);
  4058. if (quest) {
  4059. const char* taskgroup = 0;
  4060. if (str_taskgroup.length() > 0)
  4061. taskgroup = str_taskgroup.c_str();
  4062. vector<Location>* locations = 0;
  4063. int i = 7;
  4064. while (true) {
  4065. Location loc;
  4066. loc.x = lua_interface->GetFloatValue(state, i);
  4067. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4068. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4069. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4070. break;
  4071. if (locations == 0)
  4072. locations = new vector<Location>;
  4073. locations->push_back(loc);
  4074. i += 3;
  4075. }
  4076. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4077. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4078. if (quest_step && icon > 0)
  4079. quest_step->SetIcon(icon);
  4080. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4081. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4082. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4083. }
  4084. }
  4085. lua_interface->ResetFunctionStack(state);
  4086. return 0;
  4087. }
  4088. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4089. Quest* quest = lua_interface->GetQuest(state);
  4090. int32 step = lua_interface->GetInt32Value(state, 2);
  4091. string description = lua_interface->GetStringValue(state, 3);
  4092. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4093. float percentage = lua_interface->GetFloatValue(state, 5);
  4094. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4095. int16 icon = lua_interface->GetInt16Value(state, 7);
  4096. if (quest) {
  4097. const char* taskgroup = 0;
  4098. if (str_taskgroup.length() > 0)
  4099. taskgroup = str_taskgroup.c_str();
  4100. int32 spell_id = 0;
  4101. vector<int32>* ids = 0;
  4102. int i = 0;
  4103. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4104. if (ids == 0)
  4105. ids = new vector<int32>;
  4106. ids->push_back(spell_id);
  4107. i++;
  4108. }
  4109. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4110. if (quest_step && icon > 0 && quantity > 0)
  4111. quest_step->SetIcon(icon);
  4112. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4113. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4114. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4115. }
  4116. safe_delete(ids);
  4117. }
  4118. lua_interface->ResetFunctionStack(state);
  4119. return 0;
  4120. }
  4121. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4122. if (!lua_interface)
  4123. return 0;
  4124. Quest* quest = lua_interface->GetQuest(state);
  4125. int32 step = lua_interface->GetInt32Value(state, 2);
  4126. string description = lua_interface->GetStringValue(state, 3);
  4127. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4128. float percentage = lua_interface->GetFloatValue(state, 5);
  4129. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4130. int16 icon = lua_interface->GetInt16Value(state, 7);
  4131. if (quest) {
  4132. const char* taskgroup = 0;
  4133. if (str_taskgroup.length() > 0)
  4134. taskgroup = str_taskgroup.c_str();
  4135. int32 item_id = 0;
  4136. vector<int32>* ids = 0;
  4137. int i = 0;
  4138. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4139. if (ids == 0)
  4140. ids = new vector<int32>;
  4141. ids->push_back(item_id);
  4142. i++;
  4143. }
  4144. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4145. if (quest_step && icon > 0 && quantity > 0)
  4146. quest_step->SetIcon(icon);
  4147. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4148. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4149. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4150. }
  4151. safe_delete(ids);
  4152. }
  4153. lua_interface->ResetFunctionStack(state);
  4154. return 0;
  4155. }
  4156. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4157. if (!lua_interface)
  4158. return 0;
  4159. Quest* quest = lua_interface->GetQuest(state);
  4160. int32 step = lua_interface->GetInt32Value(state, 2);
  4161. string description = lua_interface->GetStringValue(state, 3);
  4162. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4163. float percentage = lua_interface->GetFloatValue(state, 5);
  4164. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4165. int16 icon = lua_interface->GetInt16Value(state, 7);
  4166. if (quest) {
  4167. const char* taskgroup = 0;
  4168. if (str_taskgroup.length() > 0)
  4169. taskgroup = str_taskgroup.c_str();
  4170. int32 item_id = 0;
  4171. vector<int32>* ids = 0;
  4172. int i = 0;
  4173. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4174. if (ids == 0)
  4175. ids = new vector<int32>;
  4176. ids->push_back(item_id);
  4177. i++;
  4178. }
  4179. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4180. if (quest_step && icon > 0 && quantity > 0)
  4181. quest_step->SetIcon(icon);
  4182. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4183. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4184. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4185. }
  4186. safe_delete(ids);
  4187. }
  4188. lua_interface->ResetFunctionStack(state);
  4189. return 0;
  4190. }
  4191. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4192. if (!lua_interface)
  4193. return 0;
  4194. Quest* quest = lua_interface->GetQuest(state);
  4195. string action = lua_interface->GetStringValue(state, 2);
  4196. lua_interface->ResetFunctionStack(state);
  4197. if (quest) {
  4198. if (action.length() > 0)
  4199. quest->SetCompleteAction(action);
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. Quest* quest = lua_interface->GetQuest(state);
  4207. int32 step = lua_interface->GetInt32Value(state, 2);
  4208. string action = lua_interface->GetStringValue(state, 3);
  4209. lua_interface->ResetFunctionStack(state);
  4210. if (quest) {
  4211. if (step > 0 && action.length() > 0)
  4212. quest->AddCompleteAction(step, action);
  4213. }
  4214. return 0;
  4215. }
  4216. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4217. if (!lua_interface)
  4218. return 0;
  4219. Quest* quest = lua_interface->GetQuest(state);
  4220. int32 step = lua_interface->GetInt32Value(state, 2);
  4221. string action = lua_interface->GetStringValue(state, 3);
  4222. lua_interface->ResetFunctionStack(state);
  4223. if (quest) {
  4224. if (step > 0 && action.length() > 0)
  4225. quest->AddProgressAction(step, action);
  4226. }
  4227. return 0;
  4228. }
  4229. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4230. if (!lua_interface)
  4231. return 0;
  4232. Quest* quest = lua_interface->GetQuest(state);
  4233. string description = lua_interface->GetStringValue(state, 2);
  4234. lua_interface->ResetFunctionStack(state);
  4235. if (quest && description.length() > 0)
  4236. quest->SetDescription(description);
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Quest* quest = lua_interface->GetQuest(state);
  4243. string description = lua_interface->GetStringValue(state, 2);
  4244. lua_interface->ResetFunctionStack(state);
  4245. if (quest && description.length() > 0)
  4246. quest->SetCompletedDescription(description);
  4247. return 0;
  4248. }
  4249. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4250. if (!lua_interface)
  4251. return 0;
  4252. Quest* quest = lua_interface->GetQuest(state);
  4253. int32 step = lua_interface->GetInt32Value(state, 2);
  4254. string description = lua_interface->GetStringValue(state, 3);
  4255. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4256. lua_interface->ResetFunctionStack(state);
  4257. if (quest && step > 0 && description.length() > 0) {
  4258. quest->SetTaskGroupDescription(step, description, display_bullets);
  4259. }
  4260. return 0;
  4261. }
  4262. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4263. if (!lua_interface)
  4264. return 0;
  4265. Quest* quest = lua_interface->GetQuest(state);
  4266. int32 step = lua_interface->GetInt32Value(state, 2);
  4267. string description = lua_interface->GetStringValue(state, 3);
  4268. lua_interface->ResetFunctionStack(state);
  4269. if (quest && step > 0 && description.length() > 0) {
  4270. quest->SetStepDescription(step, description);
  4271. }
  4272. return 0;
  4273. }
  4274. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4275. Quest* quest = lua_interface->GetQuest(state);
  4276. string zone = lua_interface->GetStringValue(state, 2);
  4277. lua_interface->ResetFunctionStack(state);
  4278. if (quest && zone.length() > 0)
  4279. quest->SetZone(zone);
  4280. return 0;
  4281. }
  4282. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4283. if (!lua_interface)
  4284. return 0;
  4285. Quest* quest = lua_interface->GetQuest(state);
  4286. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4287. lua_interface->ResetFunctionStack(state);
  4288. if (quest && spawn) {
  4289. if (spawn->IsPlayer()) {
  4290. Client* client = ((Player*)spawn)->GetClient();
  4291. if (client) {
  4292. client->AddPendingQuestReward(quest);
  4293. }
  4294. }
  4295. }
  4296. return 0;
  4297. }
  4298. int EQ2Emu_lua_Harvest(lua_State* state) {
  4299. if (!lua_interface)
  4300. return 0;
  4301. Spawn* player = lua_interface->GetSpawn(state);
  4302. Spawn* node = lua_interface->GetSpawn(state, 2);
  4303. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4304. Client* client = ((Player*)player)->GetClient();
  4305. if (client) {
  4306. ((GroundSpawn*)node)->ProcessHarvest(client);
  4307. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4308. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4309. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4310. }
  4311. }
  4312. }
  4313. else if (player && player->IsPlayer()) {
  4314. Client* client = ((Player*)player)->GetClient();
  4315. if (client)
  4316. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4317. }
  4318. lua_interface->ResetFunctionStack(state);
  4319. return 0;
  4320. }
  4321. int EQ2Emu_lua_Bind(lua_State* state) {
  4322. if (!lua_interface)
  4323. return 0;
  4324. Spawn* spawn = lua_interface->GetSpawn(state);
  4325. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4326. float x = lua_interface->GetFloatValue(state, 3);
  4327. float y = lua_interface->GetFloatValue(state, 4);
  4328. float z = lua_interface->GetFloatValue(state, 5);
  4329. float h = lua_interface->GetFloatValue(state, 6);
  4330. lua_interface->ResetFunctionStack(state);
  4331. if (!spawn) {
  4332. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4333. return 0;
  4334. }
  4335. if (!spawn->IsPlayer()) {
  4336. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4337. return 0;
  4338. }
  4339. if (zone_id == 0) {
  4340. Client* client = ((Player*)spawn)->GetClient();
  4341. if (!client) {
  4342. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4343. return 0;
  4344. }
  4345. if (!client->Bind())
  4346. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4347. }
  4348. else {
  4349. Player* player = (Player*)spawn;
  4350. player->GetPlayerInfo()->SetBindZone(zone_id);
  4351. player->GetPlayerInfo()->SetBindX(x);
  4352. player->GetPlayerInfo()->SetBindY(y);
  4353. player->GetPlayerInfo()->SetBindZ(z);
  4354. player->GetPlayerInfo()->SetBindHeading(h);
  4355. }
  4356. return 0;
  4357. }
  4358. int EQ2Emu_lua_Gate(lua_State* state) {
  4359. if (!lua_interface)
  4360. return 0;
  4361. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4362. Spawn* spawn = lua_interface->GetSpawn(state);
  4363. lua_interface->ResetFunctionStack(state);
  4364. if (spawn) {
  4365. if (spawn->IsPlayer()) {
  4366. Client* client = ((Player*)spawn)->GetClient();
  4367. if (client) {
  4368. if (!client->Gate((spell != nullptr) ? true : false))
  4369. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4370. }
  4371. }
  4372. }
  4373. return 0;
  4374. }
  4375. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4376. if (!lua_interface)
  4377. return 0;
  4378. bool ret = false;
  4379. Spawn* spawn = lua_interface->GetSpawn(state);
  4380. lua_interface->ResetFunctionStack(state);
  4381. if (spawn) {
  4382. if (spawn->IsPlayer()) {
  4383. Client* client = ((Player*)spawn)->GetClient();
  4384. if (client)
  4385. ret = client->BindAllowed();
  4386. }
  4387. }
  4388. lua_interface->SetBooleanValue(state, ret);
  4389. return 1;
  4390. }
  4391. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4392. if (!lua_interface)
  4393. return 0;
  4394. bool ret = false;
  4395. Spawn* spawn = lua_interface->GetSpawn(state);
  4396. lua_interface->ResetFunctionStack(state);
  4397. if (spawn) {
  4398. if (spawn->IsPlayer()) {
  4399. Client* client = ((Player*)spawn)->GetClient();
  4400. ZoneServer* zone = lua_interface->GetZone(state);
  4401. if (client && zone){
  4402. ret = zone->GetCanGate();
  4403. }
  4404. }
  4405. }
  4406. lua_interface->SetBooleanValue(state, ret);
  4407. return 1;
  4408. }
  4409. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4410. Spawn* spawn = lua_interface->GetSpawn(state);
  4411. lua_interface->ResetFunctionStack(state);
  4412. if (spawn) {
  4413. lua_interface->SetBooleanValue(state, spawn->Alive());
  4414. return 1;
  4415. }
  4416. return 0;
  4417. }
  4418. int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
  4419. ZoneServer* zone = lua_interface->GetZone(state);
  4420. int32 group_id = lua_interface->GetInt32Value(state, 2);
  4421. lua_interface->ResetFunctionStack(state);
  4422. if (zone) {
  4423. lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
  4424. return 1;
  4425. }
  4426. return 0;
  4427. }
  4428. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4429. if (!lua_interface)
  4430. return 0;
  4431. Spawn* spawn = lua_interface->GetSpawn(state);
  4432. lua_interface->ResetFunctionStack(state);
  4433. if (spawn && spawn->IsEntity()) {
  4434. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4435. return 1;
  4436. }
  4437. return 0;
  4438. }
  4439. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4440. Spawn* spawn = lua_interface->GetSpawn(state);
  4441. string message = lua_interface->GetStringValue(state, 2);
  4442. string color_str = lua_interface->GetStringValue(state, 3);
  4443. lua_interface->ResetFunctionStack(state);
  4444. int8 color = CHANNEL_NARRATIVE;
  4445. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4446. Client* client = ((Player*)spawn)->GetClient();
  4447. if (client) {
  4448. if (color_str.length() > 0) {
  4449. // leave for backwards compat, but all future should just use the number
  4450. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4451. color = CHANNEL_COLOR_RED;
  4452. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4453. color = CHANNEL_COLOR_YELLOW;
  4454. else
  4455. {
  4456. // use a number to specify the channel as per Commands/Commands.h defines
  4457. color = (int8)atoul(color_str.c_str());
  4458. }
  4459. }
  4460. client->SimpleMessage(color, message.c_str());
  4461. }
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4466. Spawn* spawn = lua_interface->GetSpawn(state);
  4467. string message = lua_interface->GetStringValue(state, 2);
  4468. int8 red = lua_interface->GetInt8Value(state, 3);
  4469. int8 green = lua_interface->GetInt8Value(state, 4);
  4470. int8 blue = lua_interface->GetInt8Value(state, 5);
  4471. lua_interface->ResetFunctionStack(state);
  4472. if (!spawn) {
  4473. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4474. return 0;
  4475. }
  4476. if (!spawn->IsPlayer()) {
  4477. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4478. return 0;
  4479. }
  4480. int32 words = ::CountWordsInString(message.c_str());
  4481. if (words < 5)
  4482. words = 5;
  4483. Client* client = ((Player*)spawn)->GetClient();
  4484. if (client)
  4485. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4486. return 0;
  4487. }
  4488. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4489. Spawn* spawn = lua_interface->GetSpawn(state);
  4490. int8 param = lua_interface->GetInt8Value(state, 2);
  4491. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4492. int8 value = lua_interface->GetInt8Value(state, 4);
  4493. lua_interface->ResetFunctionStack(state);
  4494. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4495. Client* client = ((Player*)spawn)->GetClient();
  4496. if (client) {
  4497. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4498. switch (param) {
  4499. case 1: {
  4500. packet->setDataByName("parameter1", param_value);
  4501. break;
  4502. }
  4503. case 2: {
  4504. packet->setDataByName("parameter2", param_value);
  4505. break;
  4506. }
  4507. case 3: {
  4508. packet->setDataByName("parameter3", param_value);
  4509. break;
  4510. }
  4511. case 4: {
  4512. packet->setDataByName("parameter4", param_value);
  4513. break;
  4514. }
  4515. case 5: {
  4516. packet->setDataByName("parameter5", param_value);
  4517. break;
  4518. }
  4519. }
  4520. packet->setDataByName("value", value);
  4521. client->QueuePacket(packet->serialize());
  4522. safe_delete(packet);
  4523. }
  4524. }
  4525. return 0;
  4526. }
  4527. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4528. Spawn* spawn = lua_interface->GetSpawn(state);
  4529. lua_interface->ResetFunctionStack(state);
  4530. if (spawn && spawn->IsPlayer()) {
  4531. if (((Player*)spawn)->GetIsTracking())
  4532. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4533. else
  4534. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4535. }
  4536. return 0;
  4537. }
  4538. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4539. Spawn* player = lua_interface->GetSpawn(state);
  4540. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4541. string name = lua_interface->GetStringValue(state, 3);
  4542. float distance = lua_interface->GetFloatValue(state, 4);
  4543. string command = lua_interface->GetStringValue(state, 5);
  4544. string error_text = lua_interface->GetStringValue(state, 6);
  4545. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4546. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4547. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4548. lua_interface->ResetFunctionStack(state);
  4549. if (spawn) {
  4550. if (distance == 0)
  4551. distance = 10.0f;
  4552. if (command.length() == 0)
  4553. command = name;
  4554. if (command.length() < 1 && name.length() < 1)
  4555. {
  4556. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4557. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4558. spawn->RemovePrimaryCommands();
  4559. }
  4560. else
  4561. {
  4562. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4563. }
  4564. }
  4565. return 0;
  4566. }
  4567. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4568. if (!lua_interface)
  4569. return 0;
  4570. Spawn* player = lua_interface->GetSpawn(state);
  4571. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4572. int16 tier = lua_interface->GetInt16Value(state, 3);
  4573. lua_interface->ResetFunctionStack(state);
  4574. if (player && player->IsPlayer()) {
  4575. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4576. return 1;
  4577. }
  4578. return 0;
  4579. }
  4580. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4581. if (!lua_interface)
  4582. return 0;
  4583. Spawn* player = lua_interface->GetSpawn(state);
  4584. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4585. int16 tier = lua_interface->GetInt16Value(state, 3);
  4586. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4587. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4588. bool add_to_hotbar = true;
  4589. if (num_args > 4) {
  4590. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4591. }
  4592. lua_interface->ResetFunctionStack(state);
  4593. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4594. if (player && spell && player->IsPlayer()) {
  4595. Client* client = player->GetClient();
  4596. if (client) {
  4597. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4598. {
  4599. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4600. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4601. client->GetPlayer()->UnlockSpell(spell);
  4602. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4603. }
  4604. else
  4605. {
  4606. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4607. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4608. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4609. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4610. client->GetPlayer()->UnlockSpell(spell);
  4611. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4612. }
  4613. //if (client ) {
  4614. // ((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);
  4615. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4616. if (outapp)
  4617. client->QueuePacket(outapp);
  4618. }
  4619. }
  4620. return 0;
  4621. }
  4622. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4623. if (!lua_interface)
  4624. return 0;
  4625. Spawn* player = lua_interface->GetSpawn(state);
  4626. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4627. lua_interface->ResetFunctionStack(state);
  4628. if (player && player->IsPlayer()) {
  4629. Client* client = player->GetClient();
  4630. if (client) {
  4631. ((Player*)player)->DeleteSpellBook(type_selection);
  4632. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4633. if (outapp)
  4634. client->QueuePacket(outapp);
  4635. }
  4636. }
  4637. return 0;
  4638. }
  4639. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4640. if (!lua_interface)
  4641. return 0;
  4642. Spawn* player = lua_interface->GetSpawn(state);
  4643. lua_interface->ResetFunctionStack(state);
  4644. if (player && player->IsPlayer()) {
  4645. Client* client = player->GetClient();
  4646. if (client) {
  4647. client->SendNewAdventureSpells();
  4648. }
  4649. }
  4650. return 0;
  4651. }
  4652. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4653. if (!lua_interface)
  4654. return 0;
  4655. Spawn* player = lua_interface->GetSpawn(state);
  4656. lua_interface->ResetFunctionStack(state);
  4657. if (player && player->IsPlayer()) {
  4658. Client* client = player->GetClient();
  4659. if (client) {
  4660. client->SendNewTradeskillSpells();
  4661. }
  4662. }
  4663. return 0;
  4664. }
  4665. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4666. if (!lua_interface)
  4667. return 0;
  4668. Spawn* player = lua_interface->GetSpawn(state);
  4669. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4670. lua_interface->ResetFunctionStack(state);
  4671. if (player && player->IsPlayer()) {
  4672. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4673. Client* client = player->GetClient();
  4674. if (sbe && client) {
  4675. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4676. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4677. if (outapp)
  4678. client->QueuePacket(outapp);
  4679. }
  4680. }
  4681. return 0;
  4682. }
  4683. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4684. if (!lua_interface)
  4685. return 0;
  4686. Spawn* player = lua_interface->GetSpawn(state);
  4687. lua_interface->ResetFunctionStack(state);
  4688. if (player && player->IsPlayer()) {
  4689. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4690. return 1;
  4691. }
  4692. return 0;
  4693. }
  4694. int EQ2Emu_lua_Attack(lua_State* state) {
  4695. if (lua_interface) {
  4696. Spawn* npc = lua_interface->GetSpawn(state);
  4697. Spawn* player = lua_interface->GetSpawn(state, 2);
  4698. lua_interface->ResetFunctionStack(state);
  4699. if (npc && player && npc->IsNPC() && player->IsEntity())
  4700. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4701. }
  4702. return 0;
  4703. }
  4704. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4705. if (lua_interface) {
  4706. Spawn* target = lua_interface->GetSpawn(state);
  4707. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4708. lua_interface->ResetFunctionStack(state);
  4709. if (target && target->GetZone())
  4710. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4711. }
  4712. return 0;
  4713. }
  4714. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4715. Spawn* player;
  4716. if (lua_interface) {
  4717. player = lua_interface->GetSpawn(state);
  4718. lua_interface->ResetFunctionStack(state);
  4719. if (player && player->IsPlayer()) {
  4720. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4721. return 1;
  4722. }
  4723. }
  4724. return 0;
  4725. }
  4726. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4727. Spawn* player;
  4728. Client* client;
  4729. if (lua_interface) {
  4730. player = lua_interface->GetSpawn(state);
  4731. lua_interface->ResetFunctionStack(state);
  4732. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4733. if ((client = ((Player*)player)->GetClient()))
  4734. client->HandInCollections();
  4735. }
  4736. return 0;
  4737. }
  4738. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4739. Spawn* widget;
  4740. if (lua_interface) {
  4741. widget = lua_interface->GetSpawn(state);
  4742. lua_interface->ResetFunctionStack(state);
  4743. if (widget && widget->IsWidget())
  4744. ((Widget*)widget)->HandleUse(nullptr, "");
  4745. }
  4746. return 0;
  4747. }
  4748. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4749. Spawn* spawn = 0;
  4750. int32 primary_list = 0;
  4751. int32 secondary_list = 0;
  4752. if (lua_interface) {
  4753. spawn = lua_interface->GetSpawn(state);
  4754. primary_list = lua_interface->GetInt32Value(state, 2);
  4755. secondary_list = lua_interface->GetInt32Value(state, 3);
  4756. lua_interface->ResetFunctionStack(state);
  4757. if (!spawn->IsNPC()) {
  4758. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4759. return 0;
  4760. }
  4761. NPC* npc = (NPC*)spawn;
  4762. npc->SetPrimarySpellList(primary_list);
  4763. npc->SetSecondarySpellList(secondary_list);
  4764. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4765. }
  4766. return 0;
  4767. }
  4768. int EQ2Emu_lua_GetPet(lua_State* state) {
  4769. if (!lua_interface)
  4770. return 0;
  4771. Spawn* spawn = lua_interface->GetSpawn(state);
  4772. lua_interface->ResetFunctionStack(state);
  4773. if (spawn) {
  4774. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4775. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4776. return 1;
  4777. }
  4778. }
  4779. return 0;
  4780. }
  4781. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4782. if (!lua_interface)
  4783. return 0;
  4784. Spawn* spawn = lua_interface->GetSpawn(state);
  4785. lua_interface->ResetFunctionStack(state);
  4786. if (spawn) {
  4787. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4788. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4789. return 1;
  4790. }
  4791. }
  4792. return 0;
  4793. }
  4794. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4795. if (!lua_interface)
  4796. return 0;
  4797. Spawn* spawn = lua_interface->GetSpawn(state);
  4798. lua_interface->ResetFunctionStack(state);
  4799. if (spawn) {
  4800. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4801. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4802. return 1;
  4803. }
  4804. }
  4805. return 0;
  4806. }
  4807. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4808. if (!lua_interface)
  4809. return 0;
  4810. Spawn* spawn = lua_interface->GetSpawn(state);
  4811. lua_interface->ResetFunctionStack(state);
  4812. if (spawn) {
  4813. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4814. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4815. return 1;
  4816. }
  4817. }
  4818. return 0;
  4819. }
  4820. int EQ2Emu_lua_Charm(lua_State* state) {
  4821. if (!lua_interface)
  4822. return 0;
  4823. Spawn* owner = lua_interface->GetSpawn(state);
  4824. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4825. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4826. lua_interface->ResetFunctionStack(state);
  4827. if (!luaspell) {
  4828. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4829. return 0;
  4830. }
  4831. if(luaspell->resisted) {
  4832. return 0;
  4833. }
  4834. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4835. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4836. pet->SetPet(true);
  4837. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4838. ((NPC*)pet)->SetOwner((Entity*)owner);
  4839. // If owner is player and player does not have a summoned pet set the players charsheet
  4840. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4841. Player* player = (Player*)owner;
  4842. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4843. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4844. player->GetInfoStruct()->set_pet_movement(2);
  4845. player->GetInfoStruct()->set_pet_behavior(3);
  4846. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4847. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4848. // Make sure the values get sent to the client
  4849. player->SetCharSheetChanged(true);
  4850. }
  4851. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4852. pet->SetSpawnScript("");
  4853. // Set faction to the same as the owner
  4854. pet->SetFactionID(owner->GetFactionID());
  4855. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4856. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4857. // Clear hate list
  4858. ((NPC*)pet)->Brain()->ClearHate();
  4859. // Set the brain to a pet brain
  4860. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4861. }
  4862. return 0;
  4863. }
  4864. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4865. if (!lua_interface)
  4866. return 0;
  4867. Spawn* spawn = lua_interface->GetSpawn(state);
  4868. lua_interface->ResetFunctionStack(state);
  4869. if (!spawn) {
  4870. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4871. return 0;
  4872. }
  4873. vector<Spawn*> groupMembers;
  4874. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4875. groupMembers = *spawn->GetSpawnGroup();
  4876. }
  4877. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4878. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4879. deque<GroupMemberInfo*>::iterator itr;
  4880. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4881. if (group)
  4882. {
  4883. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4884. deque<GroupMemberInfo*>* members = group->GetMembers();
  4885. GroupMemberInfo* info = 0;
  4886. for (itr = members->begin(); itr != members->end(); itr++) {
  4887. info = *itr;
  4888. if (info->client)
  4889. groupMembers.push_back(info->client->GetPlayer());
  4890. }
  4891. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4892. }
  4893. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4894. }
  4895. else
  4896. return 0;
  4897. lua_createtable(state, groupMembers.size(), 0);
  4898. int newTable = lua_gettop(state);
  4899. for (int32 i = 0; i < groupMembers.size(); i++) {
  4900. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4901. lua_rawseti(state, newTable, i + 1);
  4902. }
  4903. return 1;
  4904. }
  4905. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4906. if (!lua_interface)
  4907. return 0;
  4908. lua_interface->ResetFunctionStack(state);
  4909. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4910. lua_interface->SetOptionWindowValue(state, option_window);
  4911. return 1;
  4912. }
  4913. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4914. if (!lua_interface)
  4915. return 0;
  4916. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4917. if (option_window) {
  4918. OptionWindowOption option_window_option;
  4919. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4920. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4921. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4922. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4923. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4924. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4925. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4926. option_window->push_back(option_window_option);
  4927. }
  4928. lua_interface->ResetFunctionStack(state);
  4929. return 0;
  4930. }
  4931. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4932. if (!lua_interface)
  4933. return 0;
  4934. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4935. Spawn* player = lua_interface->GetSpawn(state, 2);
  4936. string window_title = lua_interface->GetStringValue(state, 3);
  4937. string cancel_command = lua_interface->GetStringValue(state, 4);
  4938. lua_interface->ResetFunctionStack(state);
  4939. if (!player->IsPlayer()) {
  4940. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4941. return 0;
  4942. }
  4943. Client* client = ((Player*)player)->GetClient();
  4944. if (option_window && window_title.length() > 0 && client) {
  4945. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4946. if (!packet)
  4947. return 0;
  4948. packet->setDataByName("title_text", window_title.c_str());
  4949. if (cancel_command.length() > 0)
  4950. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4951. packet->setArrayLengthByName("num_selections", option_window->size());
  4952. vector<OptionWindowOption>::iterator itr;
  4953. int8 i = 0;
  4954. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4955. OptionWindowOption opt = *itr;
  4956. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4957. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4958. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4959. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4960. if (opt.optionCommand.length() > 0)
  4961. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4962. if (opt.optionConfirmTitle.length() > 0)
  4963. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4964. i++;
  4965. }
  4966. client->QueuePacket(packet->serialize());
  4967. lua_interface->SetLuaUserDataStale(option_window);
  4968. safe_delete(option_window);
  4969. safe_delete(packet);
  4970. }
  4971. return 0;
  4972. }
  4973. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4974. if (!lua_interface)
  4975. return 0;
  4976. Spawn* spawn = lua_interface->GetSpawn(state);
  4977. lua_interface->ResetFunctionStack(state);
  4978. if (spawn) {
  4979. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4980. return 1;
  4981. }
  4982. else
  4983. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4984. return 0;
  4985. }
  4986. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4987. if (!lua_interface)
  4988. return 0;
  4989. Spawn* spawn = lua_interface->GetSpawn(state);
  4990. lua_interface->ResetFunctionStack(state);
  4991. if (spawn) {
  4992. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4993. return 1;
  4994. }
  4995. else
  4996. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4997. return 0;
  4998. }
  4999. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  5000. if (!lua_interface)
  5001. return 0;
  5002. Spawn* spawn = lua_interface->GetSpawn(state);
  5003. lua_interface->ResetFunctionStack(state);
  5004. if (spawn) {
  5005. int8 class_id = spawn->GetTradeskillClass();
  5006. // Need to add 42 for the offset in the array
  5007. class_id += 44;
  5008. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  5009. return 1;
  5010. }
  5011. else
  5012. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  5013. return 0;
  5014. }
  5015. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  5016. if (!lua_interface)
  5017. return 0;
  5018. Spawn* spawn = lua_interface->GetSpawn(state);
  5019. int16 level = lua_interface->GetInt8Value(state, 2);
  5020. lua_interface->ResetFunctionStack(state);
  5021. if (spawn) {
  5022. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  5023. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  5024. else
  5025. spawn->SetTSLevel(level);
  5026. }
  5027. else
  5028. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  5029. return 0;
  5030. }
  5031. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  5032. if (!lua_interface)
  5033. return 0;
  5034. Spawn* spawn = lua_interface->GetSpawn(state);
  5035. int8 attackable = lua_interface->GetInt8Value(state, 2);
  5036. lua_interface->ResetFunctionStack(state);
  5037. if (spawn) {
  5038. spawn->SetAttackable(attackable);
  5039. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  5040. }
  5041. return 0;
  5042. }
  5043. int EQ2Emu_lua_SummonPet(lua_State* state) {
  5044. // Check to see if we have a valid lua_interface
  5045. if (!lua_interface)
  5046. return 0;
  5047. // Get the spawn that is getting the pet
  5048. Spawn* spawn = lua_interface->GetSpawn(state);
  5049. // Get the DB ID of the pet
  5050. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5051. // The max level the pet can gain
  5052. int8 max_level = lua_interface->GetInt8Value(state, 3);
  5053. // Get the spell that this command was called from
  5054. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5055. lua_interface->ResetFunctionStack(state);
  5056. // Check to make sure the spawn pointer is valid
  5057. if (!spawn) {
  5058. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5059. return 0;
  5060. }
  5061. // Check to make sure the spawn is an entity
  5062. if (!spawn->IsEntity()) {
  5063. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5064. return 0;
  5065. }
  5066. // Check to make sure the spawn doesn't already have a pet of this type
  5067. if (((Entity*)spawn)->GetPet()) {
  5068. if (spawn->IsPlayer()) {
  5069. Client* client = ((Player*)spawn)->GetClient();
  5070. if (client)
  5071. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5072. }
  5073. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5074. return 0;
  5075. }
  5076. // Check to see if the DB ID for the pet is set
  5077. if (pet_id == 0) {
  5078. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5079. return 0;
  5080. }
  5081. // Check to see if the pointer to the spell is valid
  5082. if (!luaspell) {
  5083. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5084. return 0;
  5085. }
  5086. if(luaspell->resisted) {
  5087. return 0;
  5088. }
  5089. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5090. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5091. if (!pet) {
  5092. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5093. return 0;
  5094. }
  5095. // Check to make sure the pet is an npc
  5096. if (!pet->IsNPC()) {
  5097. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5098. return 0;
  5099. }
  5100. // Spawn the pet at the same location as the owner
  5101. pet->SetX(spawn->GetX());
  5102. pet->SetY(spawn->GetY());
  5103. pet->SetZ(spawn->GetZ());
  5104. pet->SetLocation(spawn->GetLocation());
  5105. pet->SetHeading(spawn->GetHeading());
  5106. std::string petName = std::string("");
  5107. if(spawn->IsEntity()) {
  5108. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5109. }
  5110. if(petName.size() < 1) {
  5111. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5112. petName = spawn->GetZone()->pet_names.at(rand_index);
  5113. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5114. }
  5115. // If player set various values for the char sheet (pet window)
  5116. if (spawn->IsPlayer()) {
  5117. Player* player = (Player*)spawn;
  5118. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5119. player->GetInfoStruct()->set_pet_name(petName);
  5120. player->GetInfoStruct()->set_pet_movement(2);
  5121. player->GetInfoStruct()->set_pet_behavior(3);
  5122. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5123. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5124. // Make sure the values get sent to the client
  5125. player->SetCharSheetChanged(true);
  5126. }
  5127. // Set the pets name
  5128. pet->SetName(petName.c_str());
  5129. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5130. if (max_level > 0)
  5131. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5132. else
  5133. pet->SetLevel(spawn->GetLevel());
  5134. // Set the max level this pet can reach
  5135. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5136. ((NPC*)pet)->UpdateWeapons();
  5137. // Set the faction of the pet to the same faction as the owner
  5138. pet->SetFactionID(spawn->GetFactionID());
  5139. // Set the spawn as a pet
  5140. pet->SetPet(true);
  5141. // Give a pointer of the owner to the pet
  5142. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5143. // Give a pointer of the pet to the owner
  5144. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5145. // Set the pet type
  5146. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5147. // Set the spell id used to create this pet
  5148. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5149. // Set the spell tier used to create this pet
  5150. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5151. // Set the pets spawn type to 6
  5152. pet->SetSpawnType(6);
  5153. // Set the pets brain
  5154. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5155. // Check to see if the pet has a subtitle
  5156. if (strlen(pet->GetSubTitle()) > 0) {
  5157. // Add the players name to the front of the sub title
  5158. string pet_subtitle;
  5159. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5160. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5161. // Set the pets subtitle to the new one
  5162. pet->SetSubTitle(pet_subtitle.c_str());
  5163. }
  5164. // Add the "Pet Options" entity command to the pet
  5165. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5166. const char* spawn_script = world.GetSpawnScript(pet_id);
  5167. bool runScript = false;
  5168. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5169. runScript = true;
  5170. pet->SetSpawnScript(string(spawn_script));
  5171. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5172. }
  5173. spawn->GetZone()->AddSpawn(pet);
  5174. if(runScript){
  5175. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5176. }
  5177. // Set the pet as the return value for this function
  5178. lua_interface->SetSpawnValue(state, pet);
  5179. return 1;
  5180. }
  5181. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5182. if (!lua_interface)
  5183. return 0;
  5184. Spawn* spawn = lua_interface->GetSpawn(state);
  5185. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5186. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5187. lua_interface->ResetFunctionStack(state);
  5188. if (!spawn) {
  5189. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. if (!spawn->IsEntity()) {
  5193. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. if (((Entity*)spawn)->GetDeityPet()) {
  5197. if (spawn->IsPlayer()) {
  5198. Client* client = ((Player*)spawn)->GetClient();
  5199. if (client)
  5200. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5201. }
  5202. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5203. return 0;
  5204. }
  5205. if (pet_id == 0) {
  5206. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5207. return 0;
  5208. }
  5209. if (!luaspell) {
  5210. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5211. return 0;
  5212. }
  5213. if(luaspell->resisted) {
  5214. return 0;
  5215. }
  5216. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5217. if (!pet) {
  5218. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5219. return 0;
  5220. }
  5221. if (!pet->IsNPC()) {
  5222. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5223. return 0;
  5224. }
  5225. pet->SetX(spawn->GetX());
  5226. pet->SetY(spawn->GetY());
  5227. pet->SetZ(spawn->GetZ());
  5228. pet->SetLocation(spawn->GetLocation());
  5229. pet->SetHeading(spawn->GetHeading());
  5230. spawn->GetZone()->AddSpawn(pet);
  5231. string random_pet_name;
  5232. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5233. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5234. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5235. pet->SetName(random_pet_name.c_str());
  5236. pet->SetLevel(spawn->GetLevel());
  5237. pet->SetFactionID(spawn->GetFactionID());
  5238. pet->SetPet(true);
  5239. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5240. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5241. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5242. pet->SetSpawnType(6);
  5243. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5244. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5245. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5246. if (strlen(pet->GetSubTitle()) > 0) {
  5247. string pet_subtitle;
  5248. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5249. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5250. pet->SetSubTitle(pet_subtitle.c_str());
  5251. }
  5252. // deity and cosmetic pets are not attackable
  5253. pet->SetAttackable(false);
  5254. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5255. lua_interface->SetSpawnValue(state, pet);
  5256. return 1;
  5257. }
  5258. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5259. if (!lua_interface)
  5260. return 0;
  5261. Spawn* spawn = lua_interface->GetSpawn(state);
  5262. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5263. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5264. lua_interface->ResetFunctionStack(state);
  5265. if (!spawn) {
  5266. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5267. return 0;
  5268. }
  5269. if (!spawn->IsEntity()) {
  5270. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5271. return 0;
  5272. }
  5273. if (((Entity*)spawn)->GetCosmeticPet()) {
  5274. if (spawn->IsPlayer()) {
  5275. Client* client = ((Player*)spawn)->GetClient();
  5276. if (client)
  5277. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5278. }
  5279. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5280. return 0;
  5281. }
  5282. if (pet_id == 0) {
  5283. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. if (!luaspell) {
  5287. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5288. return 0;
  5289. }
  5290. if(luaspell->resisted) {
  5291. return 0;
  5292. }
  5293. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5294. if (!pet) {
  5295. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5296. return 0;
  5297. }
  5298. if (!pet->IsNPC()) {
  5299. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5300. return 0;
  5301. }
  5302. pet->SetX(spawn->GetX());
  5303. pet->SetY(spawn->GetY());
  5304. pet->SetZ(spawn->GetZ());
  5305. pet->SetLocation(spawn->GetLocation());
  5306. pet->SetHeading(spawn->GetHeading());
  5307. spawn->GetZone()->AddSpawn(pet);
  5308. string random_pet_name;
  5309. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5310. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5311. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5312. pet->SetName(random_pet_name.c_str());
  5313. pet->SetLevel(spawn->GetLevel());
  5314. pet->SetFactionID(spawn->GetFactionID());
  5315. pet->SetPet(true);
  5316. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5317. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5318. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5319. pet->SetSpawnType(6);
  5320. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5321. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5322. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5323. if (strlen(pet->GetSubTitle()) > 0) {
  5324. string pet_subtitle;
  5325. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5326. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5327. pet->SetSubTitle(pet_subtitle.c_str());
  5328. }
  5329. pet->SetAttackable(false);
  5330. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5331. lua_interface->SetSpawnValue(state, pet);
  5332. return 1;
  5333. }
  5334. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5335. if (!lua_interface)
  5336. return 0;
  5337. Spawn* spawn = lua_interface->GetSpawn(state);
  5338. lua_interface->ResetFunctionStack(state);
  5339. if (!spawn) {
  5340. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5341. return 0;
  5342. }
  5343. if (!spawn->IsPet()) {
  5344. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5345. return 0;
  5346. }
  5347. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5348. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5349. return 0;
  5350. }
  5351. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5352. if (!lua_interface)
  5353. return 0;
  5354. Quest* quest = lua_interface->GetQuest(state);
  5355. if (!quest) {
  5356. 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));
  5357. lua_interface->ResetFunctionStack(state);
  5358. return 0;
  5359. }
  5360. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5361. lua_interface->ResetFunctionStack(state);
  5362. if (feather_color > 0)
  5363. quest->SetFeatherColor(feather_color);
  5364. return 0;
  5365. }
  5366. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5367. if (!lua_interface)
  5368. return 0;
  5369. Spawn* spawn = lua_interface->GetSpawn(state);
  5370. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5371. lua_interface->ResetFunctionStack(state);
  5372. if (!spawn) {
  5373. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5374. return 0;
  5375. }
  5376. if (!spawn2) {
  5377. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5378. return 0;
  5379. }
  5380. spawn->RemoveSpawnAccess(spawn2);
  5381. return 0;
  5382. }
  5383. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5384. if (!lua_interface)
  5385. return 0;
  5386. ZoneServer* zone = lua_interface->GetZone(state);
  5387. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5388. lua_interface->ResetFunctionStack(state);
  5389. if (!zone) {
  5390. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5391. return 0;
  5392. }
  5393. if (location_id == 0) {
  5394. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5395. return 0;
  5396. }
  5397. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5398. if (!location) {
  5399. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5400. return 0;
  5401. }
  5402. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  5403. Spawn* spawn = 0;
  5404. if (location->entities[rand_number]) {
  5405. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5406. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  5407. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5408. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  5409. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5410. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  5411. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5412. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  5413. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5414. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  5415. if(spawn && spawn->IsOmittedByDBFlag())
  5416. {
  5417. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5418. safe_delete(spawn);
  5419. spawn = 0;
  5420. return 0;
  5421. }
  5422. if (spawn) {
  5423. const char* script = 0;
  5424. for (int x = 0; x < 3; x++) {
  5425. switch (x) {
  5426. case 0:
  5427. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5428. break;
  5429. case 1:
  5430. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5431. break;
  5432. case 2:
  5433. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5434. break;
  5435. }
  5436. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5437. spawn->SetSpawnScript(string(script));
  5438. break;
  5439. }
  5440. }
  5441. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5442. lua_interface->SetSpawnValue(state, spawn);
  5443. return 1;
  5444. }
  5445. else {
  5446. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5447. safe_delete(spawn);
  5448. }
  5449. }
  5450. return 0;
  5451. }
  5452. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5453. if (!lua_interface)
  5454. return 0;
  5455. Spawn* caster = lua_interface->GetSpawn(state);
  5456. Spawn* target = lua_interface->GetSpawn(state, 2);
  5457. int32 id = lua_interface->GetInt32Value(state, 3);
  5458. string command = lua_interface->GetStringValue(state, 4);
  5459. lua_interface->ResetFunctionStack(state);
  5460. if (!caster) {
  5461. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. if (!target) {
  5465. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5466. return 0;
  5467. }
  5468. if (!caster->IsPlayer()) {
  5469. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5473. if (!entity_command) {
  5474. 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());
  5475. return 0;
  5476. }
  5477. Client* client = ((Player*)caster)->GetClient();
  5478. if (!client) {
  5479. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5480. return 0;
  5481. }
  5482. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5483. return 0;
  5484. }
  5485. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5486. if (!lua_interface)
  5487. return 0;
  5488. Spawn* spawn = lua_interface->GetSpawn(state);
  5489. lua_interface->ResetFunctionStack(state);
  5490. if (!spawn) {
  5491. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5492. return 0;
  5493. }
  5494. if (!spawn->IsNPC()) {
  5495. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5496. return 0;
  5497. }
  5498. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5499. return 0;
  5500. }
  5501. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5502. if (!lua_interface)
  5503. return 0;
  5504. Spawn* spawn = lua_interface->GetSpawn(state);
  5505. int16 tick = lua_interface->GetInt16Value(state, 2);
  5506. lua_interface->ResetFunctionStack(state);
  5507. if (!spawn) {
  5508. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5509. return 0;
  5510. }
  5511. if (!spawn->IsNPC()) {
  5512. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5513. return 0;
  5514. }
  5515. if (tick < 20) {
  5516. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5517. return 0;
  5518. }
  5519. ((NPC*)spawn)->Brain()->SetTick(tick);
  5520. return 0;
  5521. }
  5522. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5523. if (!lua_interface)
  5524. return 0;
  5525. Spawn* spawn = lua_interface->GetSpawn(state);
  5526. Spawn* target = lua_interface->GetSpawn(state, 2);
  5527. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5528. lua_interface->ResetFunctionStack(state);
  5529. if (!spawn) {
  5530. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5531. return 0;
  5532. }
  5533. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5534. spawn->SetFollowTarget(target, follow_distance);
  5535. return 0;
  5536. }
  5537. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5538. if (!lua_interface)
  5539. return 0;
  5540. Spawn* spawn = lua_interface->GetSpawn(state);
  5541. lua_interface->ResetFunctionStack(state);
  5542. if (!spawn) {
  5543. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. Spawn* target = spawn->GetFollowTarget();
  5547. if (target) {
  5548. lua_interface->SetSpawnValue(state, target);
  5549. return 1;
  5550. }
  5551. return 0;
  5552. }
  5553. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5554. if (!lua_interface)
  5555. return 0;
  5556. Spawn* spawn = lua_interface->GetSpawn(state);
  5557. lua_interface->ResetFunctionStack(state);
  5558. if (!spawn) {
  5559. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5560. return 0;
  5561. }
  5562. if (spawn->following)
  5563. spawn->following = false;
  5564. else
  5565. spawn->following = true;
  5566. return 0;
  5567. }
  5568. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5569. if (!lua_interface)
  5570. return 0;
  5571. Spawn* spawn = lua_interface->GetSpawn(state);
  5572. lua_interface->ResetFunctionStack(state);
  5573. if (!spawn) {
  5574. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5575. return 0;
  5576. }
  5577. lua_interface->SetBooleanValue(state, spawn->following);
  5578. return 1;
  5579. }
  5580. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5581. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5582. // I will attempt to explain how this function works for future refrence
  5583. // Fist lets make sure lua_interface is valid, if not return out
  5584. if (!lua_interface)
  5585. return 0;
  5586. // Next we grab the first 2 params same as we usually would
  5587. Spawn* spawn = lua_interface->GetSpawn(state);
  5588. string var = lua_interface->GetStringValue(state, 2);
  5589. // 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
  5590. // 1 = Spawn
  5591. // 2 = Zone
  5592. // 3 = Item
  5593. // 4 = Quest
  5594. // 5 = String
  5595. // 6 = nil (null)
  5596. int8 dataType = 0;
  5597. // Define pointers for each potential type
  5598. Spawn* spawnVal = 0;
  5599. ZoneServer* zone = 0;
  5600. Item* item = 0;
  5601. Quest* quest = 0;
  5602. string val;
  5603. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5604. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5605. // options window are also light user data be we do not handle those.
  5606. // We check with lua_islightuserdata(lua_State*, index)
  5607. if (lua_islightuserdata(state, 3)) {
  5608. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5609. // and convert it to LUAUserData*
  5610. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5611. // Check to make sure the data we got is valid, if not give an error
  5612. if (!data || !data->IsCorrectlyInitialized()) {
  5613. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5614. }
  5615. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5616. else if (data->IsSpawn()) {
  5617. spawnVal = data->spawn;
  5618. dataType = 1;
  5619. }
  5620. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5621. else if (data->IsZone()) {
  5622. zone = data->zone;
  5623. dataType = 2;
  5624. }
  5625. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5626. else if (data->IsItem()) {
  5627. item = data->item;
  5628. dataType = 3;
  5629. }
  5630. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5631. else if (data->IsQuest()) {
  5632. quest = data->quest;
  5633. dataType = 4;
  5634. }
  5635. }
  5636. // Wasn't light user data, check if it is nil(null)
  5637. else if (lua_isnil(state, 3)) {
  5638. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5639. dataType = 6;
  5640. }
  5641. // Wasn't light user data or nil (null), must be a string
  5642. else {
  5643. // Set the string and dataType variable
  5644. val = lua_interface->GetStringValue(state, 3);
  5645. dataType = 5;
  5646. }
  5647. lua_interface->ResetFunctionStack(state);
  5648. // We now have all the params, lets check to make sure they are valid
  5649. if (!spawn) {
  5650. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5651. return 0;
  5652. }
  5653. if (var.length() == 0) {
  5654. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5655. return 0;
  5656. }
  5657. if (dataType == 0) {
  5658. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5659. return 0;
  5660. }
  5661. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5662. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5663. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5664. switch (dataType) {
  5665. case 1:
  5666. // 1 = Spawn
  5667. spawn->AddTempVariable(var, spawnVal);
  5668. break;
  5669. case 2:
  5670. // 2 = Zone
  5671. spawn->AddTempVariable(var, zone);
  5672. break;
  5673. case 3:
  5674. // 3 = Item
  5675. spawn->AddTempVariable(var, item);
  5676. break;
  5677. case 4:
  5678. // 4 = Quest
  5679. spawn->AddTempVariable(var, quest);
  5680. break;
  5681. case 5:
  5682. // 5 = String
  5683. spawn->AddTempVariable(var, val);
  5684. break;
  5685. case 6:
  5686. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5687. spawn->DeleteTempVariable(var);
  5688. break;
  5689. }
  5690. // And we are done so return out
  5691. return 0;
  5692. }
  5693. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5694. if (!lua_interface)
  5695. return 0;
  5696. Spawn* spawn = lua_interface->GetSpawn(state);
  5697. string var = lua_interface->GetStringValue(state, 2);
  5698. lua_interface->ResetFunctionStack(state);
  5699. if (!spawn) {
  5700. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. if (var.length() == 0) {
  5704. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5705. return 0;
  5706. }
  5707. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5708. int8 type = spawn->GetTempVariableType(var);
  5709. Spawn* spawn2 = 0;
  5710. ZoneServer* zone = 0;
  5711. Item* item = 0;
  5712. Quest* quest = 0;
  5713. // Set the lua function return value based on the type of data the variable contains
  5714. switch (type) {
  5715. case 1:
  5716. spawn2 = spawn->GetTempVariableSpawn(var);
  5717. if (!spawn2)
  5718. return 0;
  5719. lua_interface->SetSpawnValue(state, spawn2);
  5720. break;
  5721. case 2:
  5722. zone = spawn->GetTempVariableZone(var);
  5723. if (!zone)
  5724. return 0;
  5725. lua_interface->SetZoneValue(state, zone);
  5726. break;
  5727. case 3:
  5728. item = spawn->GetTempVariableItem(var);
  5729. if (!item)
  5730. return 0;
  5731. lua_interface->SetItemValue(state, item);
  5732. break;
  5733. case 4:
  5734. quest = spawn->GetTempVariableQuest(var);
  5735. if (!quest)
  5736. return 0;
  5737. lua_interface->SetQuestValue(state, quest);
  5738. break;
  5739. case 5:
  5740. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5741. break;
  5742. default:
  5743. // Not a valid type then the variable was not set so return out
  5744. return 0;
  5745. }
  5746. // Return value was set so return out
  5747. return 1;
  5748. }
  5749. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5750. {
  5751. if (!lua_interface)
  5752. return 0;
  5753. Quest* quest = lua_interface->GetQuest(state);
  5754. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5755. string description = lua_interface->GetStringValue(state, 3);
  5756. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5757. if (!quest) {
  5758. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5759. lua_interface->ResetFunctionStack(state);
  5760. lua_interface->SetBooleanValue(state, false);
  5761. return 1;
  5762. }
  5763. if (!spawn) {
  5764. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5765. lua_interface->ResetFunctionStack(state);
  5766. lua_interface->SetBooleanValue(state, false);
  5767. return 1;
  5768. }
  5769. if (!spawn->IsPlayer()) {
  5770. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5771. lua_interface->ResetFunctionStack(state);
  5772. lua_interface->SetBooleanValue(state, false);
  5773. return 1;
  5774. }
  5775. if (item_id == 0) {
  5776. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5777. lua_interface->ResetFunctionStack(state);
  5778. lua_interface->SetBooleanValue(state, false);
  5779. return 1;
  5780. }
  5781. Client* client = ((Player*)spawn)->GetClient();
  5782. if (!client) {
  5783. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5784. lua_interface->ResetFunctionStack(state);
  5785. lua_interface->SetBooleanValue(state, false);
  5786. return 1;
  5787. }
  5788. Item* item = master_item_list.GetItem(item_id);
  5789. if (!item) {
  5790. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5791. lua_interface->ResetFunctionStack(state);
  5792. lua_interface->SetBooleanValue(state, false);
  5793. return 1;
  5794. }
  5795. Item* firstItem = new Item(item);
  5796. quest->AddTmpRewardItem(firstItem);
  5797. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5798. bool itemsAddedSuccessfully = true;
  5799. if(num_args > 4)
  5800. {
  5801. for(int8 n=5;n<num_args+1;n++)
  5802. {
  5803. int32 new_item = lua_interface->GetInt32Value(state, n);
  5804. Item* tmpItem = master_item_list.GetItem(new_item);
  5805. if(tmpItem)
  5806. {
  5807. Item* newTmpItem = new Item(tmpItem);
  5808. quest->AddTmpRewardItem(newTmpItem);
  5809. }
  5810. else
  5811. itemsAddedSuccessfully = false;
  5812. }
  5813. }
  5814. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5815. lua_interface->ResetFunctionStack(state);
  5816. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5817. return 1;
  5818. }
  5819. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5820. if (!lua_interface)
  5821. return 0;
  5822. Quest* quest = lua_interface->GetQuest(state);
  5823. lua_interface->ResetFunctionStack(state);
  5824. if (!quest) {
  5825. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5826. return 0;
  5827. }
  5828. quest->SetRepeatable(true);
  5829. return 0;
  5830. }
  5831. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5832. if (!lua_interface)
  5833. return 0;
  5834. Spawn* spawn = lua_interface->GetSpawn(state);
  5835. lua_interface->ResetFunctionStack(state);
  5836. if (!spawn) {
  5837. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5838. return 0;
  5839. }
  5840. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5841. string ret = classes.GetClassNameCase(base_class);
  5842. if (ret.length() > 0) {
  5843. lua_interface->SetStringValue(state, ret.c_str());
  5844. return 1;
  5845. }
  5846. return 0;
  5847. }
  5848. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5849. if (!lua_interface)
  5850. return 0;
  5851. Spawn* player = lua_interface->GetSpawn(state);
  5852. lua_interface->ResetFunctionStack(state);
  5853. if (player && player->IsPlayer()) {
  5854. Client* client = player->GetClient();
  5855. if (client)
  5856. client->SendWaypoints();
  5857. }
  5858. return 0;
  5859. }
  5860. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5861. if (!lua_interface)
  5862. return 0;
  5863. Spawn* player = lua_interface->GetSpawn(state);
  5864. string name = lua_interface->GetStringValue(state, 2);
  5865. int32 type = lua_interface->GetInt32Value(state, 3);
  5866. lua_interface->ResetFunctionStack(state);
  5867. if (type == 0)
  5868. type = 2;
  5869. if (name.length() > 0) {
  5870. if (player && player->IsPlayer()) {
  5871. Client* client = player->GetClient();
  5872. if (client)
  5873. client->AddWaypoint(name, type);
  5874. }
  5875. }
  5876. return 0;
  5877. }
  5878. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5879. if (!lua_interface)
  5880. return 0;
  5881. Spawn* player = lua_interface->GetSpawn(state);
  5882. string name = lua_interface->GetStringValue(state, 2);
  5883. lua_interface->ResetFunctionStack(state);
  5884. if (name.length() > 0) {
  5885. if (player && player->IsPlayer()) {
  5886. Client* client = player->GetClient();
  5887. if (client)
  5888. client->RemoveWaypoint(name);
  5889. }
  5890. }
  5891. return 0;
  5892. }
  5893. int EQ2Emu_lua_AddWard(lua_State* state) {
  5894. if (!lua_interface)
  5895. return 0;
  5896. int32 damage = lua_interface->GetInt32Value(state);
  5897. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5898. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5899. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5900. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5901. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5902. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5903. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5904. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5905. lua_interface->ResetFunctionStack(state);
  5906. if(!spell || spell->resisted) {
  5907. return 0;
  5908. }
  5909. bool ward_was_added = false;
  5910. ZoneServer* zone = spell->caster->GetZone();
  5911. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5912. for (int32 i = 0; i < spell->targets.size(); i++) {
  5913. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5914. if (!target)
  5915. continue;
  5916. if (target->IsEntity()) {
  5917. // If the ward is already active remove it
  5918. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5919. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5920. // Create new ward info
  5921. WardInfo* ward = new WardInfo;
  5922. ward->Spell = spell;
  5923. ward->BaseDamage = damage;
  5924. ward->DamageLeft = damage;
  5925. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5926. ward->keepWard = keepWard;
  5927. ward->WardType = wardType;
  5928. if (damageAbsorptionPercent > 100)
  5929. damageAbsorptionPercent = 100;
  5930. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5931. if (damageAbsorptionMaxHealthPercent > 100)
  5932. damageAbsorptionMaxHealthPercent = 100;
  5933. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5934. ward->RedirectDamagePercent = redirectDamagePercent;
  5935. ward->LastRedirectDamage = 0;
  5936. ward->LastAbsorbedDamage = 0;
  5937. ward->HitCount = 0;
  5938. spell->num_triggers = maxHitCount;
  5939. spell->had_triggers = true;
  5940. spell->cancel_after_all_triggers = false;
  5941. ward->MaxHitCount = maxHitCount;
  5942. ward->RoundTriggered = false;
  5943. if (wardType == WARD_TYPE_MAGICAL)
  5944. ward->DamageType = damageTypes;
  5945. // Add the ward to the entity
  5946. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5947. ward_was_added = true;
  5948. }
  5949. }
  5950. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5951. if (ward_was_added && spell->caster->IsPlayer()) {
  5952. spell->had_dmg_remaining = true;
  5953. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5954. }
  5955. return 0;
  5956. }
  5957. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5958. if (!lua_interface)
  5959. return 0;
  5960. int32 amount = lua_interface->GetInt32Value(state);
  5961. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5962. lua_interface->ResetFunctionStack(state);
  5963. WardInfo* ward = 0;
  5964. if(!spell || spell->resisted) {
  5965. return 0;
  5966. }
  5967. ZoneServer* zone = spell->caster->GetZone();
  5968. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5969. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5970. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5971. ward = target->GetWard(spell->spell->GetSpellID());
  5972. if (target && ward) {
  5973. ward->DamageLeft += amount;
  5974. if (ward->DamageLeft > ward->BaseDamage)
  5975. ward->DamageLeft = ward->BaseDamage;
  5976. for (int32 i = 0; i < spell->targets.size(); i++) {
  5977. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5978. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5979. }
  5980. }
  5981. }
  5982. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5983. if (ward && spell->caster->IsPlayer())
  5984. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5985. return 0;
  5986. }
  5987. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5988. if (!lua_interface)
  5989. return 0;
  5990. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5991. lua_interface->ResetFunctionStack(state);
  5992. if (!spell) {
  5993. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5997. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5998. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5999. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  6000. if (ward) {
  6001. lua_interface->SetInt32Value(state, ward->DamageLeft);
  6002. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6003. return 1;
  6004. }
  6005. }
  6006. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6007. return 0;
  6008. }
  6009. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  6010. if (!lua_interface)
  6011. return 0;
  6012. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6013. if (!spell) {
  6014. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  6015. lua_interface->ResetFunctionStack(state);
  6016. return 0;
  6017. }
  6018. string type = lua_interface->GetStringValue(state, 2);
  6019. lua_interface->ResetFunctionStack(state);
  6020. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6021. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  6022. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  6023. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  6024. if (ward) {
  6025. if (boost::iequals(type, "damageleft"))
  6026. lua_interface->SetInt32Value(state, ward->DamageLeft);
  6027. else if (boost::iequals(type, "basedamage"))
  6028. lua_interface->SetInt32Value(state, ward->BaseDamage);
  6029. else if (boost::iequals(type, "keepward"))
  6030. lua_interface->SetBooleanValue(state, ward->keepWard);
  6031. else if (boost::iequals(type, "wardtype"))
  6032. lua_interface->SetInt32Value(state, ward->WardType);
  6033. else if (boost::iequals(type, "dmgabsorptionpct"))
  6034. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  6035. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  6036. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  6037. else if (boost::iequals(type, "redirectdamagepercent"))
  6038. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  6039. else if (boost::iequals(type, "lastredirectdamage"))
  6040. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  6041. else if (boost::iequals(type, "lastabsorbeddamage"))
  6042. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  6043. else if (boost::iequals(type, "hitcount"))
  6044. lua_interface->SetInt32Value(state, ward->HitCount);
  6045. else if (boost::iequals(type, "maxhitcount"))
  6046. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  6047. else
  6048. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  6049. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6050. return 1;
  6051. }
  6052. }
  6053. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6054. return 0;
  6055. }
  6056. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  6057. if (!lua_interface)
  6058. return 0;
  6059. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6060. lua_interface->ResetFunctionStack(state);
  6061. if(!spell) {
  6062. return 0;
  6063. }
  6064. if(!spell->caster) {
  6065. lua_interface->LogError("%s: RemoveWard error: no valid caster", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. ZoneServer* zone = spell->caster->GetZone();
  6069. if(!zone) {
  6070. lua_interface->LogError("%s: RemoveWard error: no valid zone for caster", lua_interface->GetScriptName(state));
  6071. return 0;
  6072. }
  6073. Spawn* target = 0;
  6074. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6075. for (int32 i = 0; i < spell->targets.size(); i++) {
  6076. target = zone->GetSpawnByID(spell->targets.at(i));
  6077. if (target && target->IsEntity()) {
  6078. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6079. }
  6080. }
  6081. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6082. return 0;
  6083. }
  6084. int EQ2Emu_lua_Interrupt(lua_State* state)
  6085. {
  6086. if (!lua_interface)
  6087. return 0;
  6088. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6089. Spawn* target = lua_interface->GetSpawn(state, 2);
  6090. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6091. lua_interface->ResetFunctionStack(state);
  6092. if (!caster)
  6093. {
  6094. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6095. return 0;
  6096. }
  6097. if (!target)
  6098. {
  6099. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!spell) {
  6103. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. if (!target->IsEntity() && !spell)
  6107. {
  6108. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6109. return 0;
  6110. }
  6111. if (!target && spell) {
  6112. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6113. for (int8 i = 0; i < spell->targets.size(); i++) {
  6114. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6115. if (!target || !target->IsEntity())
  6116. continue;
  6117. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6118. }
  6119. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6120. }
  6121. else
  6122. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6123. return 0;
  6124. }
  6125. int EQ2Emu_lua_Stealth(lua_State* state) {
  6126. if (!lua_interface)
  6127. return 0;
  6128. int8 type = lua_interface->GetInt8Value(state);
  6129. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6130. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6131. lua_interface->ResetFunctionStack(state);
  6132. if (!spell) {
  6133. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. ZoneServer* zone = spell->caster->GetZone();
  6137. if (spawn) {
  6138. if (spawn->IsEntity()) {
  6139. if (type == 1) {
  6140. ((Entity*)spawn)->AddStealthSpell(spell);
  6141. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6142. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6143. }
  6144. else if (type == 2) {
  6145. ((Entity*)spawn)->AddInvisSpell(spell);
  6146. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6147. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6148. }
  6149. return 0;
  6150. }
  6151. else {
  6152. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6153. return 0;
  6154. }
  6155. }
  6156. else {
  6157. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6158. for (int32 i = 0; i < spell->targets.size(); i++) {
  6159. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6160. if (!spawn || !spawn->IsEntity())
  6161. continue;
  6162. if (type == 1) {
  6163. ((Entity*)spawn)->AddStealthSpell(spell);
  6164. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6165. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6166. }
  6167. else if (type == 2) {
  6168. ((Entity*)spawn)->AddInvisSpell(spell);
  6169. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6170. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6171. }
  6172. else {
  6173. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6174. break;
  6175. }
  6176. }
  6177. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6178. }
  6179. return 0;
  6180. }
  6181. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6182. if (!lua_interface)
  6183. return 0;
  6184. Spawn* spawn = lua_interface->GetSpawn(state);
  6185. lua_interface->ResetFunctionStack(state);
  6186. if (!spawn) {
  6187. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6188. return 0;
  6189. }
  6190. if (spawn->IsEntity()) {
  6191. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6192. return 1;
  6193. }
  6194. else
  6195. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6199. if (!lua_interface)
  6200. return 0;
  6201. Spawn* spawn = lua_interface->GetSpawn(state);
  6202. lua_interface->ResetFunctionStack(state);
  6203. if (!spawn) {
  6204. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. if (spawn->IsEntity()) {
  6208. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6209. return 1;
  6210. }
  6211. else
  6212. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6213. return 0;
  6214. }
  6215. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6216. if (!lua_interface)
  6217. return 0;
  6218. Spawn* player = lua_interface->GetSpawn(state);
  6219. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6220. lua_interface->ResetFunctionStack(state);
  6221. if (!player->IsPlayer()) {
  6222. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6226. return 1;
  6227. }
  6228. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6229. if (!lua_interface)
  6230. return 0;
  6231. Spawn* spawn = lua_interface->GetSpawn(state);
  6232. int8 slot = lua_interface->GetInt8Value(state, 2);
  6233. lua_interface->ResetFunctionStack(state);
  6234. if (!spawn) {
  6235. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (!spawn->IsEntity()) {
  6239. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6243. if (!item) {
  6244. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. lua_interface->SetItemValue(state, item);
  6248. return 1;
  6249. }
  6250. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6251. if (!lua_interface)
  6252. return 0;
  6253. Spawn* player = lua_interface->GetSpawn(state);
  6254. int32 id = lua_interface->GetInt32Value(state, 2);
  6255. lua_interface->ResetFunctionStack(state);
  6256. if (!player) {
  6257. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. if (!player->IsPlayer()) {
  6261. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6262. return 0;
  6263. }
  6264. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6265. if (!item) {
  6266. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6267. return 0;
  6268. }
  6269. lua_interface->SetItemValue(state, item);
  6270. return 1;
  6271. }
  6272. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6273. if (!lua_interface)
  6274. return 0;
  6275. Spawn* spawn = lua_interface->GetSpawn(state);
  6276. int8 slot = lua_interface->GetInt8Value(state, 2);
  6277. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6278. lua_interface->ResetFunctionStack(state);
  6279. if (!spawn) {
  6280. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. if (!spawn->IsEntity()) {
  6284. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6285. return 0;
  6286. }
  6287. Item* item = master_item_list.GetItem(item_id);
  6288. if (!item) {
  6289. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6290. return 0;
  6291. }
  6292. Item* copy = new Item(item);
  6293. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6294. if(result)
  6295. {
  6296. ((Entity*)spawn)->SetEquipment(copy, slot);
  6297. spawn->vis_changed = true;
  6298. if(spawn->IsPlayer())
  6299. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6300. }
  6301. else
  6302. {
  6303. safe_delete(copy);
  6304. }
  6305. lua_interface->SetBooleanValue(state, result);
  6306. return 1;
  6307. }
  6308. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6309. if (!lua_interface)
  6310. return 0;
  6311. Spawn* spawn = lua_interface->GetSpawn(state);
  6312. int8 slot = lua_interface->GetInt8Value(state, 2);
  6313. Item* item = lua_interface->GetItem(state, 3);
  6314. lua_interface->ResetFunctionStack(state);
  6315. if (!spawn) {
  6316. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. if (!spawn->IsEntity()) {
  6320. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6321. return 0;
  6322. }
  6323. if (!item) {
  6324. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6325. return 0;
  6326. }
  6327. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6328. if(result)
  6329. {
  6330. ((Entity*)spawn)->SetEquipment(item, slot);
  6331. spawn->vis_changed = true;
  6332. if(spawn->IsPlayer())
  6333. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6334. }
  6335. lua_interface->SetBooleanValue(state, result);
  6336. return 1;
  6337. }
  6338. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6339. if (!lua_interface)
  6340. return 0;
  6341. Spawn* spawn = lua_interface->GetSpawn(state);
  6342. int8 slot = lua_interface->GetInt8Value(state, 2);
  6343. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6344. lua_interface->ResetFunctionStack(state);
  6345. if (!spawn) {
  6346. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. if (!spawn->IsEntity()) {
  6350. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. if(slot >= NUM_SLOTS) {
  6354. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6355. return 0;
  6356. }
  6357. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6358. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6359. if(item) {
  6360. item->save_needed = true;
  6361. if(no_delete_item) {
  6362. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6363. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6364. }
  6365. else{
  6366. Client* client = ((Player*)spawn)->GetClient();
  6367. client->UnequipItem(item->details.index);
  6368. }
  6369. }
  6370. }
  6371. else
  6372. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6373. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6374. spawn->vis_changed = true;
  6375. if(spawn->IsPlayer())
  6376. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6377. lua_interface->SetBooleanValue(state, true);
  6378. return 1;
  6379. }
  6380. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6381. if (!lua_interface)
  6382. return 0;
  6383. Spawn* spawn = lua_interface->GetSpawn(state);
  6384. int8 slot = lua_interface->GetInt8Value(state, 2);
  6385. int16 type = lua_interface->GetInt16Value(state, 3);
  6386. int8 r = lua_interface->GetInt8Value(state, 4);
  6387. int8 g = lua_interface->GetInt8Value(state, 5);
  6388. int8 b = lua_interface->GetInt8Value(state, 6);
  6389. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6390. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6391. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6392. lua_interface->ResetFunctionStack(state);
  6393. if (!spawn) {
  6394. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6395. return 0;
  6396. }
  6397. if (!spawn->IsEntity()) {
  6398. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6399. return 0;
  6400. }
  6401. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6402. spawn->vis_changed = true;
  6403. lua_interface->SetBooleanValue(state, true);
  6404. return 1;
  6405. }
  6406. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Spawn* player = lua_interface->GetSpawn(state);
  6410. int32 id = lua_interface->GetInt32Value(state, 2);
  6411. int8 count = lua_interface->GetInt8Value(state, 3);
  6412. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6413. lua_interface->ResetFunctionStack(state);
  6414. if (!player) {
  6415. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6416. return 0;
  6417. }
  6418. if (!player->IsPlayer()) {
  6419. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6420. return 0;
  6421. }
  6422. if (!count)
  6423. count = 1;
  6424. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6425. if (!item) {
  6426. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. lua_interface->SetItemValue(state, item);
  6430. return 1;
  6431. }
  6432. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6433. if (!lua_interface)
  6434. return 0;
  6435. Spawn* spawn = lua_interface->GetSpawn(state);
  6436. int32 anim = lua_interface->GetInt32Value(state, 2);
  6437. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6438. int8 type = lua_interface->GetInt8Value(state, 4);
  6439. lua_interface->ResetFunctionStack(state);
  6440. if (!spawn) {
  6441. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6442. return 0;
  6443. }
  6444. if (spawn2) {
  6445. if (spawn2->IsPlayer()) {
  6446. if (type != 1 && type != 2)
  6447. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6448. else
  6449. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6450. return 0;
  6451. }
  6452. else {
  6453. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6454. return 0;
  6455. }
  6456. }
  6457. else
  6458. spawn->GetZone()->PlayAnimation(spawn, anim);
  6459. return 0;
  6460. }
  6461. int EQ2Emu_lua_IsPet(lua_State* state) {
  6462. if (!lua_interface)
  6463. return 0;
  6464. Spawn* spawn = lua_interface->GetSpawn(state);
  6465. lua_interface->ResetFunctionStack(state);
  6466. if (!spawn) {
  6467. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6468. return 0;
  6469. }
  6470. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6471. return 1;
  6472. }
  6473. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6474. if (!lua_interface)
  6475. return 0;
  6476. Spawn* spawn = lua_interface->GetSpawn(state);
  6477. lua_interface->ResetFunctionStack(state);
  6478. if (!spawn) {
  6479. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. if (!spawn->IsNPC()) {
  6483. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6484. return 0;
  6485. }
  6486. if (((NPC*)spawn)->GetOwner()) {
  6487. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6488. return 1;
  6489. }
  6490. return 0;
  6491. }
  6492. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6493. if (!lua_interface)
  6494. return 0;
  6495. Spawn* spawn = lua_interface->GetSpawn(state);
  6496. Spawn* target = lua_interface->GetSpawn(state, 2);
  6497. lua_interface->ResetFunctionStack(state);
  6498. if (!spawn) {
  6499. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6500. return 0;
  6501. }
  6502. if (!spawn) {
  6503. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6504. return 0;
  6505. }
  6506. spawn->SetTarget(target);
  6507. return 0;
  6508. }
  6509. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6510. if (!lua_interface)
  6511. return 0;
  6512. Spawn* spawn = lua_interface->GetSpawn(state);
  6513. bool val = lua_interface->GetBooleanValue(state, 2);
  6514. lua_interface->ResetFunctionStack(state);
  6515. if (!spawn) {
  6516. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6517. return 0;
  6518. }
  6519. if (!spawn->IsEntity()) {
  6520. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6521. return 0;
  6522. }
  6523. ((Entity*)spawn)->InCombat(val);
  6524. if (val) {
  6525. spawn->ClearRunningLocations();
  6526. spawn->CalculateRunningLocation(true);
  6527. }
  6528. return 0;
  6529. }
  6530. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6531. if (!lua_interface)
  6532. return 0;
  6533. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6534. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6535. lua_interface->ResetFunctionStack(state);
  6536. if (!spawn1) {
  6537. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. if (!spawn2) {
  6541. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6542. return 0;
  6543. }
  6544. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6545. return 1;
  6546. }
  6547. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6548. if (!lua_interface)
  6549. return 0;
  6550. Spawn* spawn = lua_interface->GetSpawn(state);
  6551. lua_interface->ResetFunctionStack(state);
  6552. if (!spawn) {
  6553. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. if (!spawn->IsNPC()) {
  6557. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6558. return 0;
  6559. }
  6560. ((NPC*)spawn)->ClearRunback();
  6561. return 0;
  6562. }
  6563. int EQ2Emu_lua_Runback(lua_State* state) {
  6564. if (!lua_interface)
  6565. return 0;
  6566. Spawn* spawn = lua_interface->GetSpawn(state);
  6567. lua_interface->ResetFunctionStack(state);
  6568. if (!spawn) {
  6569. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6570. return 0;
  6571. }
  6572. if (!spawn->IsNPC()) {
  6573. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6574. return 0;
  6575. }
  6576. ((NPC*)spawn)->Runback();
  6577. return 0;
  6578. }
  6579. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6580. if (!lua_interface)
  6581. return 0;
  6582. Spawn* spawn = lua_interface->GetSpawn(state);
  6583. lua_interface->ResetFunctionStack(state);
  6584. if (!spawn) {
  6585. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. if (!spawn->IsNPC()) {
  6589. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6593. return 1;
  6594. }
  6595. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6596. if (!lua_interface)
  6597. return 0;
  6598. Spawn* spawn = lua_interface->GetSpawn(state);
  6599. lua_interface->ResetFunctionStack(state);
  6600. if (!spawn) {
  6601. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. if (!spawn->IsEntity()) {
  6605. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6606. return 0;
  6607. }
  6608. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6609. return 1;
  6610. }
  6611. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6612. if (!lua_interface)
  6613. return 0;
  6614. Spawn* spawn = lua_interface->GetSpawn(state);
  6615. lua_interface->ResetFunctionStack(state);
  6616. if (!spawn) {
  6617. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6618. return 0;
  6619. }
  6620. if (!spawn->IsEntity()) {
  6621. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6625. return 1;
  6626. }
  6627. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6628. if (!lua_interface)
  6629. return 0;
  6630. Spawn* spawn = lua_interface->GetSpawn(state);
  6631. lua_interface->ResetFunctionStack(state);
  6632. if (!spawn) {
  6633. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6634. return 0;
  6635. }
  6636. if (!spawn->IsEntity()) {
  6637. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6641. return 1;
  6642. }
  6643. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6644. if (!lua_interface)
  6645. return 0;
  6646. Spawn* spawn = lua_interface->GetSpawn(state);
  6647. lua_interface->ResetFunctionStack(state);
  6648. if (!spawn) {
  6649. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6650. return 0;
  6651. }
  6652. if (!spawn->IsEntity()) {
  6653. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6654. return 0;
  6655. }
  6656. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6657. return 1;
  6658. }
  6659. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6660. if (!lua_interface)
  6661. return 0;
  6662. Spawn* spawn = lua_interface->GetSpawn(state);
  6663. Spawn* target = lua_interface->GetSpawn(state, 2);
  6664. float distance = lua_interface->GetFloatValue(state, 3);
  6665. lua_interface->ResetFunctionStack(state);
  6666. if (!spawn) {
  6667. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (!target) {
  6671. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. if (!spawn->IsNPC()) {
  6675. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. if (!target->IsEntity()) {
  6679. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6683. return 1;
  6684. }
  6685. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6686. if (!lua_interface)
  6687. return 0;
  6688. Spawn* spawn = lua_interface->GetSpawn(state);
  6689. Spawn* target = lua_interface->GetSpawn(state, 2);
  6690. float distance = lua_interface->GetFloatValue(state, 3);
  6691. lua_interface->ResetFunctionStack(state);
  6692. if (!spawn) {
  6693. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6694. return 0;
  6695. }
  6696. if (!target) {
  6697. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6698. return 0;
  6699. }
  6700. if (!spawn->IsNPC()) {
  6701. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (!target->IsEntity()) {
  6705. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6709. return 0;
  6710. }
  6711. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6712. if (!lua_interface)
  6713. return 0;
  6714. Spawn* spawn = lua_interface->GetSpawn(state);
  6715. lua_interface->ResetFunctionStack(state);
  6716. if (!spawn) {
  6717. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6718. return 0;
  6719. }
  6720. if (!spawn->IsNPC()) {
  6721. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6722. return 0;
  6723. }
  6724. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6725. return 1;
  6726. }
  6727. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6728. if (!lua_interface)
  6729. return 0;
  6730. Spawn* spawn = lua_interface->GetSpawn(state);
  6731. lua_interface->ResetFunctionStack(state);
  6732. if (!spawn) {
  6733. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6734. return 0;
  6735. }
  6736. if (!spawn->IsNPC()) {
  6737. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6738. return 0;
  6739. }
  6740. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6741. return 1;
  6742. }
  6743. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6744. if (!lua_interface)
  6745. return 0;
  6746. Spawn* spawn = lua_interface->GetSpawn(state);
  6747. lua_interface->ResetFunctionStack(state);
  6748. if (!spawn) {
  6749. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6750. return 0;
  6751. }
  6752. if (!spawn->IsNPC()) {
  6753. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6754. return 0;
  6755. }
  6756. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6757. if (hated) {
  6758. lua_interface->SetSpawnValue(state, hated);
  6759. return 1;
  6760. }
  6761. return 0;
  6762. }
  6763. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6764. if (!lua_interface)
  6765. return 0;
  6766. Spawn* spawn = lua_interface->GetSpawn(state);
  6767. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6768. lua_interface->ResetFunctionStack(state);
  6769. if (!spawn) {
  6770. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. if (!spawn->IsNPC()) {
  6774. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. if (!hated) {
  6778. ((NPC*)spawn)->Brain()->ClearHate();
  6779. return 0;
  6780. }
  6781. else
  6782. {
  6783. if (!hated->IsEntity()) {
  6784. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6785. return 0;
  6786. }
  6787. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6788. return 0;
  6789. }
  6790. return 0;
  6791. }
  6792. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6793. if (!lua_interface)
  6794. return 0;
  6795. Spawn* spawn = lua_interface->GetSpawn(state);
  6796. lua_interface->ResetFunctionStack(state);
  6797. if (!spawn) {
  6798. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6799. return 0;
  6800. }
  6801. if (!spawn->IsNPC()) {
  6802. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6803. return 0;
  6804. }
  6805. ((NPC*)spawn)->Brain()->ClearEncounter();
  6806. return 0;
  6807. }
  6808. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6809. if (!lua_interface)
  6810. return 0;
  6811. Spawn* spawn = lua_interface->GetSpawn(state);
  6812. lua_interface->ResetFunctionStack(state);
  6813. if (!spawn) {
  6814. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6815. return 0;
  6816. }
  6817. if (!spawn->IsNPC()) {
  6818. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6819. return 0;
  6820. }
  6821. // Temp list to store hate list
  6822. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6823. if (encounterList->size() == 0) {
  6824. safe_delete(encounterList);
  6825. return 0;
  6826. }
  6827. lua_createtable(state, encounterList->size(), 0);
  6828. int newTable = lua_gettop(state);
  6829. for (int32 i = 0; i < encounterList->size(); i++) {
  6830. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6831. if (temp)
  6832. lua_interface->SetSpawnValue(state, temp);
  6833. lua_rawseti(state, newTable, i + 1);
  6834. }
  6835. safe_delete(encounterList);
  6836. return 1;
  6837. }
  6838. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6839. if (!lua_interface)
  6840. return 0;
  6841. Spawn* spawn = lua_interface->GetSpawn(state);
  6842. lua_interface->ResetFunctionStack(state);
  6843. if (!spawn) {
  6844. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. if (!spawn->IsNPC()) {
  6848. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. // Temp list to store hate list
  6852. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6853. if (hateList->size() == 0) {
  6854. safe_delete(hateList);
  6855. return 0;
  6856. }
  6857. lua_createtable(state, hateList->size(), 0);
  6858. int newTable = lua_gettop(state);
  6859. for (int32 i = 0; i < hateList->size(); i++) {
  6860. lua_interface->SetSpawnValue(state, hateList->at(i));
  6861. lua_rawseti(state, newTable, i + 1);
  6862. }
  6863. safe_delete(hateList);
  6864. return 1;
  6865. }
  6866. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6867. if (!lua_interface)
  6868. return 0;
  6869. Spawn* spawn = lua_interface->GetSpawn(state);
  6870. lua_interface->ResetFunctionStack(state);
  6871. if (!spawn) {
  6872. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6873. return 0;
  6874. }
  6875. if (spawn->IsPlayer()) {
  6876. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6877. lua_interface->SetBooleanValue(state, true);
  6878. else
  6879. lua_interface->SetBooleanValue(state, false);
  6880. return 1;
  6881. }
  6882. else {
  6883. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6884. return 1;
  6885. }
  6886. }
  6887. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6888. if (!lua_interface)
  6889. return 0;
  6890. Quest* quest = lua_interface->GetQuest(state);
  6891. lua_interface->ResetFunctionStack(state);
  6892. if (!quest) {
  6893. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6894. return 0;
  6895. }
  6896. quest->SetCompletedFlag(true);
  6897. return 0;
  6898. }
  6899. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6900. if (!lua_interface)
  6901. return 0;
  6902. Spawn* spawn = lua_interface->GetSpawn(state);
  6903. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6904. int8 tier = lua_interface->GetInt8Value(state, 3);
  6905. lua_interface->ResetFunctionStack(state);
  6906. if (!spawn) {
  6907. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6908. return 0;
  6909. }
  6910. if (!spawn->IsEntity()) {
  6911. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6912. return 0;
  6913. }
  6914. if (spellID == 0) {
  6915. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6916. return 0;
  6917. }
  6918. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6919. if (effect) {
  6920. if (tier > 0) {
  6921. // If a tier was passed chec to see if it is the same as the effect
  6922. if (tier == effect->tier)
  6923. lua_interface->SetBooleanValue(state, true);
  6924. else
  6925. lua_interface->SetBooleanValue(state, false);
  6926. return 1;
  6927. }
  6928. else {
  6929. // Have an effect but no tier was passed so return true
  6930. lua_interface->SetBooleanValue(state, true);
  6931. }
  6932. return 1;
  6933. }
  6934. // no effect so return false
  6935. lua_interface->SetBooleanValue(state, false);
  6936. return 1;
  6937. }
  6938. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6939. if (!lua_interface)
  6940. return 0;
  6941. Spawn* spawn = lua_interface->GetSpawn(state);
  6942. int32 id = lua_interface->GetInt32Value(state, 2);
  6943. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6944. lua_interface->ResetFunctionStack(state);
  6945. Spawn* spawn2 = 0;
  6946. vector<Spawn*> list;
  6947. if (!spawn) {
  6948. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6949. return 0;
  6950. }
  6951. //If zone not provided, use spawn's zone
  6952. if (!zone)
  6953. zone = spawn->GetZone();
  6954. list = zone->GetSpawnsByID(id);
  6955. if (list.size() == 0) {
  6956. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6957. return 0;
  6958. }
  6959. vector<Spawn*>::iterator itr = list.begin();
  6960. for (int8 i = 0; i < list.size(); i++) {
  6961. spawn2 = itr[i];
  6962. if (spawn2)
  6963. spawn2->AddAllowAccessSpawn(spawn);
  6964. }
  6965. return 0;
  6966. }
  6967. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6968. if (!lua_interface)
  6969. return 0;
  6970. Spawn* spawn = lua_interface->GetSpawn(state);
  6971. int32 id = lua_interface->GetInt32Value(state, 2);
  6972. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6973. lua_interface->ResetFunctionStack(state);
  6974. Spawn* spawn2 = 0;
  6975. if (!spawn) {
  6976. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. //If zone not provided, use spawn's zone
  6980. if (!zone)
  6981. zone = spawn->GetZone();
  6982. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6983. vector<Spawn*>::iterator itr = list.begin();
  6984. if (list.size() == 0) {
  6985. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6986. return 0;
  6987. }
  6988. for (int8 i = 0; i < list.size(); i++) {
  6989. spawn2 = itr[i];
  6990. if (spawn2)
  6991. spawn2->RemoveSpawnAccess(spawn);
  6992. }
  6993. return 0;
  6994. }
  6995. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6996. if (!lua_interface)
  6997. return 0;
  6998. Quest* quest = lua_interface->GetQuest(state);
  6999. lua_interface->ResetFunctionStack(state);
  7000. if (!quest) {
  7001. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  7002. return 0;
  7003. }
  7004. quest->SetYellowName(true);
  7005. return 0;
  7006. }
  7007. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  7008. if (!lua_interface)
  7009. return 0;
  7010. Spawn* spawn = lua_interface->GetSpawn(state);
  7011. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7012. lua_interface->ResetFunctionStack(state);
  7013. if (!spawn) {
  7014. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  7015. return 0;
  7016. }
  7017. if (!spawn->IsPlayer()) {
  7018. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  7019. return 0;
  7020. }
  7021. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  7022. return 1;
  7023. }
  7024. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  7025. if (!lua_interface)
  7026. return 0;
  7027. Spawn* spawn = lua_interface->GetSpawn(state);
  7028. lua_interface->ResetFunctionStack(state);
  7029. if (!spawn) {
  7030. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7031. return 0;
  7032. }
  7033. if (!spawn->IsPlayer()) {
  7034. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7035. return 0;
  7036. }
  7037. ZoneServer* zone = spawn->GetZone();
  7038. if (!zone) {
  7039. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. Instance_Type iType = zone->GetInstanceType();
  7043. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7044. iType == GROUP_LOCKOUT_INSTANCE ||
  7045. iType == RAID_LOCKOUT_INSTANCE ||
  7046. iType == SOLO_PERSIST_INSTANCE ||
  7047. iType == GROUP_PERSIST_INSTANCE ||
  7048. iType == RAID_PERSIST_INSTANCE) {
  7049. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7050. if (data) {
  7051. // Check to see if the timer has already been set, if it has return out.
  7052. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  7053. return 0;
  7054. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  7055. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  7056. if(spawn->IsPlayer()) {
  7057. Client* client = ((Player*)spawn)->GetClient();
  7058. if (client) {
  7059. string time_msg = "";
  7060. int32 time = data->success_lockout_time;
  7061. int16 hour;
  7062. int8 min;
  7063. int8 sec;
  7064. hour = time / 3600;
  7065. time = time % 3600;
  7066. min = time / 60;
  7067. time = time % 60;
  7068. sec = time;
  7069. if (hour > 0) {
  7070. char temp[10];
  7071. sprintf(temp, " %i", hour);
  7072. time_msg.append(temp);
  7073. time_msg.append(" hour");
  7074. time_msg.append((hour > 1) ? "s" : "");
  7075. }
  7076. if (min > 0) {
  7077. char temp[5];
  7078. sprintf(temp, " %i", min);
  7079. time_msg.append(temp);
  7080. time_msg.append(" minute");
  7081. time_msg.append((min > 1) ? "s" : "");
  7082. }
  7083. // Only add seconds if minutes and hours are 0
  7084. if (hour == 0 && min == 0 && sec > 0) {
  7085. char temp[5];
  7086. sprintf(temp, " %i", sec);
  7087. time_msg.append(temp);
  7088. time_msg.append(" second");
  7089. time_msg.append((sec > 1) ? "s" : "");
  7090. }
  7091. 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());
  7092. }
  7093. else {
  7094. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7095. }
  7096. }
  7097. }
  7098. else
  7099. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7100. }
  7101. else
  7102. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7103. return 0;
  7104. }
  7105. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7106. if (!lua_interface)
  7107. return 0;
  7108. Spawn* spawn = lua_interface->GetSpawn(state);
  7109. lua_interface->ResetFunctionStack(state);
  7110. if (!spawn) {
  7111. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. if (!spawn->IsPlayer()) {
  7115. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7116. return 0;
  7117. }
  7118. ZoneServer* zone = spawn->GetZone();
  7119. if (!zone) {
  7120. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7121. return 0;
  7122. }
  7123. Instance_Type iType = zone->GetInstanceType();
  7124. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7125. iType == GROUP_LOCKOUT_INSTANCE ||
  7126. iType == RAID_LOCKOUT_INSTANCE ||
  7127. iType == SOLO_PERSIST_INSTANCE ||
  7128. iType == GROUP_PERSIST_INSTANCE ||
  7129. iType == RAID_PERSIST_INSTANCE) {
  7130. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7131. if (data) {
  7132. // Check to see if the timer has already been set, if it has return out.
  7133. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7134. return 0;
  7135. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7136. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7137. if(spawn->IsPlayer()) {
  7138. Client* client = ((Player*)spawn)->GetClient();
  7139. if (client) {
  7140. string time_msg = "";
  7141. int32 time = data->failure_lockout_time;
  7142. int16 hour;
  7143. int8 min;
  7144. int8 sec;
  7145. hour = time / 3600;
  7146. time = time % 3600;
  7147. min = time / 60;
  7148. time = time % 60;
  7149. sec = time;
  7150. if (hour > 0) {
  7151. char temp[10];
  7152. sprintf(temp, " %i", hour);
  7153. time_msg.append(temp);
  7154. time_msg.append(" hour");
  7155. time_msg.append((hour > 1) ? "s" : "");
  7156. }
  7157. if (min > 0) {
  7158. char temp[5];
  7159. sprintf(temp, " %i", min);
  7160. time_msg.append(temp);
  7161. time_msg.append(" minute");
  7162. time_msg.append((min > 1) ? "s" : "");
  7163. }
  7164. // Only add seconds if minutes and hours are 0
  7165. if (hour == 0 && min == 0 && sec > 0) {
  7166. char temp[5];
  7167. sprintf(temp, " %i", sec);
  7168. time_msg.append(temp);
  7169. time_msg.append(" second");
  7170. time_msg.append((sec > 1) ? "s" : "");
  7171. }
  7172. 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());
  7173. }
  7174. }
  7175. else {
  7176. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7177. }
  7178. }
  7179. else
  7180. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7181. }
  7182. else
  7183. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7184. return 0;
  7185. }
  7186. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7187. if (!lua_interface)
  7188. return 0;
  7189. Spawn* spawn = lua_interface->GetSpawn(state);
  7190. lua_interface->ResetFunctionStack(state);
  7191. if (!spawn) {
  7192. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7193. return 0;
  7194. }
  7195. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7196. return 1;
  7197. }
  7198. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7199. if (!lua_interface)
  7200. return 0;
  7201. Spawn* player = lua_interface->GetSpawn(state);
  7202. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7203. if (!player) {
  7204. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7205. lua_interface->ResetFunctionStack(state);
  7206. return 0;
  7207. }
  7208. if (!player->IsPlayer()) {
  7209. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7210. lua_interface->ResetFunctionStack(state);
  7211. return 0;
  7212. }
  7213. if (!ground) {
  7214. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7215. lua_interface->ResetFunctionStack(state);
  7216. return 0;
  7217. }
  7218. if (!ground->IsGroundSpawn()) {
  7219. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7220. lua_interface->ResetFunctionStack(state);
  7221. return 0;
  7222. }
  7223. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7224. if (!groundspawn_entries) {
  7225. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7226. lua_interface->ResetFunctionStack(state);
  7227. return 0;
  7228. }
  7229. Skill* skill = 0;
  7230. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7231. if (collection_skill == "Collecting")
  7232. skill = ((Player*)player)->GetSkillByName("Gathering");
  7233. else
  7234. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7235. if (!skill) {
  7236. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7237. lua_interface->ResetFunctionStack(state);
  7238. return 0;
  7239. }
  7240. vector<GroundSpawnEntry*>::iterator itr;
  7241. GroundSpawnEntry* entry = 0;
  7242. bool can_harvest = false;
  7243. sint32 min_skill = -1;
  7244. int16 totalSkill = skill->current_val;
  7245. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7246. if(skillID != 0xFFFFFFFF)
  7247. {
  7248. ((Entity*)player)->MStats.lock();
  7249. totalSkill += ((Entity*)player)->stats[skillID];
  7250. ((Entity*)player)->MStats.unlock();
  7251. }
  7252. // first, iterate through groundspawn_entries, discard tables player cannot use
  7253. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7254. {
  7255. entry = *itr;
  7256. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7257. min_skill = entry->min_skill_level;
  7258. // if player lacks skill, skip table
  7259. if (entry->min_skill_level > totalSkill)
  7260. continue;
  7261. // if bonus, but player lacks level, skip table
  7262. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7263. continue;
  7264. can_harvest = true;
  7265. break;
  7266. }
  7267. lua_interface->SetBooleanValue(state, can_harvest);
  7268. // If false, send the message to the client
  7269. if (!can_harvest) {
  7270. Client* client = ((Player*)player)->GetClient();
  7271. if (client) {
  7272. string msg = "You do not have enough skill to ";
  7273. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7274. msg.append("gather");
  7275. else if (collection_skill == "Mining")
  7276. msg.append("mine");
  7277. else if (collection_skill == "Trapping")
  7278. msg.append("trap");
  7279. else if (collection_skill == "Foresting")
  7280. msg.append("forest");
  7281. else if (collection_skill == "Fishing")
  7282. msg.append("catch");
  7283. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7284. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7285. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7286. }
  7287. }
  7288. lua_interface->ResetFunctionStack(state);
  7289. return 1;
  7290. }
  7291. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7292. if (!lua_interface)
  7293. return 0;
  7294. Spawn* player = lua_interface->GetSpawn(state);
  7295. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7296. lua_interface->ResetFunctionStack(state);
  7297. if (!player) {
  7298. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7299. return 0;
  7300. }
  7301. if (!player->IsPlayer()) {
  7302. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7306. lua_interface->SetBooleanValue(state, ret);
  7307. return 1;
  7308. }
  7309. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7310. // Check to see if we have a valid lua_interface
  7311. if (!lua_interface)
  7312. return 0;
  7313. // Get the spawn that is getting the pet
  7314. Spawn* spawn = lua_interface->GetSpawn(state);
  7315. Spawn* target = lua_interface->GetSpawn(state, 2);
  7316. // Get the DB ID of the pet
  7317. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7318. float x = lua_interface->GetFloatValue(state, 4);
  7319. float y = lua_interface->GetFloatValue(state, 5);
  7320. float z = lua_interface->GetFloatValue(state, 6);
  7321. // Get the spell that this command was called from
  7322. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7323. lua_interface->ResetFunctionStack(state);
  7324. // Check to make sure the spawn pointer is valid
  7325. if (!spawn) {
  7326. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7327. return 0;
  7328. }
  7329. // Check to make sure the spawn is an entity
  7330. if (!spawn->IsEntity()) {
  7331. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7332. return 0;
  7333. }
  7334. if (!target) {
  7335. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. if (!target->IsEntity()) {
  7339. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. // Check to see if the DB ID for the pet is set
  7343. if (pet_id == 0) {
  7344. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7345. return 0;
  7346. }
  7347. // Check to see if the pointer to the spell is valid
  7348. if (!luaspell) {
  7349. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7350. return 0;
  7351. }
  7352. if(luaspell->resisted) {
  7353. return 0;
  7354. }
  7355. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7356. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7357. if (!pet) {
  7358. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7359. return 0;
  7360. }
  7361. // Check to make sure the pet is an npc
  7362. if (!pet->IsNPC()) {
  7363. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7364. return 0;
  7365. }
  7366. if (x == 0)
  7367. x = spawn->GetX();
  7368. if (y == 0)
  7369. y = spawn->GetY();
  7370. if (z == 0)
  7371. z = spawn->GetZ();
  7372. // Spawn the pet at the same location as the owner
  7373. pet->SetX(x);
  7374. pet->SetY(y);
  7375. pet->SetZ(z);
  7376. pet->SetLocation(spawn->GetLocation());
  7377. pet->SetHeading(spawn->GetHeading());
  7378. spawn->GetZone()->AddSpawn(pet);
  7379. const char* spawn_script = world.GetSpawnScript(pet_id);
  7380. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7381. spawn->SetSpawnScript(string(spawn_script));
  7382. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7383. }
  7384. std::string petName = std::string("");
  7385. if(spawn->IsEntity()) {
  7386. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7387. }
  7388. if(petName.size() < 1) {
  7389. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7390. petName = spawn->GetZone()->pet_names.at(rand_index);
  7391. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7392. }
  7393. // Set the pets name
  7394. pet->SetName(petName.c_str());
  7395. // Set the level of the pet to the owners level
  7396. pet->SetLevel(spawn->GetLevel());
  7397. // Set the faction of the pet to the same faction as the owner
  7398. pet->SetFactionID(spawn->GetFactionID());
  7399. // Set the spawn as a pet
  7400. pet->SetPet(true);
  7401. // Give a pointer of the owner to the pet
  7402. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7403. // Set the pet type
  7404. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7405. // Set the spell id used to create this pet
  7406. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7407. // Set the spell tier used to create this pet
  7408. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7409. // Set the pets spawn type to 6
  7410. pet->SetSpawnType(6);
  7411. // Set the pets brain
  7412. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7413. // Check to see if the pet has a subtitle
  7414. if (strlen(pet->GetSubTitle()) > 0) {
  7415. // Add the players name to the front of the sub title
  7416. string pet_subtitle;
  7417. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7418. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7419. // Set the pets subtitle to the new one
  7420. pet->SetSubTitle(pet_subtitle.c_str());
  7421. }
  7422. // Set the pet as the return value for this function
  7423. lua_interface->SetSpawnValue(state, pet);
  7424. return 1;
  7425. }
  7426. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7427. if (!lua_interface)
  7428. return 0;
  7429. Spawn* spawn = lua_interface->GetSpawn(state);
  7430. Spawn* player = lua_interface->GetSpawn(state, 2);
  7431. float max_distance = lua_interface->GetFloatValue(state, 3);
  7432. string type = lua_interface->GetStringValue(state, 4);
  7433. lua_interface->ResetFunctionStack(state);
  7434. if (!spawn || (spawn && spawn->IsPlayer())) {
  7435. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7436. return 0;
  7437. }
  7438. if (!player || !player->IsPlayer()) {
  7439. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7440. return 0;
  7441. }
  7442. Client* client = ((Player*)player)->GetClient();
  7443. if (!client) {
  7444. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. //Set max_distance to default if not set or not proper value
  7448. if (max_distance <= 0)
  7449. max_distance = 500;
  7450. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7451. if (packet) {
  7452. float unknown2_3 = 0;
  7453. int8 placement_mode = 0;
  7454. if (type == "wall") {
  7455. placement_mode = 2;
  7456. unknown2_3 = 150;
  7457. }
  7458. else if (type == "ceiling")
  7459. placement_mode = 1;
  7460. packet->setDataByName("placement_mode", placement_mode);
  7461. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7462. packet->setDataByName("model_type", spawn->GetModelType());
  7463. packet->setDataByName("unknown", 1); //size
  7464. packet->setDataByName("unknown2", 1); //size 2
  7465. packet->setDataByName("unknown2", .5, 1); //size 3
  7466. packet->setDataByName("unknown2", 3, 2);
  7467. packet->setDataByName("unknown2", unknown2_3, 3);
  7468. packet->setDataByName("max_distance", max_distance);
  7469. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7470. client->QueuePacket(packet->serialize());
  7471. safe_delete(packet);
  7472. }
  7473. return 0;
  7474. }
  7475. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7476. if (!lua_interface)
  7477. return 0;
  7478. Item* item = lua_interface->GetItem(state);
  7479. lua_interface->ResetFunctionStack(state);
  7480. if (!item) {
  7481. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7482. return 0;
  7483. }
  7484. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7485. return 1;
  7486. }
  7487. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7488. if (!lua_interface)
  7489. return 0;
  7490. Item* item = lua_interface->GetItem(state);
  7491. lua_interface->ResetFunctionStack(state);
  7492. if (!item) {
  7493. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7494. return 0;
  7495. }
  7496. lua_interface->SetInt32Value(state, item->effect_type);
  7497. return 1;
  7498. }
  7499. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7500. if (!lua_interface)
  7501. return 0;
  7502. Spawn* spawn = lua_interface->GetSpawn(state);
  7503. lua_interface->ResetFunctionStack(state);
  7504. if (!spawn) {
  7505. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7506. return 0;
  7507. }
  7508. if (spawn->GetZone())
  7509. spawn->GetZone()->AddTransportSpawn(spawn);
  7510. return 0;
  7511. }
  7512. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7513. if (!lua_interface)
  7514. return 0;
  7515. Spawn* spawn = lua_interface->GetSpawn(state);
  7516. lua_interface->ResetFunctionStack(state);
  7517. if (!spawn) {
  7518. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7519. return 0;
  7520. }
  7521. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7522. return 1;
  7523. }
  7524. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. Skill* skill = lua_interface->GetSkill(state);
  7528. lua_interface->ResetFunctionStack(state);
  7529. if (!skill) {
  7530. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. lua_interface->SetInt32Value(state, skill->current_val);
  7534. return 1;
  7535. }
  7536. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7537. if (!lua_interface)
  7538. return 0;
  7539. Skill* skill = lua_interface->GetSkill(state);
  7540. lua_interface->ResetFunctionStack(state);
  7541. if (!skill) {
  7542. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7543. return 0;
  7544. }
  7545. lua_interface->SetInt32Value(state, skill->max_val);
  7546. return 1;
  7547. }
  7548. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7549. if (!lua_interface)
  7550. return 0;
  7551. Skill* skill = lua_interface->GetSkill(state);
  7552. lua_interface->ResetFunctionStack(state);
  7553. if (!skill) {
  7554. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7558. return 1;
  7559. }
  7560. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7561. if (!lua_interface)
  7562. return 0;
  7563. Skill* skill = lua_interface->GetSkill(state);
  7564. int16 value = lua_interface->GetInt16Value(state, 2);
  7565. lua_interface->ResetFunctionStack(state);
  7566. if (!skill) {
  7567. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7568. return 0;
  7569. }
  7570. skill->max_val = value;
  7571. if (skill->max_val < skill->current_val)
  7572. skill->current_val = skill->max_val;
  7573. return 0;
  7574. }
  7575. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7576. if (!lua_interface)
  7577. return 0;
  7578. Skill* skill = lua_interface->GetSkill(state);
  7579. int16 value = lua_interface->GetInt16Value(state, 2);
  7580. lua_interface->ResetFunctionStack(state);
  7581. if (!skill) {
  7582. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7583. return 0;
  7584. }
  7585. if (value > skill->max_val)
  7586. skill->current_val = skill->max_val;
  7587. else
  7588. skill->current_val = value;
  7589. return 0;
  7590. }
  7591. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7592. if (!lua_interface)
  7593. return 0;
  7594. Spawn* player = lua_interface->GetSpawn(state);
  7595. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7596. lua_interface->ResetFunctionStack(state);
  7597. if (skill_id > 0 && player && player->IsPlayer()) {
  7598. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7599. return 1;
  7600. }
  7601. return 0;
  7602. }
  7603. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7604. if (!lua_interface)
  7605. return 0;
  7606. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7607. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7608. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7609. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7610. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7611. lua_interface->ResetFunctionStack(state);
  7612. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7613. if (player_spawn && player_spawn->IsPlayer()) {
  7614. Player* player = (Player*)player_spawn;
  7615. bool added = false;
  7616. if (!player->skill_list.HasSkill(skill_id)) {
  7617. player->AddSkill(skill_id, current_val, max_val, true);
  7618. added = true;
  7619. }
  7620. 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
  7621. Client* client = player->GetClient();
  7622. if (client) {
  7623. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7624. if (packet)
  7625. client->QueuePacket(packet);
  7626. }
  7627. }
  7628. if (added) {
  7629. lua_interface->SetBooleanValue(state, true);
  7630. return 1;
  7631. }
  7632. }
  7633. else {
  7634. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7635. }
  7636. }
  7637. else {
  7638. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7639. }
  7640. lua_interface->SetBooleanValue(state, false);
  7641. return 1;
  7642. }
  7643. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7644. if (!lua_interface)
  7645. return 0;
  7646. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7647. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7648. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7649. lua_interface->ResetFunctionStack(state);
  7650. if (skill_id > 0) {
  7651. if (player_spawn && player_spawn->IsPlayer()) {
  7652. Player* player = (Player*)player_spawn;
  7653. if (player->skill_list.HasSkill(skill_id)) {
  7654. player->RemovePlayerSkill(skill_id, true);
  7655. if (!more_to_remove) {
  7656. Client* client = player->GetClient();
  7657. if (client) {
  7658. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7659. if (packet)
  7660. client->QueuePacket(packet);
  7661. }
  7662. }
  7663. }
  7664. }
  7665. else {
  7666. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7667. }
  7668. }
  7669. else {
  7670. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7671. }
  7672. return 0;
  7673. }
  7674. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7675. if (!lua_interface)
  7676. return 0;
  7677. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7678. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7679. int16 amount = lua_interface->GetInt8Value(state, 3);
  7680. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7681. lua_interface->ResetFunctionStack(state);
  7682. if (amount > 0 && skill_type < 100) {
  7683. if (player_spawn && player_spawn->IsPlayer()) {
  7684. Player* player = (Player*)player_spawn;
  7685. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7686. if (!more_to_increase) {
  7687. Client* client = player->GetClient();
  7688. if (client) {
  7689. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7690. if (packet)
  7691. client->QueuePacket(packet);
  7692. }
  7693. }
  7694. }
  7695. else {
  7696. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7697. }
  7698. }
  7699. else {
  7700. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7701. }
  7702. return 0;
  7703. }
  7704. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7705. if (!lua_interface)
  7706. return 0;
  7707. Spawn* spawn = lua_interface->GetSpawn(state);
  7708. string name = lua_interface->GetStringValue(state, 2);
  7709. lua_interface->ResetFunctionStack(state);
  7710. if (!spawn) {
  7711. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7712. return 0;
  7713. }
  7714. if (!spawn->IsEntity()) {
  7715. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7716. return 0;
  7717. }
  7718. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7719. if (skill) {
  7720. lua_interface->SetSkillValue(state, skill);
  7721. return 1;
  7722. }
  7723. return 0;
  7724. }
  7725. int EQ2Emu_lua_AddProc(lua_State* state) {
  7726. if (!lua_interface)
  7727. return 0;
  7728. Spawn* spawn = lua_interface->GetSpawn(state);
  7729. int8 type = lua_interface->GetInt8Value(state, 2);
  7730. float chance = lua_interface->GetFloatValue(state, 3);
  7731. Item* item = lua_interface->GetItem(state, 4);
  7732. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7733. LuaSpell* spell = 0;
  7734. if (!item)
  7735. spell = lua_interface->GetCurrentSpell(state);
  7736. if (!spawn && (!spell || !use_all_spelltargets)) {
  7737. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7738. return 0;
  7739. }
  7740. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7741. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7742. return 0;
  7743. }
  7744. if (!item && !spell) {
  7745. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7746. return 0;
  7747. }
  7748. if(spell && spell->resisted) {
  7749. return 0;
  7750. }
  7751. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7752. Spawn* target;
  7753. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7754. for (int8 i = 0; i < spell->targets.size(); i++) {
  7755. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7756. if (!target || !target->IsEntity())
  7757. continue;
  7758. ((Entity*)target)->AddProc(type, chance, item, spell);
  7759. }
  7760. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7761. }
  7762. else
  7763. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7764. return 0;
  7765. }
  7766. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7767. if (!lua_interface)
  7768. return 0;
  7769. Spawn* spawn = lua_interface->GetSpawn(state);
  7770. int8 type = lua_interface->GetInt8Value(state, 2);
  7771. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7772. float chance = lua_interface->GetFloatValue(state, 4);
  7773. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7774. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7775. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7776. Item* item = lua_interface->GetItem(state, 8);
  7777. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7778. bool extended_version = true;
  7779. LuaSpell* spell = 0;
  7780. if (!item)
  7781. spell = lua_interface->GetCurrentSpell(state);
  7782. if (!spawn && (!spell || !use_all_spelltargets)) {
  7783. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7784. return 0;
  7785. }
  7786. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7787. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7788. return 0;
  7789. }
  7790. if (!item && !spell) {
  7791. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. if(spell && spell->resisted) {
  7795. return 0;
  7796. }
  7797. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7798. Spawn* target;
  7799. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7800. for (int8 i = 0; i < spell->targets.size(); i++) {
  7801. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7802. if (!target || !target->IsEntity())
  7803. continue;
  7804. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7805. }
  7806. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7807. }
  7808. else
  7809. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7810. return 0;
  7811. }
  7812. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7813. if (!lua_interface)
  7814. return 0;
  7815. Spawn* spawn = lua_interface->GetSpawn(state);
  7816. Item* item = lua_interface->GetItem(state, 2);
  7817. LuaSpell* spell = 0;
  7818. if (!item)
  7819. spell = lua_interface->GetCurrentSpell(state);
  7820. lua_interface->ResetFunctionStack(state);
  7821. if (!item && !spell) {
  7822. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. if (spell && spell->caster && spell->caster->GetZone()) {
  7826. Spawn* target;
  7827. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7828. for (int8 i = 0; i < spell->targets.size(); i++) {
  7829. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7830. if (!target || !target->IsEntity())
  7831. continue;
  7832. ((Entity*)target)->RemoveProc(item, spell);
  7833. }
  7834. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7835. spell->caster->RemoveProc(item, spell);
  7836. }
  7837. else if (!spawn) {
  7838. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7839. return 0;
  7840. }
  7841. else if (!spawn->IsEntity()) {
  7842. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. else {
  7846. ((Entity*)spawn)->RemoveProc(item, spell);
  7847. }
  7848. return 0;
  7849. }
  7850. int EQ2Emu_lua_Knockback(lua_State* state) {
  7851. if (!lua_interface)
  7852. return 0;
  7853. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7854. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7855. int32 duration = lua_interface->GetInt32Value(state, 3);
  7856. float vertical = lua_interface->GetFloatValue(state, 4);
  7857. float horizontal = lua_interface->GetFloatValue(state, 5);
  7858. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7859. lua_interface->ResetFunctionStack(state);
  7860. if (!target_spawn) {
  7861. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7862. return 0;
  7863. }
  7864. if (!spawn) {
  7865. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7866. return 0;
  7867. }
  7868. if ((vertical != 0 || horizontal != 0)) {
  7869. if(spawn->IsPlayer()) {
  7870. Client* client = ((Player*)spawn)->GetClient();
  7871. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7872. if (packet) {
  7873. packet->setDataByName("target_x", target_spawn->GetX());
  7874. packet->setDataByName("target_y", target_spawn->GetY());
  7875. packet->setDataByName("target_z", target_spawn->GetZ());
  7876. packet->setDataByName("vertical_movement", vertical);
  7877. packet->setDataByName("horizontal_movement", horizontal);
  7878. if (use_heading)
  7879. packet->setDataByName("use_player_heading", 1);
  7880. client->QueuePacket(packet->serialize());
  7881. }
  7882. safe_delete(packet);
  7883. }
  7884. else {
  7885. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7886. }
  7887. }
  7888. return 0;
  7889. }
  7890. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7891. if (!lua_interface)
  7892. return 0;
  7893. Spawn* spawn = lua_interface->GetSpawn(state);
  7894. lua_interface->ResetFunctionStack(state);
  7895. if (!spawn) {
  7896. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7900. return 1;
  7901. }
  7902. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7903. if (!lua_interface)
  7904. return 0;
  7905. Spawn* caster = lua_interface->GetSpawn(state);
  7906. Spawn* target = lua_interface->GetSpawn(state, 2);
  7907. string name = lua_interface->GetStringValue(state, 3);
  7908. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7909. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7910. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7911. string success_msg = lua_interface->GetStringValue(state, 7);
  7912. string effect_msg = lua_interface->GetStringValue(state, 8);
  7913. lua_interface->ResetFunctionStack(state);
  7914. if (!caster) {
  7915. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7916. return 0;
  7917. }
  7918. if (!caster->IsEntity()) {
  7919. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7920. return 0;
  7921. }
  7922. if (!target) {
  7923. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7924. return 0;
  7925. }
  7926. if (!target->IsEntity()) {
  7927. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7928. return 0;
  7929. }
  7930. if (name.length() == 0) {
  7931. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7935. return 0;
  7936. }
  7937. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7938. if (!lua_interface)
  7939. return 0;
  7940. string name = lua_interface->GetStringValue(state);
  7941. lua_interface->ResetFunctionStack(state);
  7942. if (name.length() == 0) {
  7943. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7947. if (!skill) {
  7948. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7949. return 0;
  7950. }
  7951. lua_interface->SetInt32Value(state, skill->skill_id);
  7952. return 1;
  7953. }
  7954. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7955. if (!lua_interface)
  7956. return 0;
  7957. Spawn* spawn = lua_interface->GetSpawn(state);
  7958. lua_interface->ResetFunctionStack(state);
  7959. if (!spawn) {
  7960. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7961. return 0;
  7962. }
  7963. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7964. return 1;
  7965. }
  7966. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7967. if (!lua_interface)
  7968. return 0;
  7969. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7970. lua_interface->ResetFunctionStack(state);
  7971. if (!luaspell) {
  7972. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7973. return 0;
  7974. }
  7975. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7976. return 1;
  7977. }
  7978. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7979. if (!lua_interface)
  7980. return 0;
  7981. Spawn* spawn = lua_interface->GetSpawn(state);
  7982. Spawn* target = lua_interface->GetSpawn(state, 2);
  7983. lua_interface->ResetFunctionStack(state);
  7984. if (!spawn) {
  7985. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. if (!spawn->IsEntity()) {
  7989. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7990. return 0;
  7991. }
  7992. if (!target) {
  7993. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7994. return 0;
  7995. }
  7996. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7997. return 1;
  7998. }
  7999. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  8000. if (!lua_interface)
  8001. return 0;
  8002. Spawn* spawn = lua_interface->GetSpawn(state);
  8003. Spawn* target = lua_interface->GetSpawn(state, 2);
  8004. lua_interface->ResetFunctionStack(state);
  8005. if (!spawn) {
  8006. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. if (!spawn->IsEntity()) {
  8010. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. if (!target) {
  8014. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  8015. return 0;
  8016. }
  8017. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  8018. return 1;
  8019. }
  8020. int EQ2Emu_lua_InFront(lua_State* state) {
  8021. if (!lua_interface)
  8022. return 0;
  8023. Spawn* spawn = lua_interface->GetSpawn(state);
  8024. Spawn* target = lua_interface->GetSpawn(state, 2);
  8025. lua_interface->ResetFunctionStack(state);
  8026. if (!spawn) {
  8027. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  8028. return 0;
  8029. }
  8030. if (!target) {
  8031. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  8032. return 0;
  8033. }
  8034. lua_interface->SetBooleanValue(state, spawn->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  8035. return 1;
  8036. }
  8037. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  8038. if (!lua_interface)
  8039. return 0;
  8040. Item* item = lua_interface->GetItem(state);
  8041. lua_interface->ResetFunctionStack(state);
  8042. if (!item) {
  8043. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. lua_interface->SetInt32Value(state, item->details.count);
  8047. return 1;
  8048. }
  8049. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  8050. if (!lua_interface)
  8051. return 0;
  8052. Item* item = lua_interface->GetItem(state);
  8053. Spawn* owner = lua_interface->GetSpawn(state, 2);
  8054. int16 new_count = lua_interface->GetInt32Value(state, 3);
  8055. lua_interface->ResetFunctionStack(state);
  8056. if (!item) {
  8057. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  8058. return 0;
  8059. }
  8060. if (!owner) {
  8061. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. if (!owner->IsPlayer()) {
  8065. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8066. return 0;
  8067. }
  8068. if (item->stack_count < new_count) {
  8069. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  8070. return 0;
  8071. }
  8072. if (new_count > 0) {
  8073. item->details.count = new_count;
  8074. item->save_needed = true;
  8075. }
  8076. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8077. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8078. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8079. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8080. else
  8081. {
  8082. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. Client* client = ((Player*)owner)->GetClient();
  8086. if (!client)
  8087. return 0;
  8088. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8089. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8090. if (app)
  8091. client->QueuePacket(app);
  8092. return 0;
  8093. }
  8094. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8095. if (!lua_interface)
  8096. return 0;
  8097. int32 time = lua_interface->GetInt32Value(state);
  8098. string function = lua_interface->GetStringValue(state, 2);
  8099. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8100. Spawn* target = lua_interface->GetSpawn(state, 4);
  8101. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8102. lua_interface->ResetFunctionStack(state);
  8103. if (time == 0) {
  8104. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8105. return 0;
  8106. }
  8107. if (function.length() == 0) {
  8108. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8109. return 0;
  8110. }
  8111. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8112. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8113. return 0;
  8114. }
  8115. SpellScriptTimer* timer = new SpellScriptTimer;
  8116. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8117. #ifdef WIN32
  8118. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8119. #else
  8120. bzero(timer, sizeof(SpellScriptTimer));
  8121. #endif*/
  8122. timer->caster = 0;
  8123. timer->deleteWhenDone = false;
  8124. timer->target = 0;
  8125. timer->time = Timer::GetCurrentTime2() + time;
  8126. timer->customFunction = function;
  8127. timer->spell = spell;
  8128. if (caster)
  8129. timer->caster = caster->GetID();
  8130. if (target)
  8131. timer->target = target->GetID();
  8132. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8133. return 0;
  8134. }
  8135. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8136. if (!lua_interface)
  8137. return 0;
  8138. float hp_perc = lua_interface->GetFloatValue(state);
  8139. float power_perc = lua_interface->GetFloatValue(state, 2);
  8140. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8141. Spawn* target = lua_interface->GetSpawn(state, 4);
  8142. string heal_name = lua_interface->GetStringValue(state, 5);
  8143. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8144. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8145. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8146. lua_interface->ResetFunctionStack(state);
  8147. if (!spell) {
  8148. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8149. return 0;
  8150. }
  8151. Entity* caster = spell->caster;
  8152. if (!caster) {
  8153. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8154. return 0;
  8155. }
  8156. Client* client = 0;
  8157. PendingResurrection* rez = 0;
  8158. ZoneServer* zone = spell->caster->GetZone();
  8159. if (!target) {
  8160. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8161. if (spell->targets.size() > 0) {
  8162. vector<int32> spell_targets = spell->targets;
  8163. for (int8 i = 0; i < spell_targets.size(); i++) {
  8164. target = zone->GetSpawnByID(spell_targets.at(i));
  8165. if (!target)
  8166. continue;
  8167. if (!target->IsPlayer())
  8168. continue;
  8169. client = ((Player*)target)->GetClient();
  8170. if (!client)
  8171. continue;
  8172. rez = client->GetCurrentRez();
  8173. if (rez->active)
  8174. continue;
  8175. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8176. rez->active = true;
  8177. rez->caster = caster;
  8178. rez->expire_timer = new Timer;
  8179. int32 duration = spell->spell->GetSpellDuration();
  8180. rez->expire_timer->Start(duration * 100);
  8181. rez->hp_perc = hp_perc;
  8182. rez->mp_perc = power_perc;
  8183. rez->range = spell->spell->GetSpellData()->range;
  8184. rez->spell_name = spell->spell->GetName();
  8185. if (heal_name.length() > 0)
  8186. rez->heal_name = heal_name;
  8187. else
  8188. rez->heal_name = rez->spell_name;
  8189. rez->no_calcs = no_calcs;
  8190. rez->crit_mod = crit_mod;
  8191. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8192. if (send_window)
  8193. client->SendResurrectionWindow();
  8194. else {
  8195. target->GetZone()->ResurrectSpawn(target, client);
  8196. rez->should_delete = true;
  8197. }
  8198. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8199. }
  8200. }
  8201. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8202. }
  8203. else {
  8204. if(!target->IsPlayer())
  8205. return 0;
  8206. client = ((Player*)target)->GetClient();
  8207. if (!client)
  8208. return 0;
  8209. rez = client->GetCurrentRez();
  8210. if (rez->active)
  8211. return 0;
  8212. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8213. rez->active = true;
  8214. rez->caster = caster;
  8215. rez->expire_timer = new Timer;
  8216. int32 duration = spell->spell->GetSpellDuration();
  8217. rez->expire_timer->Start(duration * 100);
  8218. rez->hp_perc = hp_perc;
  8219. rez->mp_perc = power_perc;
  8220. rez->range = spell->spell->GetSpellData()->range;
  8221. rez->spell_name = spell->spell->GetName();
  8222. if (heal_name.length() > 0)
  8223. rez->heal_name = heal_name;
  8224. else
  8225. rez->heal_name = rez->spell_name;
  8226. rez->no_calcs = no_calcs;
  8227. rez->crit_mod = crit_mod;
  8228. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8229. if (send_window)
  8230. client->SendResurrectionWindow();
  8231. else {
  8232. target->GetZone()->ResurrectSpawn(target, client);
  8233. rez->should_delete = true;
  8234. }
  8235. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8236. }
  8237. return 0;
  8238. }
  8239. int EQ2Emu_lua_SetVision(lua_State* state) {
  8240. if (!lua_interface)
  8241. return 0;
  8242. Spawn* spawn = lua_interface->GetSpawn(state);
  8243. int32 vision = lua_interface->GetInt32Value(state, 2);
  8244. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8245. lua_interface->ResetFunctionStack(state);
  8246. if (!spawn) {
  8247. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8248. return 0;
  8249. }
  8250. if (!spawn->IsEntity()) {
  8251. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8252. return 0;
  8253. }
  8254. if (spell && spell->targets.size() > 0) {
  8255. ZoneServer* zone = spell->caster->GetZone();
  8256. for (int8 i = 0; i < spell->targets.size(); i++) {
  8257. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8258. if (target && target->IsEntity()) {
  8259. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8260. if (target->IsPlayer())
  8261. ((Player*)target)->SetCharSheetChanged(true);
  8262. }
  8263. }
  8264. }
  8265. else {
  8266. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8267. if (spawn->IsPlayer())
  8268. ((Player*)spawn)->SetCharSheetChanged(true);
  8269. }
  8270. return 0;
  8271. }
  8272. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8273. if (!lua_interface)
  8274. return 0;
  8275. Spawn* spawn = lua_interface->GetSpawn(state);
  8276. float intensity = lua_interface->GetFloatValue(state, 2);
  8277. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8278. lua_interface->ResetFunctionStack(state);
  8279. if (!spawn) {
  8280. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8281. return 0;
  8282. }
  8283. if (!spawn->IsEntity()) {
  8284. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8285. return 0;
  8286. }
  8287. if (spell && spell->targets.size() > 0) {
  8288. ZoneServer* zone = spell->caster->GetZone();
  8289. for (int8 i = 0; i < spell->targets.size(); i++) {
  8290. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8291. if (target && target->IsEntity()) {
  8292. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8293. if (target->IsPlayer())
  8294. ((Player*)target)->SetCharSheetChanged(true);
  8295. }
  8296. }
  8297. }
  8298. else {
  8299. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8300. if (spawn->IsPlayer())
  8301. ((Player*)spawn)->SetCharSheetChanged(true);
  8302. }
  8303. return 0;
  8304. }
  8305. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8306. if (!lua_interface)
  8307. return 0;
  8308. Spawn* spawn = lua_interface->GetSpawn(state);
  8309. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8310. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8311. lua_interface->ResetFunctionStack(state);
  8312. if (!spawn) {
  8313. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. if (!spawn->IsEntity()) {
  8317. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (spell && spell->targets.size() > 0) {
  8321. ZoneServer* zone = spell->caster->GetZone();
  8322. for (int8 i = 0; i < spell->targets.size(); i++) {
  8323. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8324. if (target && target->IsEntity()) {
  8325. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8326. if (target->IsPlayer())
  8327. ((Player*)target)->SetCharSheetChanged(true);
  8328. }
  8329. }
  8330. }
  8331. else {
  8332. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8333. if (spawn->IsPlayer())
  8334. ((Player*)spawn)->SetCharSheetChanged(true);
  8335. }
  8336. return 0;
  8337. }
  8338. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8339. if (!lua_interface)
  8340. return 0;
  8341. Item* item = lua_interface->GetItem(state);
  8342. int8 type = lua_interface->GetInt32Value(state, 2);
  8343. lua_interface->ResetFunctionStack(state);
  8344. if (!item) {
  8345. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8346. return 0;
  8347. }
  8348. if (type == 1)
  8349. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8350. else if (type == 2)
  8351. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8352. return 1;
  8353. }
  8354. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8355. if (!lua_interface)
  8356. return 0;
  8357. Spawn* target = lua_interface->GetSpawn(state);
  8358. float val = lua_interface->GetFloatValue(state, 2);
  8359. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8360. lua_interface->ResetFunctionStack(state);
  8361. // Added from Gangrenous post
  8362. if (spell && spell->resisted)
  8363. return 0;
  8364. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8365. if (val > 1.0f)
  8366. val = 1.0f - (val / 100.0f);
  8367. if (spell && spell->spell && spell->targets.size() > 0) {
  8368. ZoneServer* zone = spell->caster->GetZone();
  8369. for (int32 i = 0; i != spell->targets.size(); i++) {
  8370. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8371. if (spawn && spawn->IsEntity()) {
  8372. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8373. if (spawn->IsPlayer())
  8374. ((Player*)spawn)->SetCharSheetChanged(true);
  8375. }
  8376. }
  8377. }
  8378. else {
  8379. if (target && target->IsEntity()) {
  8380. ((Entity*)target)->SetSpeedMultiplier(val);
  8381. if (target->IsPlayer())
  8382. ((Player*)target)->SetCharSheetChanged(true);
  8383. }
  8384. }
  8385. return 0;
  8386. }
  8387. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8388. if (!lua_interface)
  8389. return 0;
  8390. Spawn* spawn = lua_interface->GetSpawn(state);
  8391. int16 model = lua_interface->GetInt16Value(state, 2);
  8392. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8393. lua_interface->ResetFunctionStack(state);
  8394. if (spell && spell->spell && spell->targets.size() > 0) {
  8395. ZoneServer* zone = spell->caster->GetZone();
  8396. for (int32 i = 0; i < spell->targets.size(); i++) {
  8397. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8398. if (target)
  8399. target->SetIllusionModel(model);
  8400. }
  8401. }
  8402. else {
  8403. if (!spawn) {
  8404. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8405. return 0;
  8406. }
  8407. spawn->SetIllusionModel(model);
  8408. }
  8409. return 0;
  8410. }
  8411. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8412. if (!lua_interface)
  8413. return 0;
  8414. Spawn* spawn = lua_interface->GetSpawn(state);
  8415. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8416. lua_interface->ResetFunctionStack(state);
  8417. if (spell && spell->spell && spell->targets.size() > 0) {
  8418. ZoneServer* zone = spell->caster->GetZone();
  8419. for (int32 i = 0; i < spell->targets.size(); i++) {
  8420. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8421. if (target)
  8422. target->SetIllusionModel(0);
  8423. }
  8424. }
  8425. else {
  8426. if (!spawn) {
  8427. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8428. return 0;
  8429. }
  8430. spawn->SetIllusionModel(0);
  8431. }
  8432. return 0;
  8433. }
  8434. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8435. if (!lua_interface)
  8436. return 0;
  8437. Spawn* caster = lua_interface->GetSpawn(state);
  8438. Spawn* target = lua_interface->GetSpawn(state, 2);
  8439. float chance = lua_interface->GetFloatValue(state, 3);
  8440. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8441. lua_interface->ResetFunctionStack(state);
  8442. if (!caster) {
  8443. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8444. return 0;
  8445. }
  8446. if (!caster->IsEntity()) {
  8447. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8448. return 0;
  8449. }
  8450. if (!target) {
  8451. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!target->IsEntity()) {
  8455. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. if (chance <= 0) {
  8459. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8460. return 0;
  8461. }
  8462. if (!spell) {
  8463. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8464. return 0;
  8465. }
  8466. if(spell->resisted) {
  8467. return 0;
  8468. }
  8469. if (((Entity*)caster)->GetThreatTransfer()) {
  8470. return 0;
  8471. }
  8472. ThreatTransfer* transfer = new ThreatTransfer;
  8473. transfer->Target = target->GetID();
  8474. transfer->Amount = chance;
  8475. transfer->Spell = spell;
  8476. ((Entity*)caster)->SetThreatTransfer(transfer);
  8477. return 0;
  8478. }
  8479. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8480. if (!lua_interface)
  8481. return 0;
  8482. Spawn* spawn = lua_interface->GetSpawn(state);
  8483. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8484. lua_interface->ResetFunctionStack(state);
  8485. if (!spawn || !spawn->IsEntity()) {
  8486. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8487. return 0;
  8488. }
  8489. if (!spawn->IsEntity()) {
  8490. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. if (!spell) {
  8494. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8498. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8499. if(transfer && transfer->Spell != spell) {
  8500. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8504. }
  8505. return 0;
  8506. }
  8507. int EQ2Emu_lua_CureByType(lua_State* state) {
  8508. if (!lua_interface)
  8509. return 0;
  8510. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8511. int8 cure_count = lua_interface->GetInt8Value(state);
  8512. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8513. string cure_name = lua_interface->GetStringValue(state, 3);
  8514. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8515. Spawn* target = lua_interface->GetSpawn(state, 5);
  8516. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8517. lua_interface->ResetFunctionStack(state);
  8518. if(spell && spell->resisted) {
  8519. return 0;
  8520. }
  8521. if (target) {
  8522. if (!target->IsEntity()) {
  8523. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8524. return 0;
  8525. }
  8526. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8527. std::string alternate_name = "item";
  8528. if(spell)
  8529. alternate_name = std::string(spell->spell->GetName());
  8530. if(!caster && spell)
  8531. caster = (Spawn*)spell->caster;
  8532. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8533. }
  8534. }
  8535. else {
  8536. ZoneServer* zone = spell->caster->GetZone();
  8537. vector<int32> targets = spell->targets;
  8538. vector<Entity*> targets_to_cure;
  8539. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8540. for (int8 i = 0; i < targets.size(); i++) {
  8541. target = zone->GetSpawnByID(targets.at(i));
  8542. if (!target || !target->IsEntity())
  8543. continue;
  8544. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8545. targets_to_cure.push_back((Entity*)target);
  8546. }
  8547. }
  8548. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8549. vector<Entity*>::iterator itr;
  8550. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8551. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8552. }
  8553. }
  8554. return 0;
  8555. }
  8556. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8557. if (!lua_interface)
  8558. return 0;
  8559. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8560. if(spell->resisted) {
  8561. lua_interface->ResetFunctionStack(state);
  8562. return 0;
  8563. }
  8564. int8 cure_count = lua_interface->GetInt8Value(state);
  8565. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8566. string cure_name = lua_interface->GetStringValue(state, 3);
  8567. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8568. Spawn* target = lua_interface->GetSpawn(state, 5);
  8569. lua_interface->ResetFunctionStack(state);
  8570. if (target) {
  8571. if (!target->IsEntity()) {
  8572. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8573. return 0;
  8574. }
  8575. if (((Entity*)target)->GetDetCount() > 0)
  8576. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8577. }
  8578. else {
  8579. ZoneServer* zone = spell->caster->GetZone();
  8580. vector<int32> targets = spell->targets;
  8581. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8582. for (int8 i = 0; i < targets.size(); i++) {
  8583. target = zone->GetSpawnByID(targets.at(i));
  8584. if (!target || !target->IsEntity())
  8585. continue;
  8586. if (((Entity*)target)->GetDetCount() > 0)
  8587. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8588. }
  8589. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8590. }
  8591. return 0;
  8592. }
  8593. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8594. if (!lua_interface)
  8595. return 0;
  8596. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8597. lua_interface->ResetFunctionStack(state);
  8598. if (!spell) {
  8599. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8600. return 0;
  8601. }
  8602. if (!spell->caster) {
  8603. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8604. return 0;
  8605. }
  8606. if (!spell->caster->GetZone()) {
  8607. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8608. return 0;
  8609. }
  8610. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8611. return 0;
  8612. }
  8613. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8614. if (!lua_interface)
  8615. return 0;
  8616. Spawn* spawn = lua_interface->GetSpawn(state);
  8617. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8618. lua_interface->ResetFunctionStack(state);
  8619. if (!spell) {
  8620. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8621. return 0;
  8622. }
  8623. if (spawn && spawn->IsEntity())
  8624. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8625. else {
  8626. ZoneServer* zone = spell->caster->GetZone();
  8627. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8628. for (int32 i = 0; i < spell->targets.size(); i++) {
  8629. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8630. if (!spawn || !spawn->IsEntity())
  8631. continue;
  8632. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8633. }
  8634. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8635. }
  8636. return 0;
  8637. }
  8638. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8639. if (!lua_interface)
  8640. return 0;
  8641. Spawn* spawn = lua_interface->GetSpawn(state);
  8642. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8643. lua_interface->ResetFunctionStack(state);
  8644. if (!spell) {
  8645. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8646. return 0;
  8647. }
  8648. if (spawn && spawn->IsEntity())
  8649. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8650. else {
  8651. ZoneServer* zone = spell->caster->GetZone();
  8652. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8653. for (int32 i = 0; i < spell->targets.size(); i++) {
  8654. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8655. if (!spawn || !spawn->IsEntity())
  8656. continue;
  8657. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8658. }
  8659. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8660. }
  8661. return 0;
  8662. }
  8663. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8664. if (!lua_interface)
  8665. return 0;
  8666. Spawn* caster = lua_interface->GetSpawn(state);
  8667. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8668. lua_interface->ResetFunctionStack(state);
  8669. if (!caster) {
  8670. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. if (!caster->IsPlayer()) {
  8674. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8675. return 0;
  8676. }
  8677. Spawn* target = caster->GetTarget();
  8678. if (!target) {
  8679. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8680. return 0;
  8681. }
  8682. Client* client = ((Player*)caster)->GetClient();
  8683. if (!client) {
  8684. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8685. return 0;
  8686. }
  8687. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8688. if (ho) {
  8689. ho->SetTarget(target->GetID());
  8690. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8691. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8692. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8693. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8694. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8695. deque<GroupMemberInfo*>::iterator itr;
  8696. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8697. if (group)
  8698. {
  8699. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8700. deque<GroupMemberInfo*>* members = group->GetMembers();
  8701. for (itr = members->begin(); itr != members->end(); itr++) {
  8702. if ((*itr)->client)
  8703. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8704. }
  8705. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8706. }
  8707. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8708. }
  8709. else
  8710. safe_delete(ho);
  8711. }
  8712. else {
  8713. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8714. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8715. }
  8716. else
  8717. safe_delete(ho);
  8718. }
  8719. }
  8720. return 0;
  8721. }
  8722. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8723. if (!lua_interface)
  8724. return 0;
  8725. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8726. if (!spell) {
  8727. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. int16 triggerCount = lua_interface->GetInt16Value(state);
  8731. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8732. if (!triggerCount) {
  8733. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. spell->num_triggers = triggerCount;
  8737. spell->had_triggers = true;
  8738. spell->cancel_after_all_triggers = cancel_after_triggers;
  8739. return 0;
  8740. }
  8741. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8742. if (!lua_interface)
  8743. return 0;
  8744. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8745. lua_interface->ResetFunctionStack(state);
  8746. if (!spell) {
  8747. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8748. return 0;
  8749. }
  8750. lua_interface->SetInt32Value(state, spell->num_triggers);
  8751. return 1;
  8752. }
  8753. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8754. if (!lua_interface)
  8755. return 0;
  8756. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8757. if (!spell) {
  8758. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8759. lua_interface->ResetFunctionStack(state);
  8760. return 0;
  8761. }
  8762. if (!spell->caster || !spell->caster->GetZone()) {
  8763. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8764. lua_interface->ResetFunctionStack(state);
  8765. return 0;
  8766. }
  8767. int16 remove_count = lua_interface->GetInt16Value(state);
  8768. lua_interface->ResetFunctionStack(state);
  8769. if (!remove_count)
  8770. remove_count = 1;
  8771. if (remove_count >= spell->num_triggers) {
  8772. spell->num_triggers = 0;
  8773. if (spell->cancel_after_all_triggers)
  8774. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8775. }
  8776. else {
  8777. spell->num_triggers -= remove_count;
  8778. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8779. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8780. }
  8781. return 0;
  8782. }
  8783. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8784. if (!lua_interface)
  8785. return 0;
  8786. Spawn* spawn = lua_interface->GetSpawn(state);
  8787. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8788. lua_interface->ResetFunctionStack(state);
  8789. if (!spawn) {
  8790. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8791. return 0;
  8792. }
  8793. if (!copy_spawn) {
  8794. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. spawn->CopySpawnAppearance(copy_spawn);
  8798. return 0;
  8799. }
  8800. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8801. Spawn* spawn = lua_interface->GetSpawn(state);
  8802. int8 type = lua_interface->GetInt8Value(state, 2);
  8803. lua_interface->ResetFunctionStack(state);
  8804. if (!spawn) {
  8805. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8806. return 0;
  8807. }
  8808. else if (!spawn->IsEntity()) {
  8809. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8810. return 0;
  8811. }
  8812. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8813. return 1;
  8814. }
  8815. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8816. if (!lua_interface)
  8817. return 0;
  8818. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8819. int8 type = lua_interface->GetInt8Value(state);
  8820. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8821. lua_interface->ResetFunctionStack(state);
  8822. if (!spell) {
  8823. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. if(spell->resisted) {
  8827. return 0;
  8828. }
  8829. if (spawn) {
  8830. if (!spawn->IsEntity()) {
  8831. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. Entity* entity = ((Entity*)spawn);
  8835. entity->AddImmunity(spell, type);
  8836. }
  8837. else if(spell->caster && spell->caster->GetZone()) {
  8838. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8839. for (int8 i = 0; i < spell->targets.size(); i++) {
  8840. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8841. if (!spawn || !spawn->IsEntity())
  8842. continue;
  8843. Entity* entity = ((Entity*)spawn);
  8844. entity->AddImmunity(spell, type);
  8845. }
  8846. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8847. }
  8848. return 0;
  8849. }
  8850. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8851. if (!lua_interface)
  8852. return 0;
  8853. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8854. int8 type = lua_interface->GetInt8Value(state);
  8855. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8856. lua_interface->ResetFunctionStack(state);
  8857. if (!spell) {
  8858. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8859. return 0;
  8860. }
  8861. if (spawn) {
  8862. if (!spawn->IsEntity()) {
  8863. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8864. return 0;
  8865. }
  8866. Entity* entity = ((Entity*)spawn);
  8867. entity->RemoveImmunity(spell, type);
  8868. }
  8869. else if(spell->caster && spell->caster->GetZone()) {
  8870. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8871. for (int8 i = 0; i < spell->targets.size(); i++) {
  8872. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8873. if (!spawn || !spawn->IsEntity())
  8874. continue;
  8875. Entity* entity = ((Entity*)spawn);
  8876. entity->RemoveImmunity(spell, type);
  8877. }
  8878. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8879. }
  8880. return 0;
  8881. }
  8882. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8883. if (!lua_interface)
  8884. return 0;
  8885. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8886. if(spell && spell->resisted) {
  8887. lua_interface->ResetFunctionStack(state);
  8888. return 0;
  8889. }
  8890. float snare = lua_interface->GetFloatValue(state);
  8891. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8892. lua_interface->ResetFunctionStack(state);
  8893. // convert the val to the speed multipler value (100 - val)
  8894. float val = 100.0 - snare;
  8895. val /= 100.0;
  8896. if (spawn) {
  8897. if (!spawn->IsEntity()) {
  8898. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8899. return 0;
  8900. }
  8901. ((Entity*)spawn)->SetSnareValue(spell, val);
  8902. }
  8903. else if(spell && spell->caster && spell->caster->GetZone()) {
  8904. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8905. for (int8 i = 0; i < spell->targets.size(); i++) {
  8906. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8907. if (!spawn || !spawn->IsEntity())
  8908. continue;
  8909. ((Entity*)spawn)->SetSnareValue(spell, val);
  8910. }
  8911. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8912. }
  8913. return 0;
  8914. }
  8915. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8916. if (!lua_interface)
  8917. return 0;
  8918. Spawn* spawn = lua_interface->GetSpawn(state);
  8919. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8920. lua_interface->ResetFunctionStack(state);
  8921. if (!spawn) {
  8922. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8923. return 0;
  8924. }
  8925. if (race_id == 0) {
  8926. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8927. return 0;
  8928. }
  8929. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8930. return 1;
  8931. }
  8932. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8933. if (!lua_interface)
  8934. return 0;
  8935. Spawn* spawn = lua_interface->GetSpawn(state);
  8936. lua_interface->ResetFunctionStack(state);
  8937. if (!spawn) {
  8938. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8939. return 0;
  8940. }
  8941. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8942. return 1;
  8943. }
  8944. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8945. if (!lua_interface)
  8946. return 0;
  8947. Spawn* spawn = lua_interface->GetSpawn(state);
  8948. lua_interface->ResetFunctionStack(state);
  8949. if (!spawn) {
  8950. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8951. return 0;
  8952. }
  8953. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8954. return 1;
  8955. }
  8956. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8957. if (!lua_interface)
  8958. return 0;
  8959. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8960. lua_interface->ResetFunctionStack(state);
  8961. if (!spell) {
  8962. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8963. return 0;
  8964. }
  8965. lua_interface->SetStringValue(state, spell->spell->GetName());
  8966. return 1;
  8967. }
  8968. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8969. if (!lua_interface)
  8970. return 0;
  8971. Quest* quest = lua_interface->GetQuest(state);
  8972. lua_interface->ResetFunctionStack(state);
  8973. if (!quest) {
  8974. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8975. return 0;
  8976. }
  8977. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8978. return 1;
  8979. }
  8980. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8981. if (!lua_interface)
  8982. return 0;
  8983. Quest* quest = lua_interface->GetQuest(state);
  8984. int32 flags = lua_interface->GetInt32Value(state, 2);
  8985. lua_interface->ResetFunctionStack(state);
  8986. if (!quest) {
  8987. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8988. return 0;
  8989. }
  8990. quest->SetQuestFlags(flags);
  8991. return 0;
  8992. }
  8993. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8994. if (!lua_interface)
  8995. return 0;
  8996. Quest* quest = lua_interface->GetQuest(state);
  8997. Spawn* player = lua_interface->GetSpawn(state, 2);
  8998. int32 step = lua_interface->GetInt32Value(state, 3);
  8999. int32 duration = lua_interface->GetInt32Value(state, 4);
  9000. string action = lua_interface->GetStringValue(state, 5);
  9001. lua_interface->ResetFunctionStack(state);
  9002. if (!quest) {
  9003. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  9004. return 0;
  9005. }
  9006. if (!player) {
  9007. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9008. return 0;
  9009. }
  9010. if (!player->IsPlayer()) {
  9011. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9012. return 0;
  9013. }
  9014. if (step == 0) {
  9015. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  9016. return 0;
  9017. }
  9018. if (duration == 0) {
  9019. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  9020. return 0;
  9021. }
  9022. if (action.length() == 0) {
  9023. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  9024. return 0;
  9025. }
  9026. Client* client = ((Player*)player)->GetClient();
  9027. if (!client) {
  9028. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9029. return 0;
  9030. }
  9031. quest->SetTimerStep(step);
  9032. quest->AddFailedAction(step, action);
  9033. quest->SetStepTimer(duration);
  9034. client->AddQuestTimer(quest->GetQuestID());
  9035. return 0;
  9036. }
  9037. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  9038. if (!lua_interface)
  9039. return 0;
  9040. Quest* quest = lua_interface->GetQuest(state);
  9041. Spawn* player = lua_interface->GetSpawn(state, 2);
  9042. lua_interface->ResetFunctionStack(state);
  9043. if (!quest) {
  9044. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  9045. return 0;
  9046. }
  9047. if (!player) {
  9048. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. if (!player->IsPlayer()) {
  9052. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. Client* client = ((Player*)player)->GetClient();
  9056. if (!client) {
  9057. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9058. return 0;
  9059. }
  9060. quest->SetTimerStep(0);
  9061. quest->SetStepTimer(0);
  9062. client->RemoveQuestTimer(quest->GetQuestID());
  9063. return 0;
  9064. }
  9065. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  9066. if (!lua_interface)
  9067. return 0;
  9068. Spawn* player = lua_interface->GetSpawn(state);
  9069. Quest* quest = lua_interface->GetQuest(state, 2);
  9070. int32 step = lua_interface->GetInt32Value(state, 3);
  9071. lua_interface->ResetFunctionStack(state);
  9072. if (!player) {
  9073. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9074. return 0;
  9075. }
  9076. if (!player->IsPlayer()) {
  9077. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9078. return 0;
  9079. }
  9080. if (!quest) {
  9081. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9082. return 0;
  9083. }
  9084. if (step == 0) {
  9085. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9086. return 0;
  9087. }
  9088. Client* client = ((Player*)player)->GetClient();
  9089. if (!client) {
  9090. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9091. return 0;
  9092. }
  9093. if (quest->RemoveQuestStep(step, client)) {
  9094. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9095. client->GetCurrentZone()->SendQuestUpdates(client);
  9096. }
  9097. else
  9098. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9099. return 0;
  9100. }
  9101. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9102. if (!lua_interface)
  9103. return 0;
  9104. Quest* quest = lua_interface->GetQuest(state, 1);
  9105. int32 step = lua_interface->GetInt32Value(state, 2);
  9106. string desc = lua_interface->GetStringValue(state, 3);
  9107. string task_group = lua_interface->GetStringValue(state, 4);
  9108. lua_interface->ResetFunctionStack(state);
  9109. if (!quest) {
  9110. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9111. return 0;
  9112. }
  9113. if (step == 0) {
  9114. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9115. return 0;
  9116. }
  9117. QuestStep* quest_step = quest->GetQuestStep(step);
  9118. if (!quest_step) {
  9119. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9120. return 0;
  9121. }
  9122. quest_step->SetStepProgress(0);
  9123. quest_step->SetTaskGroup(task_group);
  9124. quest_step->SetDescription(desc);
  9125. return 0;
  9126. }
  9127. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Quest* quest = lua_interface->GetQuest(state);
  9131. int32 step = lua_interface->GetInt32Value(state, 2);
  9132. string action = lua_interface->GetStringValue(state, 3);
  9133. lua_interface->ResetFunctionStack(state);
  9134. if (!quest) {
  9135. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. if (step == 0) {
  9139. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9140. return 0;
  9141. }
  9142. if (action.length() == 0) {
  9143. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9144. return 0;
  9145. }
  9146. quest->AddFailedAction(step, action);
  9147. return 0;
  9148. }
  9149. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9150. if (!lua_interface)
  9151. return 0;
  9152. Spawn* player = lua_interface->GetSpawn(state);
  9153. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9154. int32 step = lua_interface->GetInt32Value(state, 3);
  9155. lua_interface->ResetFunctionStack(state);
  9156. if (!player) {
  9157. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9158. return 0;
  9159. }
  9160. if (!player->IsPlayer()) {
  9161. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. if (quest_id == 0) {
  9165. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9166. return 0;
  9167. }
  9168. if (step == 0) {
  9169. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9170. return 0;
  9171. }
  9172. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9173. if (!quest) {
  9174. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9175. return 0;
  9176. }
  9177. quest->StepFailed(step);
  9178. return 0;
  9179. }
  9180. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9181. if (!lua_interface)
  9182. return 0;
  9183. Spawn* player = lua_interface->GetSpawn(state);
  9184. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9185. lua_interface->ResetFunctionStack(state);
  9186. if (!player) {
  9187. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9188. return 0;
  9189. }
  9190. if (!player->IsPlayer()) {
  9191. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9192. return 0;
  9193. }
  9194. if (quest_id == 0) {
  9195. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9196. return 0;
  9197. }
  9198. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9199. return 1;
  9200. }
  9201. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9202. if (!lua_interface)
  9203. return 0;
  9204. string name = lua_interface->GetStringValue(state);
  9205. string value = lua_interface->GetStringValue(state, 2);
  9206. string comment = lua_interface->GetStringValue(state, 3);
  9207. lua_interface->ResetFunctionStack(state);
  9208. if (name.length() == 0) {
  9209. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9210. return 0;
  9211. }
  9212. if (value.length() == 0) {
  9213. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9214. return 0;
  9215. }
  9216. string varname = string("lua_").append(name);
  9217. Variable* var = variables.FindVariable(varname);
  9218. if (var)
  9219. var->SetValue(value.c_str());
  9220. else {
  9221. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9222. variables.AddVariable(var);
  9223. }
  9224. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9225. return 0;
  9226. }
  9227. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9228. if (!lua_interface)
  9229. return 0;
  9230. string name = lua_interface->GetStringValue(state);
  9231. lua_interface->ResetFunctionStack(state);
  9232. if (name.length() == 0) {
  9233. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9234. return 0;
  9235. }
  9236. string varname = string("lua_").append(name);
  9237. Variable* var = variables.FindVariable(varname);
  9238. if (var)
  9239. lua_interface->SetStringValue(state, var->GetValue());
  9240. else
  9241. lua_interface->SetStringValue(state, "NULL");
  9242. return 1;
  9243. }
  9244. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9245. if (!lua_interface)
  9246. return 0;
  9247. Spawn* player = lua_interface->GetSpawn(state);
  9248. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9249. lua_interface->ResetFunctionStack(state);
  9250. if (!player) {
  9251. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9252. return 0;
  9253. }
  9254. if (!player->IsPlayer()) {
  9255. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9256. return 0;
  9257. }
  9258. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9259. return 1;
  9260. }
  9261. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9262. if (!lua_interface)
  9263. return 0;
  9264. Spawn* player = lua_interface->GetSpawn(state);
  9265. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9266. lua_interface->ResetFunctionStack(state);
  9267. if (!player) {
  9268. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9269. return 0;
  9270. }
  9271. if (!player->IsPlayer()) {
  9272. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. Language* language = master_languages_list.GetLanguage(language_id);
  9276. if (language)
  9277. {
  9278. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9279. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9280. }
  9281. return 0;
  9282. }
  9283. int EQ2Emu_lua_IsNight(lua_State* state) {
  9284. if (!lua_interface)
  9285. return 0;
  9286. ZoneServer* zone = lua_interface->GetZone(state);
  9287. lua_interface->ResetFunctionStack(state);
  9288. if (!zone) {
  9289. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9290. return 0;
  9291. }
  9292. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9293. return 1;
  9294. }
  9295. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9296. if (!lua_interface)
  9297. return 0;
  9298. Spawn* spawn = lua_interface->GetSpawn(state);
  9299. lua_interface->ResetFunctionStack(state);
  9300. if (!spawn) {
  9301. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9302. return 0;
  9303. }
  9304. if (!spawn->IsWidget()) {
  9305. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9306. return 0;
  9307. }
  9308. ((Widget*)spawn)->SetMultiFloorLift(true);
  9309. if (spawn->GetZone())
  9310. spawn->GetZone()->AddTransportSpawn(spawn);
  9311. return 0;
  9312. }
  9313. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9314. if (!lua_interface)
  9315. return 0;
  9316. Spawn* player = lua_interface->GetSpawn(state);
  9317. int32 path = lua_interface->GetInt32Value(state, 2);
  9318. lua_interface->ResetFunctionStack(state);
  9319. if (!player) {
  9320. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9321. return 0;
  9322. }
  9323. if (!player->IsPlayer()) {
  9324. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9325. return 0;
  9326. }
  9327. if (path == 0) {
  9328. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9329. return 0;
  9330. }
  9331. Client* client = ((Player*)player)->GetClient();
  9332. if (!client) {
  9333. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9334. return 0;
  9335. }
  9336. client->SendFlightAutoMount(path);
  9337. return 0;
  9338. }
  9339. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9340. if (!lua_interface)
  9341. return 0;
  9342. Spawn* player = lua_interface->GetSpawn(state);
  9343. if (!player) {
  9344. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9345. return 0;
  9346. }
  9347. if (!player->IsPlayer()) {
  9348. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9349. return 0;
  9350. }
  9351. Client* client = ((Player*)player)->GetClient();
  9352. if (!client) {
  9353. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9354. return 0;
  9355. }
  9356. client->EndAutoMount();
  9357. return 0;
  9358. }
  9359. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9360. if (!lua_interface)
  9361. return 0;
  9362. Spawn* player = lua_interface->GetSpawn(state);
  9363. lua_interface->ResetFunctionStack(state);
  9364. if (!player) {
  9365. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9366. return 0;
  9367. }
  9368. if (!player->IsPlayer()) {
  9369. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9370. return 0;
  9371. }
  9372. Client* client = ((Player*)player)->GetClient();
  9373. if (!client) {
  9374. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9375. return 0;
  9376. }
  9377. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9378. return 1;
  9379. }
  9380. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9381. if (!lua_interface)
  9382. return 0;
  9383. Spawn* player = lua_interface->GetSpawn(state);
  9384. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9385. int32 value = lua_interface->GetInt32Value(state, 3);
  9386. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9387. lua_interface->ResetFunctionStack(state);
  9388. if (!player) {
  9389. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9390. return 0;
  9391. }
  9392. if (!player->IsPlayer()) {
  9393. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9394. return 0;
  9395. }
  9396. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Spawn* player = lua_interface->GetSpawn(state);
  9403. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9404. lua_interface->ResetFunctionStack(state);
  9405. if (!player) {
  9406. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9407. return 0;
  9408. }
  9409. if (!player->IsPlayer()) {
  9410. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9411. return 0;
  9412. }
  9413. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9414. if (!hd)
  9415. return 0;
  9416. lua_interface->SetInt32Value(state, hd->Value);
  9417. lua_interface->SetInt32Value(state, hd->Value2);
  9418. return 2;
  9419. }
  9420. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9421. if (!lua_interface)
  9422. return 0;
  9423. Spawn* spawn = lua_interface->GetSpawn(state);
  9424. int32 grid = lua_interface->GetInt32Value(state, 2);
  9425. lua_interface->ResetFunctionStack(state);
  9426. if (!spawn) {
  9427. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9428. return 0;
  9429. }
  9430. if (grid == 0) {
  9431. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9432. return 0;
  9433. }
  9434. spawn->SetLocation(grid);
  9435. return 0;
  9436. }
  9437. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9438. if (!lua_interface)
  9439. return 0;
  9440. Spawn* spawn = lua_interface->GetSpawn(state);
  9441. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9442. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9443. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9444. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9445. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9446. lua_interface->ResetFunctionStack(state);
  9447. if (!spawn) {
  9448. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9449. return 0;
  9450. }
  9451. //Add this quest to the list of required quests for this spawn
  9452. spawn->SetRequiredHistory(event_id, value1, value2);
  9453. //If private spawn value set
  9454. if (private_spawn) {
  9455. //Set the spawn to be private when not granted access via history
  9456. spawn->AddAllowAccessSpawn(spawn);
  9457. spawn->SetPrivateQuestSpawn(true);
  9458. }
  9459. //This value will override vis_flags in the vis packet
  9460. if (flag_override > 0)
  9461. spawn->SetQuestsRequiredOverride(flag_override);
  9462. return 0;
  9463. }
  9464. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9465. if (!lua_interface)
  9466. return 0;
  9467. Spawn* player = lua_interface->GetSpawn(state);
  9468. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9469. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9470. lua_interface->ResetFunctionStack(state);
  9471. if (!player) {
  9472. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9473. return 0;
  9474. }
  9475. if (!player->IsPlayer()) {
  9476. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9477. return 0;
  9478. }
  9479. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9480. return 1;
  9481. }
  9482. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9483. if (!lua_interface)
  9484. return 0;
  9485. Spawn* player = lua_interface->GetSpawn(state);
  9486. int8 level = lua_interface->GetInt8Value(state, 2);
  9487. lua_interface->ResetFunctionStack(state);
  9488. if (!player) {
  9489. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9490. return 0;
  9491. }
  9492. if (!player->IsPlayer()) {
  9493. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9494. return 0;
  9495. }
  9496. if (level == 0) {
  9497. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9498. return 0;
  9499. }
  9500. Client* client = ((Player*)player)->GetClient();
  9501. if (!client) {
  9502. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9503. return 0;
  9504. }
  9505. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9506. return 0;
  9507. }
  9508. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9509. if (!lua_interface)
  9510. return 0;
  9511. Spawn* player = lua_interface->GetSpawn(state);
  9512. int32 amount = lua_interface->GetInt32Value(state, 2);
  9513. lua_interface->ResetFunctionStack(state);
  9514. if (!player) {
  9515. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9516. return 0;
  9517. }
  9518. if (!player->IsPlayer()) {
  9519. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9520. return 0;
  9521. }
  9522. if (amount == 0) {
  9523. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9524. return 0;
  9525. }
  9526. ((Player*)player)->AddCoins(amount);
  9527. return 0;
  9528. }
  9529. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9530. if (!lua_interface)
  9531. return 0;
  9532. Spawn* player = lua_interface->GetSpawn(state);
  9533. int32 amount = lua_interface->GetInt32Value(state, 2);
  9534. lua_interface->ResetFunctionStack(state);
  9535. if (!player) {
  9536. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9537. return 0;
  9538. }
  9539. if (!player->IsPlayer()) {
  9540. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9541. return 0;
  9542. }
  9543. if (amount == 0) {
  9544. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9545. return 0;
  9546. }
  9547. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9548. return 1;
  9549. }
  9550. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9551. if (!lua_interface)
  9552. return 0;
  9553. ZoneServer* zone = lua_interface->GetZone(state);
  9554. lua_interface->ResetFunctionStack(state);
  9555. if (!zone) {
  9556. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9557. return 0;
  9558. }
  9559. vector<Entity*> players = zone->GetPlayers();
  9560. if (players.size() == 0)
  9561. return 0;
  9562. lua_createtable(state, players.size(), 0);
  9563. int newTable = lua_gettop(state);
  9564. for (int32 i = 0; i < players.size(); i++) {
  9565. lua_interface->SetSpawnValue(state, players.at(i));
  9566. lua_rawseti(state, newTable, i + 1);
  9567. }
  9568. return 1;
  9569. }
  9570. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9571. if (!lua_interface)
  9572. return 0;
  9573. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9574. if (!zone) {
  9575. lua_interface->LogError("%s: LUA SpawnGroupByID command error: zone is not valid", lua_interface->GetScriptName(state));
  9576. return 0;
  9577. }
  9578. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9579. int16 custom_level = lua_interface->GetInt32Value(state, 3);
  9580. lua_interface->ResetFunctionStack(state);
  9581. //Map of <placement_id, location_id>
  9582. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9583. map<int32, int32>::iterator itr;
  9584. vector<Spawn*> group;
  9585. Spawn* leader = 0;
  9586. if(locs == nullptr)
  9587. return 0;
  9588. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9589. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9590. if (!location) {
  9591. lua_interface->LogError("%s: LUA SpawnGroupByID command error: no location found for group id %u and the given ID (%u)", lua_interface->GetScriptName(state), group_id, itr->second);
  9592. return 0;
  9593. }
  9594. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  9595. Spawn* spawn = 0;
  9596. if (location->entities[rand_number]) {
  9597. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9598. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  9599. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9600. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  9601. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9602. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  9603. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9604. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  9605. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9606. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  9607. if(spawn && spawn->IsOmittedByDBFlag())
  9608. {
  9609. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[rand_number]->spawn_id);
  9610. safe_delete(spawn);
  9611. continue;
  9612. }
  9613. if (spawn) {
  9614. if(!leader)
  9615. leader = spawn;
  9616. if(leader)
  9617. leader->AddSpawnToGroup(spawn);
  9618. spawn->SetSpawnGroupID(group_id);
  9619. if(custom_level > 0 && custom_level != 0xFFFF) {
  9620. spawn->SetLevel(custom_level);
  9621. }
  9622. const char* script = 0;
  9623. for (int x = 0; x < 3; x++) {
  9624. switch (x) {
  9625. case 0:
  9626. script = world.GetSpawnEntryScript(location->entities[rand_number]->spawn_entry_id);
  9627. break;
  9628. case 1:
  9629. script = world.GetSpawnLocationScript(location->entities[rand_number]->spawn_location_id);
  9630. break;
  9631. case 2:
  9632. script = world.GetSpawnScript(location->entities[rand_number]->spawn_id);
  9633. break;
  9634. }
  9635. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9636. spawn->SetSpawnScript(string(script));
  9637. break;
  9638. }
  9639. }
  9640. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9641. lua_interface->SetSpawnValue(state, spawn);
  9642. group.push_back(spawn);
  9643. }
  9644. else {
  9645. LogWrite(ZONE__ERROR, 0, "Zone", "%s: Error adding spawn by group id to zone %s with location id %u.", lua_interface->GetScriptName(state), zone->GetZoneName(), group_id);
  9646. safe_delete(spawn);
  9647. }
  9648. }
  9649. }
  9650. if (!group.empty()) {
  9651. lua_createtable(state, group.size(), 0);
  9652. int newTable = lua_gettop(state);
  9653. for (int32 i = 0; i < group.size(); i++) {
  9654. lua_interface->SetSpawnValue(state, group[i]);
  9655. lua_rawseti(state, newTable, i + 1);
  9656. }
  9657. }
  9658. else
  9659. lua_pushnil(state);
  9660. return 1;
  9661. }
  9662. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9663. if (!lua_interface)
  9664. return 0;
  9665. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9666. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9667. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9668. lua_interface->ResetFunctionStack(state);
  9669. if (!spawn) {
  9670. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9671. return 0;
  9672. }
  9673. if (anim_id == 0) {
  9674. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9675. return 0;
  9676. }
  9677. if (leeway == 0)
  9678. leeway = 5000;
  9679. spawn->SetSpawnAnim(anim_id);
  9680. spawn->SetSpawnAnimLeeway(leeway);
  9681. return 0;
  9682. }
  9683. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9684. if (!lua_interface)
  9685. return 0;
  9686. Spawn* player = lua_interface->GetSpawn(state);
  9687. lua_interface->ResetFunctionStack(state);
  9688. if (!player || !player->IsPlayer()) {
  9689. return 0;
  9690. }
  9691. Client* client = ((Player*)player)->GetClient();
  9692. if (!client) {
  9693. return 0;
  9694. }
  9695. lua_interface->SetInt32Value(state, client->GetVersion());
  9696. return 1;
  9697. }
  9698. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9699. if (!lua_interface)
  9700. return 0;
  9701. Item* item = lua_interface->GetItem(state);
  9702. lua_interface->ResetFunctionStack(state);
  9703. if (!item) {
  9704. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9705. return 0;
  9706. }
  9707. lua_interface->SetInt32Value(state, item->details.item_id);
  9708. return 1;
  9709. }
  9710. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9711. if (!lua_interface)
  9712. return 0;
  9713. Spawn* spawn = lua_interface->GetSpawn(state);
  9714. lua_interface->ResetFunctionStack(state);
  9715. if (!spawn) {
  9716. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9717. return 0;
  9718. }
  9719. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9720. return 1;
  9721. }
  9722. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9723. if (!lua_interface)
  9724. return 0;
  9725. Spawn* spawn = lua_interface->GetSpawn(state);
  9726. lua_interface->ResetFunctionStack(state);
  9727. if (!spawn) {
  9728. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9729. return 0;
  9730. }
  9731. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9732. return 1;
  9733. }
  9734. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9735. if (!lua_interface)
  9736. return 0;
  9737. Spawn* spawn = lua_interface->GetSpawn(state);
  9738. lua_interface->ResetFunctionStack(state);
  9739. if (!spawn) {
  9740. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9741. return 0;
  9742. }
  9743. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9744. return 1;
  9745. }
  9746. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9747. if (!lua_interface)
  9748. return 0;
  9749. Spawn* spawn = lua_interface->GetSpawn(state);
  9750. lua_interface->ResetFunctionStack(state);
  9751. if (!spawn) {
  9752. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9753. return 0;
  9754. }
  9755. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9756. return 1;
  9757. }
  9758. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9759. if (!lua_interface)
  9760. return 0;
  9761. Spawn* spawn = lua_interface->GetSpawn(state);
  9762. float pct = lua_interface->GetFloatValue(state, 2);
  9763. lua_interface->ResetFunctionStack(state);
  9764. if (!spawn) {
  9765. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9766. return 0;
  9767. }
  9768. if (pct == 0) {
  9769. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9770. return 0;
  9771. }
  9772. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9773. lua_interface->SetInt32Value(state, amount);
  9774. return 1;
  9775. }
  9776. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9777. if (!lua_interface)
  9778. return 0;
  9779. Spawn* spawn = lua_interface->GetSpawn(state);
  9780. float pct = lua_interface->GetFloatValue(state, 2);
  9781. lua_interface->ResetFunctionStack(state);
  9782. if (!spawn) {
  9783. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9784. return 0;
  9785. }
  9786. if (pct == 0) {
  9787. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9788. return 0;
  9789. }
  9790. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9791. lua_interface->SetInt32Value(state, amount);
  9792. return 1;
  9793. }
  9794. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9795. if (!lua_interface)
  9796. return 0;
  9797. Spawn* spawn = lua_interface->GetSpawn(state);
  9798. lua_interface->ResetFunctionStack(state);
  9799. if (!spawn) {
  9800. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9801. return 0;
  9802. }
  9803. if (!spawn->IsPlayer()) {
  9804. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9805. return 0;
  9806. }
  9807. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9808. return 1;
  9809. }
  9810. int EQ2Emu_lua_Evac(lua_State* state) {
  9811. if (!lua_interface)
  9812. return 0;
  9813. Spawn* target = lua_interface->GetSpawn(state);
  9814. if (target) {
  9815. float x = target->GetZone()->GetSafeX();
  9816. float y = target->GetZone()->GetSafeY();
  9817. float z = target->GetZone()->GetSafeZ();
  9818. float h = target->GetZone()->GetSafeHeading();
  9819. target->SetX(x);
  9820. target->SetY(y);
  9821. target->SetZ(z);
  9822. target->SetHeading(h);
  9823. target->SetSpawnOrigX(x);
  9824. target->SetSpawnOrigY(y);
  9825. target->SetSpawnOrigZ(z);
  9826. target->SetSpawnOrigHeading(h);
  9827. if (target->IsPlayer()) {
  9828. Client* client = ((Player*)target)->GetClient();
  9829. if (client) {
  9830. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9831. int numargs = lua_interface->GetNumberOfArgs(state);
  9832. if(numargs == 4) {
  9833. x = lua_interface->GetFloatValue(state,1);
  9834. y = lua_interface->GetFloatValue(state,2);
  9835. z = lua_interface->GetFloatValue(state,3);
  9836. h = lua_interface->GetFloatValue(state,4);
  9837. }
  9838. client->SetReloadingZone(true);
  9839. target->SetX(x);
  9840. target->SetY(y);
  9841. target->SetZ(z);
  9842. target->SetHeading(h);
  9843. target->SetSpawnOrigX(x);
  9844. target->SetSpawnOrigY(y);
  9845. target->SetSpawnOrigZ(z);
  9846. target->SetSpawnOrigHeading(h);
  9847. target->SetAppearancePosition(x,y,z);
  9848. client->SetZoningCoords(x,y,z,h);
  9849. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9850. if (packet)
  9851. {
  9852. packet->setDataByName("x", x);
  9853. packet->setDataByName("y", y);
  9854. packet->setDataByName("z", z);
  9855. client->QueuePacket(packet->serialize());
  9856. safe_delete(packet);
  9857. }
  9858. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9859. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9860. }
  9861. }
  9862. lua_interface->ResetFunctionStack(state);
  9863. }
  9864. else {
  9865. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9866. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9867. lua_interface->ResetFunctionStack(state);
  9868. return 0;
  9869. }
  9870. ZoneServer* zone = spell->caster->GetZone();
  9871. float x = spell->caster->GetZone()->GetSafeX();
  9872. float y = spell->caster->GetZone()->GetSafeY();
  9873. float z = spell->caster->GetZone()->GetSafeZ();
  9874. float h = spell->caster->GetZone()->GetSafeHeading();
  9875. int numargs = lua_interface->GetNumberOfArgs(state);
  9876. if(numargs == 4) {
  9877. x = lua_interface->GetFloatValue(state,1);
  9878. y = lua_interface->GetFloatValue(state,2);
  9879. z = lua_interface->GetFloatValue(state,3);
  9880. h = lua_interface->GetFloatValue(state,4);
  9881. }
  9882. lua_interface->ResetFunctionStack(state);
  9883. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9884. for (int32 i = 0; i < spell->targets.size(); i++) {
  9885. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9886. if (!target2)
  9887. continue;
  9888. if (target2->IsPlayer()) {
  9889. Client* client = ((Player*)target2)->GetClient();
  9890. if (client) {
  9891. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9892. client->SetReloadingZone(true);
  9893. target2->SetX(x);
  9894. target2->SetY(y);
  9895. target2->SetZ(z);
  9896. target2->SetHeading(h);
  9897. target2->SetSpawnOrigX(x);
  9898. target2->SetSpawnOrigY(y);
  9899. target2->SetSpawnOrigZ(z);
  9900. target2->SetSpawnOrigHeading(h);
  9901. target2->SetAppearancePosition(x,y,z);
  9902. client->SetZoningCoords(x,y,z,h);
  9903. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9904. if (packet)
  9905. {
  9906. packet->setDataByName("x", x);
  9907. packet->setDataByName("y", y);
  9908. packet->setDataByName("z", z);
  9909. client->QueuePacket(packet->serialize());
  9910. safe_delete(packet);
  9911. }
  9912. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9913. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9914. }
  9915. }
  9916. }
  9917. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9918. }
  9919. return 0;
  9920. }
  9921. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9922. if (!lua_interface)
  9923. return 0;
  9924. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9925. lua_interface->ResetFunctionStack(state);
  9926. if (!luaspell || !luaspell->spell) {
  9927. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9928. return 0;
  9929. }
  9930. int8 tier = luaspell->spell->GetSpellTier();
  9931. lua_interface->SetInt32Value(state, tier);
  9932. return 1;
  9933. }
  9934. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9935. if (!lua_interface)
  9936. return 0;
  9937. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9938. lua_interface->ResetFunctionStack(state);
  9939. if (!luaspell || !luaspell->spell) {
  9940. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9941. return 0;
  9942. }
  9943. int32 spell_id = luaspell->spell->GetSpellID();
  9944. lua_interface->SetInt32Value(state, spell_id);
  9945. return 1;
  9946. }
  9947. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9948. if (!lua_interface)
  9949. return 0;
  9950. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9951. lua_interface->ResetFunctionStack(state);
  9952. if (!spawn) {
  9953. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9954. return 0;
  9955. }
  9956. if (!spawn->IsPlayer()) {
  9957. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9958. return 0;
  9959. }
  9960. ZoneServer* zone = spawn->GetZone();
  9961. if (!zone) {
  9962. return 0;
  9963. }
  9964. Client* client = ((Player*)spawn)->GetClient();
  9965. if (!client) {
  9966. return 0;
  9967. }
  9968. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9969. return 0;
  9970. }
  9971. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9972. if (!lua_interface)
  9973. return 0;
  9974. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9975. lua_interface->ResetFunctionStack(state);
  9976. if (!spawn) {
  9977. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9978. return 0;
  9979. }
  9980. if (!spawn->IsPlayer()) {
  9981. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9982. return 0;
  9983. }
  9984. ZoneServer* zone = spawn->GetZone();
  9985. if (!zone) {
  9986. return 0;
  9987. }
  9988. Client* client = ((Player*)spawn)->GetClient();
  9989. if (!client) {
  9990. return 0;
  9991. }
  9992. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9993. return 0;
  9994. }
  9995. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. Spawn* caster = lua_interface->GetSpawn(state);
  9999. Spawn* target = lua_interface->GetSpawn(state, 2);
  10000. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  10001. string spell_name = lua_interface->GetStringValue(state, 4);
  10002. lua_interface->ResetFunctionStack(state);
  10003. if (!caster) {
  10004. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10005. return 0;
  10006. }
  10007. if (!caster->IsEntity()) {
  10008. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  10009. return 0;
  10010. }
  10011. if (!target) {
  10012. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10013. return 0;
  10014. }
  10015. if (!target->IsEntity()) {
  10016. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  10017. return 0;
  10018. }
  10019. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  10020. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  10021. return 0;
  10022. }
  10023. int EQ2Emu_lua_GiveExp(lua_State* state) {
  10024. if (!lua_interface)
  10025. return 0;
  10026. Spawn* player = lua_interface->GetSpawn(state);
  10027. int32 amount = lua_interface->GetInt32Value(state, 2);
  10028. lua_interface->ResetFunctionStack(state);
  10029. if (player && player->IsPlayer() && amount > 0) {
  10030. ((Player*)player)->AddXP(amount);
  10031. }
  10032. return 0;
  10033. }
  10034. int EQ2Emu_lua_DisplayText(lua_State* state) {
  10035. if (!lua_interface)
  10036. return 0;
  10037. Spawn* player = lua_interface->GetSpawn(state);
  10038. int8 type = lua_interface->GetInt8Value(state, 2);
  10039. string text = lua_interface->GetStringValue(state, 3);
  10040. lua_interface->ResetFunctionStack(state);
  10041. Client* client = 0;
  10042. if (player && player->IsPlayer())
  10043. client = ((Player*)player)->GetClient();
  10044. if (!client || text.length() == 0) {
  10045. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  10046. return 0;
  10047. }
  10048. client->SimpleMessage(type, text.c_str());
  10049. return 0;
  10050. }
  10051. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  10052. if (!lua_interface)
  10053. return 0;
  10054. Spawn* player = lua_interface->GetSpawn(state);
  10055. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10056. lua_interface->ResetFunctionStack(state);
  10057. Client* client = 0;
  10058. if (player && player->IsPlayer())
  10059. client = ((Player*)player)->GetClient();
  10060. if (!client || !spawn) {
  10061. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  10062. return 0;
  10063. }
  10064. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  10065. if (!items) {
  10066. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  10067. return 0;
  10068. }
  10069. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  10070. return 0;
  10071. }
  10072. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  10073. if (!lua_interface)
  10074. return 0;
  10075. Spawn* spawnref = lua_interface->GetSpawn(state);
  10076. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10077. lua_interface->ResetFunctionStack(state);
  10078. if (spawn_id > 0 && spawnref) {
  10079. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10080. if (spawns.size() == 0) {
  10081. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10082. return 0;
  10083. }
  10084. Spawn* spawn = 0;
  10085. int16 index = MakeRandomInt(0, spawns.size());
  10086. if (index >= spawns.size() || index < 0)
  10087. index = 0;
  10088. spawn = spawns[index];
  10089. lua_interface->SetSpawnValue(state, spawn);
  10090. return 1;
  10091. }
  10092. else {
  10093. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10094. }
  10095. return 0;
  10096. }
  10097. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10098. Spawn* player = lua_interface->GetSpawn(state);
  10099. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10100. string name = lua_interface->GetStringValue(state, 3);
  10101. float distance = lua_interface->GetFloatValue(state, 4);
  10102. string command = lua_interface->GetStringValue(state, 5);
  10103. string error_text = lua_interface->GetStringValue(state, 6);
  10104. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10105. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10106. lua_interface->ResetFunctionStack(state);
  10107. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10108. if (distance == 0)
  10109. distance = 10.0f;
  10110. if (command.length() == 0)
  10111. command = name;
  10112. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10113. if (spawns.size() == 0) {
  10114. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10115. return 0;
  10116. }
  10117. Spawn* spawn = 0;
  10118. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10119. spawn = *itr;
  10120. if (spawn) {
  10121. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10122. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10123. }
  10124. }
  10125. }
  10126. return 0;
  10127. }
  10128. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10129. if (!lua_interface)
  10130. return 0;
  10131. Client* client = 0;
  10132. Spawn* player = lua_interface->GetSpawn(state);
  10133. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10134. lua_interface->ResetFunctionStack(state);
  10135. if (player && player->IsPlayer() && player->GetZone())
  10136. client = ((Player*)player)->GetClient();
  10137. else{
  10138. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10139. return 0;
  10140. }
  10141. if (client) {
  10142. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10143. if (packet) {
  10144. packet->setDataByName("goal_num", goal_num);
  10145. client->QueuePacket(packet->serialize());
  10146. safe_delete(packet);
  10147. }
  10148. }
  10149. return 0;
  10150. }
  10151. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10152. if (!lua_interface)
  10153. return 0;
  10154. Client* client = 0;
  10155. Spawn* player = lua_interface->GetSpawn(state);
  10156. lua_interface->ResetFunctionStack(state);
  10157. if (player && player->IsPlayer() && player->GetZone())
  10158. client = ((Player*)player)->GetClient();
  10159. else {
  10160. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10161. return 0;
  10162. }
  10163. if (client && client->GetVersion() >= 374) {
  10164. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10165. }
  10166. return 0;
  10167. }
  10168. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10169. if (!lua_interface)
  10170. return 0;
  10171. Client* client = 0;
  10172. Spawn* player = lua_interface->GetSpawn(state);
  10173. float duration = lua_interface->GetFloatValue(state, 2);
  10174. string text = lua_interface->GetStringValue(state, 3);
  10175. string voice = lua_interface->GetStringValue(state, 4);
  10176. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10177. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10178. string signal = lua_interface->GetStringValue(state, 7);
  10179. string goal1 = lua_interface->GetStringValue(state, 8);
  10180. string task1 = lua_interface->GetStringValue(state, 9);
  10181. string goal2 = lua_interface->GetStringValue(state, 10);
  10182. string task2 = lua_interface->GetStringValue(state, 11);
  10183. string goal3 = lua_interface->GetStringValue(state, 12);
  10184. string task3 = lua_interface->GetStringValue(state, 13);
  10185. string goal4 = lua_interface->GetStringValue(state, 14);
  10186. string task4 = lua_interface->GetStringValue(state, 15);
  10187. lua_interface->ResetFunctionStack(state);
  10188. if (!player) {
  10189. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10190. return 0;
  10191. }
  10192. if (!player->IsPlayer()) {
  10193. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10194. return 0;
  10195. }
  10196. else
  10197. client = ((Player*)player)->GetClient();
  10198. if (!client) {
  10199. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10200. return 0;
  10201. }
  10202. if (text.length() == 0) {
  10203. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10204. return 0;
  10205. }
  10206. if (duration >= 0 && duration < 2)
  10207. duration = 2;
  10208. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10209. if (packet) {
  10210. packet->setDataByName("open_seconds_max", duration);
  10211. packet->setDataByName("text", text.c_str());
  10212. packet->setDataByName("voice", voice.c_str());
  10213. int8 num_goals = 1;
  10214. if (task2.length() > 0)
  10215. num_goals++;
  10216. if (task3.length() > 0)
  10217. num_goals++;
  10218. if (task4.length() > 0)
  10219. num_goals++;
  10220. packet->setArrayLengthByName("num_goals", num_goals);
  10221. for (int8 i = 0; i < num_goals; i++) {
  10222. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10223. }
  10224. if (goal1.length() > 0)
  10225. packet->setArrayDataByName("goal_text", goal1.c_str());
  10226. if (goal2.length() > 0)
  10227. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10228. if (goal3.length() > 0)
  10229. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10230. if (goal4.length() > 0)
  10231. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10232. packet->setSubArrayDataByName("task_text", task1.c_str());
  10233. if (task2.length() > 0)
  10234. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10235. if (task3.length() > 0)
  10236. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10237. if (task4.length() > 0)
  10238. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10239. packet->setDataByName("complete_sound", "click");
  10240. packet->setDataByName("signal", signal.c_str());
  10241. packet->setDataByName("voice_key1", voice_key1);
  10242. packet->setDataByName("voice_key2", voice_key2);
  10243. client->QueuePacket(packet->serialize());
  10244. safe_delete(packet);
  10245. }
  10246. return 0;
  10247. }
  10248. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10249. if (!lua_interface)
  10250. return 0;
  10251. Client* client = 0;
  10252. Spawn* player = lua_interface->GetSpawn(state);
  10253. string window = lua_interface->GetStringValue(state, 2);
  10254. int8 show = lua_interface->GetInt8Value(state, 3);
  10255. lua_interface->ResetFunctionStack(state);
  10256. if (!player) {
  10257. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10258. return 0;
  10259. }
  10260. if (!player->IsPlayer()) {
  10261. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10262. return 0;
  10263. }
  10264. else
  10265. client = ((Player*)player)->GetClient();
  10266. if (!client) {
  10267. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10268. return 0;
  10269. }
  10270. if (window.length() == 0) {
  10271. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10272. return 0;
  10273. }
  10274. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10275. if (packet) {
  10276. packet->setDataByName("window", window.c_str());
  10277. packet->setDataByName("show", show);
  10278. client->QueuePacket(packet->serialize());
  10279. safe_delete(packet);
  10280. }
  10281. return 0;
  10282. }
  10283. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10284. //See GameEvents.txt for options that can be used for this function
  10285. if (!lua_interface)
  10286. return 0;
  10287. Client* client = 0;
  10288. Spawn* player = lua_interface->GetSpawn(state);
  10289. string event_name = lua_interface->GetStringValue(state, 2);
  10290. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10291. lua_interface->ResetFunctionStack(state);
  10292. if (!player || !player->IsPlayer()) {
  10293. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10294. return 0;
  10295. }
  10296. client = ((Player*)player)->GetClient();
  10297. if (!client) {
  10298. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10299. return 0;
  10300. }
  10301. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10302. if (packet) {
  10303. packet->setDataByName("event_name", event_name.c_str());
  10304. packet->setDataByName("enabled", enabled);
  10305. client->QueuePacket(packet->serialize());
  10306. safe_delete(packet);
  10307. }
  10308. return 0;
  10309. }
  10310. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10311. if (!lua_interface)
  10312. return 0;
  10313. Spawn* player = lua_interface->GetSpawn(state);
  10314. lua_interface->ResetFunctionStack(state);
  10315. if (player && player->IsPlayer()) {
  10316. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10317. return 1;
  10318. }
  10319. return 0;
  10320. }
  10321. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10322. if (!lua_interface)
  10323. return 0;
  10324. Spawn* player = lua_interface->GetSpawn(state);
  10325. int8 step = lua_interface->GetInt8Value(state, 2);
  10326. lua_interface->ResetFunctionStack(state);
  10327. if (player && player->IsPlayer() && step > 0) {
  10328. ((Player*)player)->SetTutorialStep(step);
  10329. }
  10330. return 0;
  10331. }
  10332. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10333. if (!lua_interface)
  10334. return 0;
  10335. Client* client = 0;
  10336. Spawn* player = lua_interface->GetSpawn(state);
  10337. string window = lua_interface->GetStringValue(state, 2);
  10338. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10339. lua_interface->ResetFunctionStack(state);
  10340. if (!player) {
  10341. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10342. return 0;
  10343. }
  10344. if (!player->IsPlayer()) {
  10345. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10346. return 0;
  10347. }
  10348. else
  10349. client = ((Player*)player)->GetClient();
  10350. if (!client) {
  10351. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10352. return 0;
  10353. }
  10354. if (window.length() == 0) {
  10355. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10356. return 0;
  10357. }
  10358. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10359. if (packet) {
  10360. packet->setDataByName("window", window.c_str());
  10361. packet->setDataByName("flash_seconds", flash_seconds);
  10362. client->QueuePacket(packet->serialize());
  10363. safe_delete(packet);
  10364. }
  10365. return 0;
  10366. }
  10367. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10368. if (!lua_interface)
  10369. return 0;
  10370. Spawn* spawn = lua_interface->GetSpawn(state);
  10371. Spawn* target = lua_interface->GetSpawn(state, 2);
  10372. lua_interface->ResetFunctionStack(state);
  10373. if (spawn && target)
  10374. return spawn->CheckLoS(target);
  10375. return 0;
  10376. }
  10377. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10378. if (!lua_interface)
  10379. return 0;
  10380. Spawn* spawn = lua_interface->GetSpawn(state);
  10381. float x = lua_interface->GetFloatValue(state, 2);
  10382. float y = lua_interface->GetFloatValue(state, 3);
  10383. float z = lua_interface->GetFloatValue(state, 4);
  10384. lua_interface->ResetFunctionStack(state);
  10385. if (spawn)
  10386. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10387. return 0;
  10388. }
  10389. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10390. if (!lua_interface)
  10391. return 0;
  10392. ZoneServer* zone = lua_interface->GetZone(state);
  10393. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10394. lua_interface->ResetFunctionStack(state);
  10395. if (zone)
  10396. zone->SetExpansionFlag(xpackFlag);
  10397. return 0;
  10398. }
  10399. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10400. if (!lua_interface)
  10401. return 0;
  10402. ZoneServer* zone = lua_interface->GetZone(state);
  10403. lua_interface->ResetFunctionStack(state);
  10404. if (zone) {
  10405. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10406. return 1;
  10407. }
  10408. return 0;
  10409. }
  10410. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10411. if (!lua_interface)
  10412. return 0;
  10413. ZoneServer* zone = lua_interface->GetZone(state);
  10414. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10415. lua_interface->ResetFunctionStack(state);
  10416. if (zone)
  10417. zone->SetHolidayFlag(holidayFlag);
  10418. return 0;
  10419. }
  10420. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10421. if (!lua_interface)
  10422. return 0;
  10423. ZoneServer* zone = lua_interface->GetZone(state);
  10424. lua_interface->ResetFunctionStack(state);
  10425. if (zone) {
  10426. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10427. return 1;
  10428. }
  10429. return 0;
  10430. }
  10431. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10432. if (!lua_interface)
  10433. return 0;
  10434. Spawn* spawn = lua_interface->GetSpawn(state);
  10435. bool canbind = lua_interface->GetInt32Value(state, 2);
  10436. lua_interface->ResetFunctionStack(state);
  10437. if(!spawn) {
  10438. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10439. return 0;
  10440. }
  10441. ZoneServer* zone = spawn->GetZone();
  10442. if (zone)
  10443. zone->SetCanBind(canbind);
  10444. return 0;
  10445. }
  10446. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10447. if (!lua_interface)
  10448. return 0;
  10449. Spawn* spawn = lua_interface->GetSpawn(state);
  10450. lua_interface->ResetFunctionStack(state);
  10451. if(!spawn) {
  10452. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10453. return 0;
  10454. }
  10455. ZoneServer* zone = spawn->GetZone();
  10456. if (zone) {
  10457. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10458. return 1;
  10459. }
  10460. return 0;
  10461. }
  10462. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10463. if (!lua_interface)
  10464. return 0;
  10465. Spawn* spawn = lua_interface->GetSpawn(state);
  10466. bool cangate = lua_interface->GetInt32Value(state, 2);
  10467. lua_interface->ResetFunctionStack(state);
  10468. if(!spawn) {
  10469. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10470. return 0;
  10471. }
  10472. ZoneServer* zone = spawn->GetZone();
  10473. if (zone)
  10474. zone->SetCanGate(cangate);
  10475. return 0;
  10476. }
  10477. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10478. if (!lua_interface)
  10479. return 0;
  10480. Spawn* spawn = lua_interface->GetSpawn(state);
  10481. lua_interface->ResetFunctionStack(state);
  10482. if(!spawn) {
  10483. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10484. return 0;
  10485. }
  10486. ZoneServer* zone = spawn->GetZone();
  10487. if (zone) {
  10488. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10489. return 1;
  10490. }
  10491. return 0;
  10492. }
  10493. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10494. if (!lua_interface)
  10495. return 0;
  10496. Spawn* spawn = lua_interface->GetSpawn(state);
  10497. bool canevac = lua_interface->GetInt32Value(state, 2);
  10498. lua_interface->ResetFunctionStack(state);
  10499. if(!spawn) {
  10500. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10501. return 0;
  10502. }
  10503. ZoneServer* zone = spawn->GetZone();
  10504. if (zone)
  10505. zone->SetCanEvac(canevac);
  10506. return 0;
  10507. }
  10508. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10509. if (!lua_interface)
  10510. return 0;
  10511. Spawn* spawn = lua_interface->GetSpawn(state);
  10512. lua_interface->ResetFunctionStack(state);
  10513. if(!spawn) {
  10514. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10515. return 0;
  10516. }
  10517. ZoneServer* zone = spawn->GetZone();
  10518. if (zone) {
  10519. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10520. return 1;
  10521. }
  10522. return 0;
  10523. }
  10524. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10525. if (!lua_interface)
  10526. return 0;
  10527. Spawn* spawn = lua_interface->GetSpawn(state);
  10528. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10529. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10530. float distance = lua_interface->GetFloatValue(state, 4);
  10531. string in_range_function = lua_interface->GetStringValue(state, 5);
  10532. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10533. lua_interface->ResetFunctionStack(state);
  10534. if (spawn && distance > 0 && in_range_function.length() > 0)
  10535. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10536. return 0;
  10537. }
  10538. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10539. if (!lua_interface)
  10540. return 0;
  10541. Spawn* spawn = lua_interface->GetSpawn(state);
  10542. Spawn* target = lua_interface->GetSpawn(state, 2);
  10543. lua_interface->ResetFunctionStack(state);
  10544. if (spawn && target)
  10545. {
  10546. if (spawn->IsPlayer() && target->IsEntity())
  10547. {
  10548. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10549. return 1;
  10550. }
  10551. else if (spawn->IsEntity() && target->IsEntity())
  10552. {
  10553. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10554. return 1;
  10555. }
  10556. }
  10557. return 0;
  10558. }
  10559. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10560. if (!lua_interface)
  10561. return 0;
  10562. Spawn* spawn = lua_interface->GetSpawn(state);
  10563. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10564. lua_interface->ResetFunctionStack(state);
  10565. if (spawn && spawn->IsEntity())
  10566. {
  10567. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10568. if (spawn->IsPlayer())
  10569. {
  10570. Client* client = ((Player*)spawn)->GetClient();
  10571. if (client)
  10572. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10573. }
  10574. }
  10575. return 0;
  10576. }
  10577. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10578. if (!lua_interface)
  10579. return 0;
  10580. Spawn* spawn = lua_interface->GetSpawn(state);
  10581. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10582. lua_interface->ResetFunctionStack(state);
  10583. if (spawn && spawn->IsEntity())
  10584. {
  10585. ((Entity*)spawn)->SetSeeHideSpell(val);
  10586. if (spawn->IsPlayer())
  10587. {
  10588. Client* client = ((Player*)spawn)->GetClient();
  10589. if (client)
  10590. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10591. }
  10592. }
  10593. return 0;
  10594. }
  10595. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10596. {
  10597. if (!lua_interface)
  10598. return 0;
  10599. Spawn* player = lua_interface->GetSpawn(state);
  10600. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10601. string command = lua_interface->GetStringValue(state, 3);
  10602. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10603. lua_interface->ResetFunctionStack(state);
  10604. if (spawn && player && player->IsPlayer())
  10605. {
  10606. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10607. bool res = false;
  10608. if (cmd)
  10609. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10610. lua_interface->SetBooleanValue(state, res);
  10611. return 1;
  10612. }
  10613. return 0;
  10614. }
  10615. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10616. {
  10617. if (!lua_interface)
  10618. return 0;
  10619. Spawn* spawn = lua_interface->GetSpawn(state);
  10620. int32 charID = lua_interface->GetInt32Value(state, 2);
  10621. string command = lua_interface->GetStringValue(state, 3);
  10622. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10623. lua_interface->ResetFunctionStack(state);
  10624. if (spawn && charID)
  10625. {
  10626. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10627. bool res = false;
  10628. if (cmd)
  10629. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10630. lua_interface->SetBooleanValue(state, res);
  10631. return 1;
  10632. }
  10633. return 0;
  10634. }
  10635. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10636. {
  10637. if (!lua_interface)
  10638. return 0;
  10639. Spawn* spawn = lua_interface->GetSpawn(state);
  10640. string command = lua_interface->GetStringValue(state, 2);
  10641. lua_interface->ResetFunctionStack(state);
  10642. if (spawn && command.length() > 0)
  10643. spawn->RemovePrimaryEntityCommand(command.c_str());
  10644. return 0;
  10645. }
  10646. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10647. if (!lua_interface)
  10648. return 0;
  10649. Spawn* spawn = lua_interface->GetSpawn(state);
  10650. float distance = lua_interface->GetFloatValue(state, 2);
  10651. string command = lua_interface->GetStringValue(state, 3);
  10652. Spawn* player = lua_interface->GetSpawn(state, 4);
  10653. lua_interface->ResetFunctionStack(state);
  10654. if (spawn) {
  10655. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10656. }
  10657. return 0;
  10658. }
  10659. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10660. if (!lua_interface)
  10661. return 0;
  10662. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10663. Spawn* spawn = lua_interface->GetSpawn(state);
  10664. Spawn* player = lua_interface->GetSpawn(state, 2);
  10665. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10666. lua_interface->ResetFunctionStack(state);
  10667. if (spawn && player && transport_id && player->IsPlayer()) {
  10668. Client* client = 0;
  10669. if (player && player->IsPlayer())
  10670. client = ((Player*)player)->GetClient();
  10671. if (!client)
  10672. return 0;
  10673. vector<TransportDestination*> destinations;
  10674. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10675. if (destinations.size())
  10676. {
  10677. client->SetTemporaryTransportID(transport_id);
  10678. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10679. }
  10680. else
  10681. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10682. }
  10683. return 0;
  10684. }
  10685. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10686. if (!lua_interface)
  10687. return 0;
  10688. Spawn* player = lua_interface->GetSpawn(state);
  10689. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10690. lua_interface->ResetFunctionStack(state);
  10691. if (player && player->IsPlayer()) {
  10692. Client* client = 0;
  10693. if (player && player->IsPlayer())
  10694. client = ((Player*)player)->GetClient();
  10695. if (!client)
  10696. return 0;
  10697. client->SetTemporaryTransportID(transport_id);
  10698. }
  10699. return 0;
  10700. }
  10701. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10702. if (!lua_interface)
  10703. return 0;
  10704. Spawn* player = lua_interface->GetSpawn(state);
  10705. lua_interface->ResetFunctionStack(state);
  10706. if (player && player->IsPlayer()) {
  10707. Client* client = 0;
  10708. if (player && player->IsPlayer())
  10709. client = ((Player*)player)->GetClient();
  10710. if (!client)
  10711. return 0;
  10712. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10713. return 1;
  10714. }
  10715. return 0;
  10716. }
  10717. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10718. if (!lua_interface)
  10719. return 0;
  10720. Spawn* spawn = lua_interface->GetSpawn(state);
  10721. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10722. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10723. if (!spawn) {
  10724. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10725. return 0;
  10726. }
  10727. if (!spawn->IsEntity()) {
  10728. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10729. return 0;
  10730. }
  10731. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10732. {
  10733. 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);
  10734. return 0;
  10735. }
  10736. lua_interface->ResetFunctionStack(state);
  10737. if (spell && spell->targets.size() > 0) {
  10738. ZoneServer* zone = spell->caster->GetZone();
  10739. for (int8 i = 0; i < spell->targets.size(); i++) {
  10740. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10741. if (target && target->IsEntity()) {
  10742. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10743. if (target->IsPlayer())
  10744. ((Player*)target)->SetCharSheetChanged(true);
  10745. }
  10746. }
  10747. }
  10748. else {
  10749. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10750. if (spawn->IsPlayer())
  10751. ((Player*)spawn)->SetCharSheetChanged(true);
  10752. }
  10753. return 0;
  10754. }
  10755. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10756. if (!lua_interface)
  10757. return 0;
  10758. Spawn* spawn = lua_interface->GetSpawn(state);
  10759. lua_interface->ResetFunctionStack(state);
  10760. if (!spawn) {
  10761. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10762. return 0;
  10763. }
  10764. if (!spawn->IsEntity()) {
  10765. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10766. return 0;
  10767. }
  10768. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10769. return 1;
  10770. }
  10771. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10772. if (!lua_interface)
  10773. return 0;
  10774. int32 spell_id = lua_interface->GetInt32Value(state);
  10775. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10776. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10777. if (spell_id > 0) {
  10778. if (spell_tier == 0)
  10779. spell_tier = 1;
  10780. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10781. if(!spell) {
  10782. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10783. lua_interface->ResetFunctionStack(state);
  10784. return 0;
  10785. }
  10786. LuaSpell* lua_spell = 0;
  10787. if(custom_lua_script.size() > 0)
  10788. {
  10789. // attempt to load the custom script since it isn't already loaded
  10790. // we will re-obtain the lua_spell further below
  10791. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10792. {
  10793. 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());
  10794. }
  10795. }
  10796. else
  10797. custom_lua_script = spell->GetSpellData()->lua_script;
  10798. if (!lua_spell && lua_interface)
  10799. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10800. lua_interface->ResetFunctionStack(state);
  10801. if (!lua_spell)
  10802. {
  10803. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10804. return 0;
  10805. }
  10806. lua_spell->spell = new Spell(spell);
  10807. lua_interface->AddCustomSpell(lua_spell);
  10808. lua_interface->SetSpellValue(state, lua_spell);
  10809. return 1;
  10810. }
  10811. return 0;
  10812. }
  10813. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10814. if (!lua_interface)
  10815. return 0;
  10816. LuaSpell* spell = lua_interface->GetSpell(state);
  10817. string field = lua_interface->GetStringValue(state, 2);
  10818. lua_interface->ResetFunctionStack(state);
  10819. if (!spell) {
  10820. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10821. return 0;
  10822. }
  10823. if (!spell->spell || !spell->spell->GetSpellData()) {
  10824. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10825. return 0;
  10826. }
  10827. boost::to_lower(field);
  10828. return spell->spell->GetSpellData(state, field);
  10829. }
  10830. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10831. if (!lua_interface)
  10832. return 0;
  10833. LuaSpell* spell = lua_interface->GetSpell(state);
  10834. string field = lua_interface->GetStringValue(state, 2);
  10835. int8 fieldArg = 3; // field value after the initial set
  10836. if (!spell) {
  10837. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10838. lua_interface->ResetFunctionStack(state);
  10839. return 0;
  10840. }
  10841. if (!spell->spell || !spell->spell->GetSpellData()) {
  10842. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10843. lua_interface->ResetFunctionStack(state);
  10844. return 0;
  10845. }
  10846. boost::to_lower(field);
  10847. bool valSet = false;
  10848. spell->spell->SetSpellData(state, field, fieldArg);
  10849. lua_interface->ResetFunctionStack(state);
  10850. return valSet;
  10851. }
  10852. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10853. if (!lua_interface)
  10854. return 0;
  10855. LuaSpell* spell = lua_interface->GetSpell(state);
  10856. int8 idx = lua_interface->GetInt32Value(state, 2);
  10857. if (!spell) {
  10858. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10859. lua_interface->ResetFunctionStack(state);
  10860. return 0;
  10861. }
  10862. if (!spell->spell || !spell->spell->GetSpellData()) {
  10863. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10864. lua_interface->ResetFunctionStack(state);
  10865. return 0;
  10866. }
  10867. if (spell->spell->lua_data.size() <= idx)
  10868. {
  10869. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10870. lua_interface->ResetFunctionStack(state);
  10871. return 0;
  10872. }
  10873. bool setVal = true;
  10874. LUAData* data = spell->spell->lua_data[idx];
  10875. switch (data->type)
  10876. {
  10877. case 0:
  10878. {
  10879. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10880. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10881. data->int_value = value;
  10882. data->int_value2 = value2;
  10883. break;
  10884. }
  10885. case 1:
  10886. {
  10887. float value = lua_interface->GetFloatValue(state, 3);
  10888. float value2 = lua_interface->GetFloatValue(state, 4);
  10889. data->float_value = value;
  10890. data->float_value2 = value2;
  10891. break;
  10892. }
  10893. case 2:
  10894. {
  10895. bool value = lua_interface->GetBooleanValue(state, 3);
  10896. data->bool_value = value;
  10897. break;
  10898. }
  10899. case 3:
  10900. {
  10901. string value = lua_interface->GetStringValue(state, 3);
  10902. string value2 = lua_interface->GetStringValue(state, 4);
  10903. data->string_value = value;
  10904. data->string_value2 = value2;
  10905. break;
  10906. }
  10907. default:
  10908. setVal = false;
  10909. }
  10910. lua_interface->ResetFunctionStack(state);
  10911. return setVal;
  10912. }
  10913. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10914. if (!lua_interface)
  10915. return 0;
  10916. LuaSpell* spell = lua_interface->GetSpell(state);
  10917. int8 idx = lua_interface->GetInt32Value(state, 2);
  10918. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10919. lua_interface->ResetFunctionStack(state);
  10920. if (!spell) {
  10921. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10922. return 0;
  10923. }
  10924. if (!spell->spell || !spell->spell->GetSpellData()) {
  10925. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10926. return 0;
  10927. }
  10928. if (spell->spell->lua_data.size() <= idx)
  10929. {
  10930. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10931. return 0;
  10932. }
  10933. bool setVal = true;
  10934. LUAData* data = spell->spell->lua_data[idx];
  10935. switch (data->type)
  10936. {
  10937. case 0:
  10938. {
  10939. if(!secondfield)
  10940. lua_interface->SetSInt32Value(state, data->int_value);
  10941. else
  10942. lua_interface->SetSInt32Value(state, data->int_value2);
  10943. break;
  10944. }
  10945. case 1:
  10946. {
  10947. if (!secondfield)
  10948. lua_interface->SetFloatValue(state, data->float_value);
  10949. else
  10950. lua_interface->SetFloatValue(state, data->float_value2);
  10951. break;
  10952. }
  10953. case 2:
  10954. {
  10955. lua_interface->SetBooleanValue(state, data->bool_value);
  10956. break;
  10957. }
  10958. case 3:
  10959. {
  10960. if (!secondfield)
  10961. lua_interface->SetStringValue(state, data->string_value.c_str());
  10962. else
  10963. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10964. break;
  10965. }
  10966. default:
  10967. setVal = false;
  10968. }
  10969. return setVal;
  10970. }
  10971. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10972. if (!lua_interface)
  10973. return 0;
  10974. LuaSpell* spell = lua_interface->GetSpell(state);
  10975. int8 idx = lua_interface->GetInt32Value(state, 2);
  10976. string field = lua_interface->GetStringValue(state, 3);
  10977. boost::to_lower(field);
  10978. if (!spell) {
  10979. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10980. lua_interface->ResetFunctionStack(state);
  10981. return 0;
  10982. }
  10983. if (!spell->spell || !spell->spell->GetSpellData()) {
  10984. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10985. lua_interface->ResetFunctionStack(state);
  10986. return 0;
  10987. }
  10988. if (spell->spell->effects.size() <= idx)
  10989. {
  10990. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10991. lua_interface->ResetFunctionStack(state);
  10992. return 0;
  10993. }
  10994. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10995. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10996. if (field == "description")
  10997. effect->description = string(lua_interface->GetStringValue(state, 4));
  10998. else if (field == "bullet")
  10999. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  11000. else if (field == "percentage")
  11001. effect->percentage = lua_interface->GetInt8Value(state, 4);
  11002. else { // no match
  11003. lua_interface->ResetFunctionStack(state);
  11004. return 0;
  11005. }
  11006. lua_interface->ResetFunctionStack(state);
  11007. return 1;
  11008. }
  11009. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  11010. if (!lua_interface)
  11011. return 0;
  11012. LuaSpell* spell = lua_interface->GetSpell(state);
  11013. int8 idx = lua_interface->GetInt32Value(state, 2);
  11014. string field = lua_interface->GetStringValue(state, 3);
  11015. lua_interface->ResetFunctionStack(state);
  11016. boost::to_lower(field);
  11017. if (!spell) {
  11018. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  11019. return 0;
  11020. }
  11021. if (!spell->spell || !spell->spell->GetSpellData()) {
  11022. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  11023. return 0;
  11024. }
  11025. if (spell->spell->effects.size() <= idx)
  11026. {
  11027. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  11028. return 0;
  11029. }
  11030. // do we need to lock? eh probably not this should only be used before use of the custom spell
  11031. SpellDisplayEffect* effect = spell->spell->effects[idx];
  11032. if (field == "description")
  11033. lua_interface->SetStringValue(state, effect->description.c_str());
  11034. else if (field == "bullet")
  11035. lua_interface->SetInt32Value(state, effect->subbullet);
  11036. else if (field == "percentage")
  11037. lua_interface->SetInt32Value(state, effect->percentage);
  11038. else // no match
  11039. return 0;
  11040. return 1;
  11041. }
  11042. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  11043. if (!lua_interface)
  11044. return 0;
  11045. LuaSpell* spell = lua_interface->GetSpell(state);
  11046. Spawn* caster = lua_interface->GetSpawn(state, 2);
  11047. Spawn* target = lua_interface->GetSpawn(state, 3);
  11048. lua_interface->ResetFunctionStack(state);
  11049. if (!target) {
  11050. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11051. return 0;
  11052. }
  11053. if (!target->IsEntity()) {
  11054. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  11055. return 0;
  11056. }
  11057. if (!spell) {
  11058. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  11059. return 0;
  11060. }
  11061. if (caster && !caster->IsEntity()) {
  11062. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  11063. return 0;
  11064. }
  11065. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  11066. return 0;
  11067. }
  11068. int EQ2Emu_lua_InWater(lua_State* state) {
  11069. if (!lua_interface)
  11070. return 0;
  11071. Spawn* spawn = lua_interface->GetSpawn(state);
  11072. lua_interface->ResetFunctionStack(state);
  11073. if (spawn) {
  11074. lua_interface->SetBooleanValue(state, spawn->InWater());
  11075. return 1;
  11076. }
  11077. return 0;
  11078. }
  11079. int EQ2Emu_lua_InLava(lua_State* state) {
  11080. if (!lua_interface)
  11081. return 0;
  11082. Spawn* spawn = lua_interface->GetSpawn(state);
  11083. lua_interface->ResetFunctionStack(state);
  11084. if (spawn) {
  11085. lua_interface->SetBooleanValue(state, spawn->InLava());
  11086. return 1;
  11087. }
  11088. return 0;
  11089. }
  11090. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11091. if (!lua_interface)
  11092. return 0;
  11093. Spawn* attacker = lua_interface->GetSpawn(state);
  11094. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11095. int8 type = lua_interface->GetInt8Value(state, 3);
  11096. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11097. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11098. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11099. string spell_name = lua_interface->GetStringValue(state, 7);
  11100. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11101. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11102. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11103. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11104. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11105. lua_interface->ResetFunctionStack(state);
  11106. if (!attacker) {
  11107. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11108. lua_interface->SetBooleanValue(state, false);
  11109. return 1;
  11110. }
  11111. if (!attacker->IsEntity()) {
  11112. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11113. lua_interface->SetBooleanValue(state, false);
  11114. return 1;
  11115. }
  11116. if (!victim) {
  11117. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11118. lua_interface->SetBooleanValue(state, false);
  11119. return 1;
  11120. }
  11121. if (!victim->IsEntity()) {
  11122. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11123. lua_interface->SetBooleanValue(state, false);
  11124. return 1;
  11125. }
  11126. bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
  11127. lua_interface->SetBooleanValue(state, has_damaged);
  11128. return 1;
  11129. }
  11130. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11131. if (!lua_interface)
  11132. return 0;
  11133. Spawn* spawn = lua_interface->GetSpawn(state);
  11134. lua_interface->ResetFunctionStack(state);
  11135. if (spawn) {
  11136. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11137. return 1;
  11138. }
  11139. return 0;
  11140. }
  11141. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11142. if (!lua_interface)
  11143. return 0;
  11144. Spawn* spawn = lua_interface->GetSpawn(state);
  11145. bool invul = lua_interface->GetBooleanValue(state, 2);
  11146. lua_interface->ResetFunctionStack(state);
  11147. if (spawn) {
  11148. spawn->SetInvulnerable(invul);
  11149. }
  11150. return 0;
  11151. }
  11152. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11153. if (!lua_interface)
  11154. return 0;
  11155. string category = lua_interface->GetStringValue(state);
  11156. string name = lua_interface->GetStringValue(state, 2);
  11157. lua_interface->ResetFunctionStack(state);
  11158. Rule *ret = 0;
  11159. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11160. lua_interface->SetBooleanValue(state, ret->GetBool());
  11161. return 1;
  11162. }
  11163. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11164. return 0;
  11165. }
  11166. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11167. if (!lua_interface)
  11168. return 0;
  11169. string category = lua_interface->GetStringValue(state);
  11170. string name = lua_interface->GetStringValue(state, 2);
  11171. lua_interface->ResetFunctionStack(state);
  11172. Rule *ret = 0;
  11173. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11174. lua_interface->SetInt32Value(state, ret->GetInt32());
  11175. return 1;
  11176. }
  11177. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11178. return 0;
  11179. }
  11180. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11181. if (!lua_interface)
  11182. return 0;
  11183. string category = lua_interface->GetStringValue(state);
  11184. string name = lua_interface->GetStringValue(state, 2);
  11185. lua_interface->ResetFunctionStack(state);
  11186. Rule *ret = 0;
  11187. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11188. lua_interface->SetFloatValue(state, ret->GetFloat());
  11189. return 1;
  11190. }
  11191. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11192. return 0;
  11193. }
  11194. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11195. if (!lua_interface)
  11196. return 0;
  11197. Spawn* spawn = lua_interface->GetSpawn(state);
  11198. string type = lua_interface->GetStringValue(state, 2);
  11199. lua_interface->ResetFunctionStack(state);
  11200. if (spawn) {
  11201. int res = 1;
  11202. boost::to_lower(type);
  11203. if(type == "assigned_aa")
  11204. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11205. else if ( type == "unassigned_aa")
  11206. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11207. else if ( type == "assigned_tradeskill_aa")
  11208. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11209. else if ( type == "unassigned_tradeskill_aa")
  11210. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11211. else if ( type == "assigned_prestige_aa")
  11212. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11213. else if ( type == "unassigned_prestige_aa")
  11214. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11215. else if ( type == "assigned_tradeskill_prestige_aa")
  11216. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11217. else if ( type == "unassigned_tradeskill_prestige_aa")
  11218. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11219. else
  11220. res = 0;
  11221. return res;
  11222. }
  11223. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11224. return 0;
  11225. }
  11226. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11227. if (!lua_interface)
  11228. return 0;
  11229. Spawn* spawn = lua_interface->GetSpawn(state);
  11230. string type = lua_interface->GetStringValue(state, 2);
  11231. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11232. lua_interface->ResetFunctionStack(state);
  11233. if (spawn) {
  11234. boost::to_lower(type);
  11235. if(type == "assigned_aa")
  11236. spawn->SetAssignedAA((sint16)value);
  11237. else if ( type == "unassigned_aa")
  11238. spawn->SetUnassignedAA((sint16)value);
  11239. else if ( type == "assigned_tradeskill_aa")
  11240. spawn->SetTradeskillAA((sint16)value);
  11241. else if ( type == "unassigned_tradeskill_aa")
  11242. spawn->SetUnassignedTradeskillAA((sint16)value);
  11243. else if ( type == "assigned_prestige_aa")
  11244. spawn->SetPrestigeAA((sint16)value);
  11245. else if ( type == "unassigned_prestige_aa")
  11246. spawn->SetUnassignedPrestigeAA((sint16)value);
  11247. else if ( type == "assigned_tradeskill_prestige_aa")
  11248. spawn->SetTradeskillPrestigeAA((sint16)value);
  11249. else if ( type == "unassigned_tradeskill_prestige_aa")
  11250. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11251. if(spawn->IsPlayer())
  11252. ((Player*)spawn)->SetCharSheetChanged(true);
  11253. }
  11254. return 0;
  11255. }
  11256. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11257. if (!lua_interface)
  11258. return 0;
  11259. string titleName = lua_interface->GetStringValue(state);
  11260. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11261. lua_interface->ResetFunctionStack(state);
  11262. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11263. lua_interface->SetSInt32Value(state, index);
  11264. return 1;
  11265. }
  11266. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11267. if (!lua_interface)
  11268. return 0;
  11269. Spawn* spawn = lua_interface->GetSpawn(state);
  11270. string titleName = lua_interface->GetStringValue(state, 2);
  11271. lua_interface->ResetFunctionStack(state);
  11272. if(!spawn->IsPlayer())
  11273. {
  11274. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11275. lua_interface->SetSInt32Value(state, -1);
  11276. return 1;
  11277. }
  11278. Player* player = (Player*)spawn;
  11279. // check if player already has the title, don't need to add twice
  11280. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11281. if ( playerHasTitle)
  11282. {
  11283. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11284. return 1;
  11285. }
  11286. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11287. if(!title)
  11288. {
  11289. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11290. lua_interface->SetSInt32Value(state, -1);
  11291. return 1;
  11292. }
  11293. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11294. if(returnIdx < 0)
  11295. {
  11296. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11297. }
  11298. lua_interface->SetSInt32Value(state, returnIdx);
  11299. player->GetClient()->SendTitleUpdate();
  11300. return 1;
  11301. }
  11302. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11303. if (!lua_interface)
  11304. return 0;
  11305. Spawn* spawn = lua_interface->GetSpawn(state);
  11306. string titleName = lua_interface->GetStringValue(state, 2);
  11307. lua_interface->ResetFunctionStack(state);
  11308. if(!spawn->IsPlayer())
  11309. {
  11310. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11311. return 0;
  11312. }
  11313. Player* player = (Player*)spawn;
  11314. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11315. if(!title)
  11316. {
  11317. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11318. return 0;
  11319. }
  11320. if(title->GetPrefix())
  11321. {
  11322. 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());
  11323. return 0;
  11324. }
  11325. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11326. player->GetClient()->SendTitleUpdate();
  11327. return 1;
  11328. }
  11329. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11330. if (!lua_interface)
  11331. return 0;
  11332. Spawn* spawn = lua_interface->GetSpawn(state);
  11333. string titleName = lua_interface->GetStringValue(state, 2);
  11334. lua_interface->ResetFunctionStack(state);
  11335. if(!spawn->IsPlayer())
  11336. {
  11337. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11338. return 0;
  11339. }
  11340. Player* player = (Player*)spawn;
  11341. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11342. if(!title)
  11343. {
  11344. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11345. return 0;
  11346. }
  11347. if(!title->GetPrefix())
  11348. {
  11349. 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());
  11350. return 0;
  11351. }
  11352. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11353. player->GetClient()->SendTitleUpdate();
  11354. return 1;
  11355. }
  11356. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11357. if (!lua_interface)
  11358. return 0;
  11359. Spawn* spawn = lua_interface->GetSpawn(state);
  11360. lua_interface->ResetFunctionStack(state);
  11361. if(!spawn)
  11362. {
  11363. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: spawn is null", lua_interface->GetScriptName(state));
  11364. return 0;
  11365. }
  11366. if(!spawn->IsPlayer())
  11367. {
  11368. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11369. return 0;
  11370. }
  11371. Player* player = (Player*)spawn;
  11372. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11373. player->GetClient()->SendTitleUpdate();
  11374. return 1;
  11375. }
  11376. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11377. if (!lua_interface)
  11378. return 0;
  11379. Spawn* spawn = lua_interface->GetSpawn(state);
  11380. lua_interface->ResetFunctionStack(state);
  11381. if(!spawn)
  11382. {
  11383. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: spawn is null", lua_interface->GetScriptName(state));
  11384. return 0;
  11385. }
  11386. if(!spawn->IsPlayer())
  11387. {
  11388. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11389. return 0;
  11390. }
  11391. Player* player = (Player*)spawn;
  11392. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11393. player->GetClient()->SendTitleUpdate();
  11394. return 1;
  11395. }
  11396. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11397. if (!lua_interface)
  11398. return 0;
  11399. Spawn* spawn = lua_interface->GetSpawn(state);
  11400. string field = lua_interface->GetStringValue(state, 2);
  11401. lua_interface->ResetFunctionStack(state);
  11402. if(!spawn || !spawn->IsEntity())
  11403. {
  11404. 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));
  11405. return 0;
  11406. }
  11407. Entity* ent = (Entity*)spawn;
  11408. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11409. return 1;
  11410. }
  11411. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11412. if (!lua_interface)
  11413. return 0;
  11414. Spawn* spawn = lua_interface->GetSpawn(state);
  11415. string field = lua_interface->GetStringValue(state, 2);
  11416. lua_interface->ResetFunctionStack(state);
  11417. if(!spawn || !spawn->IsEntity())
  11418. {
  11419. 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));
  11420. return 0;
  11421. }
  11422. Entity* ent = (Entity*)spawn;
  11423. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11424. return 1;
  11425. }
  11426. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11427. if (!lua_interface)
  11428. return 0;
  11429. Spawn* spawn = lua_interface->GetSpawn(state);
  11430. string field = lua_interface->GetStringValue(state, 2);
  11431. lua_interface->ResetFunctionStack(state);
  11432. if(!spawn || !spawn->IsEntity())
  11433. {
  11434. 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));
  11435. return 0;
  11436. }
  11437. Entity* ent = (Entity*)spawn;
  11438. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11439. return 1;
  11440. }
  11441. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11442. if (!lua_interface)
  11443. return 0;
  11444. Spawn* spawn = lua_interface->GetSpawn(state);
  11445. string field = lua_interface->GetStringValue(state, 2);
  11446. lua_interface->ResetFunctionStack(state);
  11447. if(!spawn || !spawn->IsEntity())
  11448. {
  11449. 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));
  11450. return 0;
  11451. }
  11452. Entity* ent = (Entity*)spawn;
  11453. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11454. return 1;
  11455. }
  11456. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11457. if (!lua_interface)
  11458. return 0;
  11459. Spawn* spawn = lua_interface->GetSpawn(state);
  11460. string field = lua_interface->GetStringValue(state, 2);
  11461. string value = lua_interface->GetStringValue(state, 3);
  11462. lua_interface->ResetFunctionStack(state);
  11463. if(!spawn || !spawn->IsEntity())
  11464. {
  11465. 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));
  11466. return 0;
  11467. }
  11468. Entity* ent = (Entity*)spawn;
  11469. bool set_ = ent->SetInfoStructString(field, value);
  11470. lua_interface->SetBooleanValue(state, set_);
  11471. return 1;
  11472. }
  11473. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11474. if (!lua_interface)
  11475. return 0;
  11476. Spawn* spawn = lua_interface->GetSpawn(state);
  11477. string field = lua_interface->GetStringValue(state, 2);
  11478. int64 value = lua_interface->GetInt64Value(state, 3);
  11479. lua_interface->ResetFunctionStack(state);
  11480. if(!spawn || !spawn->IsEntity())
  11481. {
  11482. 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));
  11483. return 0;
  11484. }
  11485. Entity* ent = (Entity*)spawn;
  11486. bool set_ = ent->SetInfoStructUInt(field, value);
  11487. lua_interface->SetBooleanValue(state, set_);
  11488. return 1;
  11489. }
  11490. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11491. if (!lua_interface)
  11492. return 0;
  11493. Spawn* spawn = lua_interface->GetSpawn(state);
  11494. string field = lua_interface->GetStringValue(state, 2);
  11495. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11496. lua_interface->ResetFunctionStack(state);
  11497. if(!spawn || !spawn->IsEntity())
  11498. {
  11499. 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));
  11500. return 0;
  11501. }
  11502. Entity* ent = (Entity*)spawn;
  11503. bool set_ = ent->SetInfoStructSInt(field, value);
  11504. lua_interface->SetBooleanValue(state, set_);
  11505. return 1;
  11506. }
  11507. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11508. if (!lua_interface)
  11509. return 0;
  11510. Spawn* spawn = lua_interface->GetSpawn(state);
  11511. string field = lua_interface->GetStringValue(state, 2);
  11512. float value = lua_interface->GetFloatValue(state, 3);
  11513. lua_interface->ResetFunctionStack(state);
  11514. if(!spawn || !spawn->IsEntity())
  11515. {
  11516. 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));
  11517. return 0;
  11518. }
  11519. Entity* ent = (Entity*)spawn;
  11520. bool set_ = ent->SetInfoStructFloat(field, value);
  11521. lua_interface->SetBooleanValue(state, set_);
  11522. return 1;
  11523. }
  11524. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11525. if (!lua_interface)
  11526. return 0;
  11527. Spawn* spawn = lua_interface->GetSpawn(state);
  11528. bool value = lua_interface->GetBooleanValue(state, 2);
  11529. lua_interface->ResetFunctionStack(state);
  11530. if(!spawn || !spawn->IsPlayer())
  11531. {
  11532. 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));
  11533. return 0;
  11534. }
  11535. ((Player*)spawn)->SetCharSheetChanged(value);
  11536. return 0;
  11537. }
  11538. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11539. if (!lua_interface)
  11540. return 0;
  11541. Spawn* spawn = lua_interface->GetSpawn(state);
  11542. std::string fromName = lua_interface->GetStringValue(state, 2);
  11543. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11544. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11545. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11546. int32 copper = lua_interface->GetInt32Value(state, 6);
  11547. int32 silver = lua_interface->GetInt32Value(state, 7);
  11548. int32 gold = lua_interface->GetInt32Value(state, 8);
  11549. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11550. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11551. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11552. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11553. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11554. lua_interface->ResetFunctionStack(state);
  11555. if(!spawn || !spawn->IsPlayer())
  11556. {
  11557. 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));
  11558. lua_interface->SetBooleanValue(state, false);
  11559. return 1;
  11560. }
  11561. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11562. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11563. lua_interface->SetBooleanValue(state, true);
  11564. return 1;
  11565. }
  11566. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11567. if (!lua_interface)
  11568. return 0;
  11569. int32 char_id = lua_interface->GetInt32Value(state);
  11570. std::string fromName = lua_interface->GetStringValue(state, 2);
  11571. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11572. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11573. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11574. int32 copper = lua_interface->GetInt32Value(state, 6);
  11575. int32 silver = lua_interface->GetInt32Value(state, 7);
  11576. int32 gold = lua_interface->GetInt32Value(state, 8);
  11577. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11578. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11579. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11580. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11581. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11582. lua_interface->ResetFunctionStack(state);
  11583. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11584. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11585. lua_interface->SetBooleanValue(state, true);
  11586. return 1;
  11587. }
  11588. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11589. Spawn* widget;
  11590. if (lua_interface) {
  11591. widget = lua_interface->GetSpawn(state);
  11592. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11593. lua_interface->ResetFunctionStack(state);
  11594. if (widget && widget->IsWidget())
  11595. {
  11596. ((Widget*)widget)->OpenDoor();
  11597. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11598. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11599. }
  11600. else
  11601. 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));
  11602. }
  11603. return 0;
  11604. }
  11605. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11606. Spawn* widget;
  11607. if (lua_interface) {
  11608. widget = lua_interface->GetSpawn(state);
  11609. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11610. lua_interface->ResetFunctionStack(state);
  11611. if (widget && widget->IsWidget())
  11612. {
  11613. ((Widget*)widget)->CloseDoor();
  11614. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11615. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11616. }
  11617. else
  11618. 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));
  11619. }
  11620. return 0;
  11621. }
  11622. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11623. if (!lua_interface)
  11624. return 0;
  11625. Spawn* widget = lua_interface->GetSpawn(state);
  11626. lua_interface->ResetFunctionStack(state);
  11627. if (widget && widget->IsWidget())
  11628. {
  11629. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11630. return 1;
  11631. }
  11632. return 0;
  11633. }
  11634. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11635. if (!lua_interface)
  11636. return 0;
  11637. sint32 min = lua_interface->GetSInt32Value(state);
  11638. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11639. lua_interface->ResetFunctionStack(state);
  11640. sint32 result = MakeRandomInt(min, max);
  11641. lua_interface->SetSInt32Value(state, result);
  11642. return 1;
  11643. }
  11644. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11645. if (!lua_interface)
  11646. return 0;
  11647. float min = lua_interface->GetFloatValue(state);
  11648. float max = lua_interface->GetFloatValue(state, 2);
  11649. lua_interface->ResetFunctionStack(state);
  11650. float result = MakeRandomFloat(min, max);
  11651. lua_interface->SetFloatValue(state, result);
  11652. return 1;
  11653. }
  11654. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11655. if (!lua_interface)
  11656. return 0;
  11657. Spawn* spawn = lua_interface->GetSpawn(state);
  11658. int32 value = lua_interface->GetInt32Value(state, 2);
  11659. lua_interface->ResetFunctionStack(state);
  11660. if(!spawn)
  11661. {
  11662. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11663. lua_interface->SetBooleanValue(state, false);
  11664. return 1;
  11665. }
  11666. spawn->AddIconValue(value);
  11667. lua_interface->SetBooleanValue(state, true);
  11668. return 1;
  11669. }
  11670. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11671. if (!lua_interface)
  11672. return 0;
  11673. Spawn* spawn = lua_interface->GetSpawn(state);
  11674. int32 value = lua_interface->GetInt32Value(state, 2);
  11675. lua_interface->ResetFunctionStack(state);
  11676. if(!spawn)
  11677. {
  11678. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11679. lua_interface->SetBooleanValue(state, false);
  11680. return 1;
  11681. }
  11682. spawn->RemoveIconValue(value);
  11683. lua_interface->SetBooleanValue(state, true);
  11684. return 1;
  11685. }
  11686. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11687. Spawn* npc = lua_interface->GetSpawn(state);
  11688. lua_interface->ResetFunctionStack(state);
  11689. if (npc && npc->IsNPC()) {
  11690. NPC* shard = (NPC*)npc;
  11691. int32 shardid = shard->GetShardID();
  11692. lua_interface->SetInt32Value(state, shardid);
  11693. return 1;
  11694. }
  11695. lua_interface->SetInt32Value(state, 0);
  11696. return 1;
  11697. }
  11698. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11699. Spawn* npc = lua_interface->GetSpawn(state);
  11700. lua_interface->ResetFunctionStack(state);
  11701. if (npc && npc->IsNPC()) {
  11702. NPC* shard = (NPC*)npc;
  11703. int32 charid = shard->GetShardCharID();
  11704. lua_interface->SetInt32Value(state, charid);
  11705. return 1;
  11706. }
  11707. lua_interface->SetInt32Value(state, 0);
  11708. return 1;
  11709. }
  11710. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11711. Spawn* npc = lua_interface->GetSpawn(state);
  11712. lua_interface->ResetFunctionStack(state);
  11713. if (npc && npc->IsNPC()) {
  11714. NPC* shard = (NPC*)npc;
  11715. int64 timestamp = shard->GetShardCreatedTimestamp();
  11716. lua_interface->SetSInt64Value(state, timestamp);
  11717. return 1;
  11718. }
  11719. lua_interface->SetSInt64Value(state, 0);
  11720. return 1;
  11721. }
  11722. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11723. if (!lua_interface)
  11724. return 0;
  11725. int32 shardid = lua_interface->GetInt32Value(state);
  11726. lua_interface->ResetFunctionStack(state);
  11727. if(shardid < 1)
  11728. lua_interface->SetBooleanValue(state, false);
  11729. else
  11730. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11731. return 1;
  11732. }
  11733. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11734. if (!lua_interface)
  11735. return 0;
  11736. Spawn* spawn = lua_interface->GetSpawn(state);
  11737. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11738. if (spawn) {
  11739. spawn->PauseMovement(delay_in_ms);
  11740. }
  11741. lua_interface->ResetFunctionStack(state);
  11742. return 0;
  11743. }
  11744. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11745. if (!lua_interface)
  11746. return 0;
  11747. Spawn* spawn = lua_interface->GetSpawn(state);
  11748. if (spawn) {
  11749. spawn->ResetMovement();
  11750. }
  11751. lua_interface->ResetFunctionStack(state);
  11752. return 0;
  11753. }
  11754. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11755. Player* player = (Player*)lua_interface->GetSpawn(state);
  11756. int8 level = lua_interface->GetInt8Value(state, 2);
  11757. lua_interface->ResetFunctionStack(state);
  11758. if (player && player->IsPlayer() && level > 0) {
  11759. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11760. return 1;
  11761. }
  11762. return 0;
  11763. }
  11764. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11765. Player* player = (Player*)lua_interface->GetSpawn(state);
  11766. int8 level = lua_interface->GetInt8Value(state, 2);
  11767. lua_interface->ResetFunctionStack(state);
  11768. if (player && player->IsPlayer() && level > 0) {
  11769. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11770. return 1;
  11771. }
  11772. return 0;
  11773. }
  11774. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11775. ZoneServer* zone = lua_interface->GetZone(state);
  11776. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11777. lua_interface->ResetFunctionStack(state);
  11778. if (zone) {
  11779. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11780. if (spawn) {
  11781. lua_interface->SetSpawnValue(state, spawn);
  11782. return 1;
  11783. }
  11784. }
  11785. return 0;
  11786. }
  11787. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11788. if (!lua_interface)
  11789. return 0;
  11790. Spawn* spawn = lua_interface->GetSpawn(state);
  11791. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11792. lua_interface->ResetFunctionStack(state);
  11793. bool res = false;
  11794. if(spawn && spawn->IsTransportSpawn())
  11795. {
  11796. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11797. spawn->SetRailID(rail_id);
  11798. res = true;
  11799. }
  11800. else if (!spawn) {
  11801. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11802. }
  11803. else if(!spawn->IsTransportSpawn()) {
  11804. 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());
  11805. }
  11806. lua_interface->SetBooleanValue(state, res);
  11807. return 1;
  11808. }
  11809. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11810. if (!lua_interface)
  11811. return 0;
  11812. ZoneServer* zone = lua_interface->GetZone(state);
  11813. lua_interface->ResetFunctionStack(state);
  11814. if (zone) {
  11815. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11816. return 1;
  11817. }
  11818. return 0;
  11819. }
  11820. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11821. if (!lua_interface)
  11822. return 0;
  11823. Spawn* spawn = lua_interface->GetSpawn(state);
  11824. lua_interface->ResetFunctionStack(state);
  11825. if (spawn) {
  11826. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11827. return 1;
  11828. }
  11829. return 0;
  11830. }
  11831. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11832. if (!lua_interface)
  11833. return 0;
  11834. Spawn* player = lua_interface->GetSpawn(state);
  11835. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11836. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11837. lua_interface->ResetFunctionStack(state);
  11838. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11839. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11840. }
  11841. else if(!zoneID) {
  11842. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11843. }
  11844. else
  11845. {
  11846. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11847. return 1;
  11848. }
  11849. return 0;
  11850. }
  11851. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11852. if (!lua_interface)
  11853. return 0;
  11854. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11855. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11856. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11857. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11858. lua_interface->ResetFunctionStack(state);
  11859. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11860. world.GetWorldTimeStruct()->year = newYear;
  11861. world.GetWorldTimeStruct()->month = newMonth;
  11862. world.GetWorldTimeStruct()->hour = newHour;
  11863. world.GetWorldTimeStruct()->minute = newMinute;
  11864. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11865. return 0;
  11866. }
  11867. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11868. if (!lua_interface)
  11869. return 0;
  11870. lua_interface->ResetFunctionStack(state);
  11871. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11872. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11873. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11874. return 1;
  11875. }
  11876. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11877. if (!lua_interface)
  11878. return 0;
  11879. lua_interface->ResetFunctionStack(state);
  11880. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11881. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11882. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11883. return 1;
  11884. }
  11885. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11886. if (!lua_interface)
  11887. return 0;
  11888. lua_interface->ResetFunctionStack(state);
  11889. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11890. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11891. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11892. return 1;
  11893. }
  11894. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11895. if (!lua_interface)
  11896. return 0;
  11897. lua_interface->ResetFunctionStack(state);
  11898. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11899. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11900. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11901. return 1;
  11902. }
  11903. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11904. if (!lua_interface)
  11905. return 0;
  11906. lua_interface->ResetFunctionStack(state);
  11907. world.SendTimeUpdate();
  11908. return 0;
  11909. }
  11910. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11911. bool update_result = false;
  11912. Faction* faction = 0;
  11913. Spawn* spawn = lua_interface->GetSpawn(state);
  11914. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11915. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11916. lua_interface->ResetFunctionStack(state);
  11917. if(!spawn || !spawn->IsPlayer()) {
  11918. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11919. return 0;
  11920. }
  11921. Player* player = (Player*)spawn;
  11922. Client* client = player->GetClient();
  11923. if (faction_id > 0) {
  11924. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11925. if(hasfaction == 0) {
  11926. //they do not have the faction. Lets get the default value and feed it in.
  11927. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11928. //add the default faction for the player.
  11929. player->SetFactionValue(faction_id, defaultfaction);
  11930. }
  11931. if(increase >= 0) {
  11932. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11933. faction = master_faction_list.GetFaction(faction_id);
  11934. if(faction && update_result)
  11935. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11936. else if(faction)
  11937. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11938. lua_interface->SetBooleanValue(state, true);
  11939. return 1;
  11940. }
  11941. if(increase < 0){
  11942. //change the negative to a positive, since thats how decreasefaction() likes it.
  11943. increase *= -1;
  11944. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11945. faction = master_faction_list.GetFaction(faction_id);
  11946. if(faction && update_result)
  11947. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11948. else if(faction)
  11949. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11950. lua_interface->SetBooleanValue(state, true);
  11951. return 1;
  11952. }
  11953. }
  11954. lua_interface->SetBooleanValue(state, false);
  11955. return 1;
  11956. }
  11957. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11958. bool hascoin = 0;
  11959. Spawn* player = lua_interface->GetSpawn(state);
  11960. int32 coins = lua_interface->GetInt32Value(state, 2);
  11961. lua_interface->ResetFunctionStack(state);
  11962. if (player && player->IsPlayer()) {
  11963. hascoin = ((Player*)player)->HasCoins(coins);
  11964. if(hascoin == 0) {
  11965. lua_interface->SetBooleanValue(state, false);
  11966. return 1;
  11967. }
  11968. if(hascoin == 1) {
  11969. lua_interface->SetBooleanValue(state, true);
  11970. return 1;
  11971. }
  11972. }
  11973. return 0;
  11974. }
  11975. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11976. int32 loot_tier = 0;
  11977. Spawn* spawn = lua_interface->GetSpawn(state);
  11978. lua_interface->ResetFunctionStack(state);
  11979. if (spawn) {
  11980. loot_tier = spawn->GetLootTier();
  11981. lua_interface->SetInt32Value(state, loot_tier);
  11982. return 1;
  11983. }
  11984. return 0;
  11985. }
  11986. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11987. if (!lua_interface)
  11988. return 0;
  11989. Spawn* spawn = lua_interface->GetSpawn(state);
  11990. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11991. lua_interface->ResetFunctionStack(state);
  11992. if (spawn) {
  11993. spawn->SetLootTier(loot_tier);
  11994. lua_interface->SetBooleanValue(state, true);
  11995. return 1;
  11996. }
  11997. lua_interface->SetBooleanValue(state, false);
  11998. return 1;
  11999. }
  12000. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  12001. int32 loot_drop_type = 0;
  12002. Spawn* spawn = lua_interface->GetSpawn(state);
  12003. lua_interface->ResetFunctionStack(state);
  12004. if (spawn) {
  12005. loot_drop_type = spawn->GetLootDropType();
  12006. lua_interface->SetInt32Value(state, loot_drop_type);
  12007. return 1;
  12008. }
  12009. return 0;
  12010. }
  12011. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  12012. if (!lua_interface)
  12013. return 0;
  12014. Spawn* spawn = lua_interface->GetSpawn(state);
  12015. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  12016. lua_interface->ResetFunctionStack(state);
  12017. if (spawn) {
  12018. spawn->SetLootDropType(loot_drop_type);
  12019. lua_interface->SetBooleanValue(state, true);
  12020. return 1;
  12021. }
  12022. lua_interface->SetBooleanValue(state, false);
  12023. return 1;
  12024. }
  12025. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  12026. if (!lua_interface)
  12027. return 0;
  12028. Spawn* spawn = lua_interface->GetSpawn(state);
  12029. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  12030. if(damage_amount > 100) {
  12031. damage_amount = 100;
  12032. }
  12033. if (!spawn) {
  12034. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  12035. lua_interface->ResetFunctionStack(state);
  12036. return 0;
  12037. }
  12038. lua_interface->ResetFunctionStack(state);
  12039. if (spawn->IsPlayer()) {
  12040. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  12041. lua_interface->SetBooleanValue(state, true);
  12042. else
  12043. lua_interface->SetBooleanValue(state, false);
  12044. }
  12045. else {
  12046. lua_interface->SetBooleanValue(state, false);
  12047. }
  12048. return 1;
  12049. }
  12050. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  12051. ZoneServer* zone = lua_interface->GetZone(state);
  12052. int32 version = lua_interface->GetInt32Value(state, 2);
  12053. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12054. if(region_map == nullptr) {
  12055. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12056. lua_interface->ResetFunctionStack(state);
  12057. return 0;
  12058. }
  12059. string region_name = lua_interface->GetStringValue(state, 3);
  12060. string env_name = lua_interface->GetStringValue(state, 4);
  12061. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  12062. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  12063. float dist = lua_interface->GetFloatValue(state, 7);
  12064. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  12065. lua_interface->ResetFunctionStack(state);
  12066. lua_interface->SetBooleanValue(state, true);
  12067. return 1;
  12068. }
  12069. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  12070. ZoneServer* zone = lua_interface->GetZone(state);
  12071. int32 version = lua_interface->GetInt32Value(state, 2);
  12072. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12073. if(region_map == nullptr) {
  12074. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12075. lua_interface->ResetFunctionStack(state);
  12076. return 0;
  12077. }
  12078. string region_name = lua_interface->GetStringValue(state, 3);
  12079. region_map->RemoveRegionNode(region_name);
  12080. lua_interface->ResetFunctionStack(state);
  12081. lua_interface->SetBooleanValue(state, true);
  12082. return 1;
  12083. }
  12084. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12085. Client* client = nullptr;
  12086. Spawn* player = lua_interface->GetSpawn(state);
  12087. if (!player) {
  12088. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12089. lua_interface->SetBooleanValue(state, false);
  12090. lua_interface->ResetFunctionStack(state);
  12091. return 1;
  12092. }
  12093. if (!player->IsPlayer()) {
  12094. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12095. lua_interface->SetBooleanValue(state, false);
  12096. lua_interface->ResetFunctionStack(state);
  12097. return 1;
  12098. }
  12099. client = player->GetClient();
  12100. if (!client) {
  12101. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12102. lua_interface->SetBooleanValue(state, false);
  12103. lua_interface->ResetFunctionStack(state);
  12104. return 1;
  12105. }
  12106. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12107. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12108. lua_interface->ResetFunctionStack(state);
  12109. lua_interface->SetBooleanValue(state, success_sight);
  12110. return 1;
  12111. }
  12112. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12113. if (!lua_interface)
  12114. return 0;
  12115. bool result = false;
  12116. Spawn* spawn = lua_interface->GetSpawn(state);
  12117. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12118. lua_interface->ResetFunctionStack(state);
  12119. if (!spawn)
  12120. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12121. else if (!spawn->IsNPC())
  12122. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12123. else
  12124. {
  12125. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12126. result = true;
  12127. }
  12128. lua_interface->SetBooleanValue(state, result);
  12129. return 1;
  12130. }
  12131. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12132. if (!lua_interface)
  12133. return 0;
  12134. bool result = false;
  12135. Spawn* spawn = lua_interface->GetSpawn(state);
  12136. lua_interface->ResetFunctionStack(state);
  12137. if (!spawn)
  12138. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12139. else if (!spawn->IsNPC())
  12140. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12141. else
  12142. {
  12143. if(((NPC*)spawn)->cast_on_aggro_completed)
  12144. result = true;
  12145. }
  12146. lua_interface->SetBooleanValue(state, result);
  12147. return 1;
  12148. }
  12149. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12150. Client* client = nullptr;
  12151. Spawn* player = lua_interface->GetSpawn(state);
  12152. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12153. lua_interface->ResetFunctionStack(state);
  12154. if (!player) {
  12155. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12156. lua_interface->SetBooleanValue(state, false);
  12157. return 1;
  12158. }
  12159. if (!player->IsPlayer()) {
  12160. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12161. lua_interface->SetBooleanValue(state, false);
  12162. return 1;
  12163. }
  12164. client = player->GetClient();
  12165. if (!client) {
  12166. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12167. lua_interface->SetBooleanValue(state, false);
  12168. return 1;
  12169. }
  12170. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12171. lua_interface->SetBooleanValue(state, result);
  12172. return 1;
  12173. }
  12174. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12175. Client* client = nullptr;
  12176. Spawn* player = lua_interface->GetSpawn(state);
  12177. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12178. lua_interface->ResetFunctionStack(state);
  12179. if (!player) {
  12180. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12181. lua_interface->SetBooleanValue(state, false);
  12182. return 1;
  12183. }
  12184. if (!player->IsPlayer()) {
  12185. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12186. lua_interface->SetBooleanValue(state, false);
  12187. return 1;
  12188. }
  12189. client = player->GetClient();
  12190. if (!client) {
  12191. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12192. lua_interface->SetBooleanValue(state, false);
  12193. return 1;
  12194. }
  12195. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12196. lua_interface->SetBooleanValue(state, result);
  12197. return 1;
  12198. }
  12199. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12200. Client* client = nullptr;
  12201. Spawn* player = lua_interface->GetSpawn(state);
  12202. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12203. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12204. // rest are all optional fields
  12205. float x = lua_interface->GetFloatValue(state, 4);
  12206. float y = lua_interface->GetFloatValue(state, 5);
  12207. float z = lua_interface->GetFloatValue(state, 6);
  12208. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12209. lua_interface->ResetFunctionStack(state);
  12210. if (!player) {
  12211. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12212. lua_interface->SetBooleanValue(state, false);
  12213. return 1;
  12214. }
  12215. if (!player->IsPlayer()) {
  12216. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12217. lua_interface->SetBooleanValue(state, false);
  12218. return 1;
  12219. }
  12220. if(!player->GetZone()) {
  12221. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12222. lua_interface->SetBooleanValue(state, false);
  12223. return 1;
  12224. }
  12225. client = player->GetClient();
  12226. if (!client) {
  12227. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12228. lua_interface->SetBooleanValue(state, false);
  12229. return 1;
  12230. }
  12231. if(!client->IsReadyForUpdates()) {
  12232. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12233. lua_interface->SetBooleanValue(state, false);
  12234. return 1;
  12235. }
  12236. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12237. lua_interface->SetBooleanValue(state, true);
  12238. return 1;
  12239. }
  12240. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12241. Client* client = nullptr;
  12242. Spawn* spawn = lua_interface->GetSpawn(state);
  12243. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12244. lua_interface->ResetFunctionStack(state);
  12245. if (!spawn) {
  12246. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12247. lua_interface->SetBooleanValue(state, false);
  12248. return 1;
  12249. }
  12250. if(!spawn->GetZone()) {
  12251. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12252. lua_interface->SetBooleanValue(state, false);
  12253. return 1;
  12254. }
  12255. spawn->AddIgnoredWidget(widget_id);
  12256. lua_interface->SetBooleanValue(state, true);
  12257. return 1;
  12258. }
  12259. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12260. ZoneServer* zone = lua_interface->GetZone(state);
  12261. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12262. lua_interface->ResetFunctionStack(state);
  12263. if(!zone) {
  12264. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12265. lua_interface->SetBooleanValue(state, false);
  12266. return 1;
  12267. }
  12268. if(!zone->IsLoading()) {
  12269. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12270. lua_interface->SetBooleanValue(state, false);
  12271. return 1;
  12272. }
  12273. zone->AddIgnoredWidget(widget_id);
  12274. lua_interface->SetBooleanValue(state, true);
  12275. return 1;
  12276. }
  12277. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12278. if (!lua_interface)
  12279. return 0;
  12280. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12281. Spawn* spawn = lua_interface->GetSpawn(state);
  12282. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12283. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12284. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12285. Spawn* target = lua_interface->GetSpawn(state, 5);
  12286. lua_interface->ResetFunctionStack(state);
  12287. if(spell && spawn && spawn->IsEntity()) {
  12288. ZoneServer* zone = spawn->GetZone();
  12289. if(zone) {
  12290. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12291. }
  12292. }
  12293. else if (spawn) {
  12294. if (spawn->IsPlayer()) {
  12295. Client* client = ((Player*)spawn)->GetClient();
  12296. if (client) {
  12297. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12298. }
  12299. }
  12300. }
  12301. return 0;
  12302. }
  12303. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12304. if (!lua_interface)
  12305. return 0;
  12306. Spawn* player = lua_interface->GetSpawn(state);
  12307. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12308. lua_interface->ResetFunctionStack(state);
  12309. if (!player) {
  12310. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12311. return 0;
  12312. }
  12313. if (!player->IsPlayer()) {
  12314. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12315. return 0;
  12316. }
  12317. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12318. lua_interface->SetBooleanValue(state, ret);
  12319. return 1;
  12320. }
  12321. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12322. if (!lua_interface)
  12323. return 0;
  12324. Spawn* player = lua_interface->GetSpawn(state);
  12325. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12326. lua_interface->ResetFunctionStack(state);
  12327. if (!player) {
  12328. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12329. return 0;
  12330. }
  12331. if (!player->IsPlayer()) {
  12332. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12333. return 0;
  12334. }
  12335. ((Player*)player)->toggle_character_flag(flag_id);
  12336. return 0;
  12337. }
  12338. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12339. LuaSpell* spell = lua_interface->GetSpell(state);
  12340. if(!spell) {
  12341. spell = lua_interface->GetCurrentSpell(state);
  12342. }
  12343. lua_interface->ResetFunctionStack(state);
  12344. if (spell) {
  12345. if(!spell->caster) {
  12346. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12347. return 0;
  12348. }
  12349. if(!spell->caster->GetZone()) {
  12350. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12351. return 0;
  12352. }
  12353. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12354. if (spawn) {
  12355. lua_interface->SetSpawnValue(state, spawn);
  12356. return 1;
  12357. }
  12358. else {
  12359. lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
  12360. }
  12361. }
  12362. return 0;
  12363. }
  12364. int EQ2Emu_lua_DespawnByLocationID(lua_State* state) {
  12365. ZoneServer* zone = lua_interface->GetZone(state);
  12366. int32 location_id = lua_interface->GetInt32Value(state, 2);
  12367. int32 delay = lua_interface->GetInt32Value(state, 3);
  12368. lua_interface->ResetFunctionStack(state);
  12369. if (zone) {
  12370. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  12371. if (spawn) {
  12372. vector<Spawn*> groupMembers;
  12373. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  12374. groupMembers = *spawn->GetSpawnGroup();
  12375. for (int32 i = 0; i < groupMembers.size(); i++) {
  12376. Spawn* member = groupMembers.at(i);
  12377. if(member && !member->IsPlayer() && member != spawn) {
  12378. member->GetZone()->Despawn(member, delay);
  12379. }
  12380. }
  12381. }
  12382. zone->Despawn(spawn, delay);
  12383. lua_interface->SetBooleanValue(state, true);
  12384. return 1;
  12385. }
  12386. }
  12387. lua_interface->SetBooleanValue(state, false);
  12388. return 1;
  12389. }
  12390. int EQ2Emu_lua_AddRespawn(lua_State* state) {
  12391. ZoneServer* zone = lua_interface->GetZone(state);
  12392. int32 location_id = lua_interface->GetInt32Value(state, 2);
  12393. int32 respawn_time = lua_interface->GetInt32Value(state, 3);
  12394. lua_interface->ResetFunctionStack(state);
  12395. if (zone) {
  12396. zone->AddRespawn(location_id, respawn_time);
  12397. lua_interface->SetBooleanValue(state, true);
  12398. return 1;
  12399. }
  12400. lua_interface->SetBooleanValue(state, false);
  12401. return 1;
  12402. }
  12403. int EQ2Emu_lua_CreatePersistedRespawn(lua_State* state) {
  12404. int32 location_id = lua_interface->GetInt32Value(state);
  12405. int8 spawn_type = lua_interface->GetInt32Value(state, 2);
  12406. int32 respawn_time = lua_interface->GetInt32Value(state, 3);
  12407. int32 zone_id = lua_interface->GetInt32Value(state, 4);
  12408. lua_interface->ResetFunctionStack(state);
  12409. if (location_id && zone_id) {
  12410. database.CreatePersistedRespawn(location_id,spawn_type,respawn_time,zone_id);
  12411. lua_interface->SetBooleanValue(state, true);
  12412. return 1;
  12413. }
  12414. lua_interface->SetBooleanValue(state, false);
  12415. return 1;
  12416. }