LuaFunctions.cpp 335 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913
  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 "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. #include <boost/algorithm/string/predicate.hpp>
  35. #include <sstream>
  36. #include <boost/algorithm/string.hpp>
  37. extern MasterFactionList master_faction_list;
  38. extern WorldDatabase database;
  39. extern LuaInterface* lua_interface;
  40. extern ConfigReader configReader;
  41. extern MasterQuestList master_quest_list;
  42. extern MasterItemList master_item_list;
  43. extern MasterSpellList master_spell_list;
  44. extern World world;
  45. extern Commands commands;
  46. extern ZoneList zone_list;
  47. extern Races races;
  48. extern Classes classes;
  49. extern Variables variables;
  50. extern MasterSkillList master_skill_list;
  51. extern MasterHeroicOPList master_ho_list;
  52. extern MasterRaceTypeList race_types_list;
  53. extern MasterLanguagesList master_languages_list;
  54. vector<string> ParseString(string strVal, char delim) {
  55. stringstream ss(strVal);
  56. vector<string> ret;
  57. while (ss.good())
  58. {
  59. string substr;
  60. getline(ss, substr, delim);
  61. ret.push_back(substr);
  62. }
  63. return ret;
  64. }
  65. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  66. stringstream ss(strVal);
  67. vector<unsigned int> ret;
  68. while (ss.good())
  69. {
  70. string substr;
  71. getline(ss, substr, delim);
  72. stringstream valss(substr);
  73. unsigned int val = 0;
  74. valss >> val;
  75. ret.push_back(val);
  76. }
  77. return ret;
  78. }
  79. map<string, signed int> ParseStringMap(string strVal, char delim) {
  80. vector<string> pairs = ParseString(strVal, delim);
  81. vector<string>::iterator itr;
  82. map<string, signed int> ret;
  83. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  84. vector<string> keyvaluepair = ParseString(*itr, ':');
  85. if (keyvaluepair.size() == 2) {
  86. stringstream valss(keyvaluepair[1]);
  87. int32 val = 0;
  88. valss >> val;
  89. ret[keyvaluepair[0]] = val;
  90. }
  91. }
  92. return ret;
  93. }
  94. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  95. vector<string> pairs = ParseString(strVal, delim);
  96. vector<string>::iterator itr;
  97. map<unsigned int, unsigned short> ret;
  98. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  99. vector<string> keyvaluepair = ParseString(*itr, ':');
  100. int32 key = 0;
  101. if (keyvaluepair.size() > 0) {
  102. stringstream keyss(keyvaluepair[0]);
  103. keyss >> key;
  104. }
  105. if (keyvaluepair.size() == 1) {
  106. ret[key] = 1;
  107. }
  108. else if (keyvaluepair.size() == 2) {
  109. stringstream valss(keyvaluepair[1]);
  110. unsigned short val = 0;
  111. valss >> val;
  112. ret[key] = val;
  113. }
  114. }
  115. return ret;
  116. }
  117. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  118. vector<string> pairs = ParseString(strVal, delim);
  119. vector<string>::iterator itr;
  120. map<unsigned int, signed int> ret;
  121. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  122. vector<string> keyvaluepair = ParseString(*itr, ':');
  123. int32 key = 0;
  124. if (keyvaluepair.size() > 0) {
  125. stringstream keyss(keyvaluepair[0]);
  126. keyss >> key;
  127. }
  128. if (keyvaluepair.size() == 1) {
  129. ret[key] = 1;
  130. }
  131. else if (keyvaluepair.size() == 2) {
  132. stringstream valss(keyvaluepair[1]);
  133. signed int val = 0;
  134. valss >> val;
  135. ret[key] = val;
  136. }
  137. }
  138. return ret;
  139. }
  140. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  141. if (!lua_interface)
  142. return 0;
  143. Spawn* spawn = lua_interface->GetSpawn(state);
  144. string mp3_string = lua_interface->GetStringValue(state, 2);
  145. string text_string = lua_interface->GetStringValue(state, 3);
  146. string emote_string = lua_interface->GetStringValue(state, 4);
  147. int32 key1 = lua_interface->GetInt32Value(state, 5);
  148. int32 key2 = lua_interface->GetInt32Value(state, 6);
  149. Spawn* player = lua_interface->GetSpawn(state, 7);
  150. int8 language = lua_interface->GetInt8Value(state, 8);
  151. if (spawn) {
  152. const char* mp3 = 0;
  153. const char* text = 0;
  154. const char* emote = 0;
  155. if (mp3_string.length() > 0)
  156. mp3 = mp3_string.c_str();
  157. if (text_string.length() > 0)
  158. text = text_string.c_str();
  159. if (emote_string.length() > 0)
  160. emote = emote_string.c_str();
  161. Client* client = 0;
  162. if (player && player->IsPlayer())
  163. client = spawn->GetZone()->GetClientBySpawn(player);
  164. if (client) {
  165. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  166. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  167. }
  168. else
  169. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  170. }
  171. return 0;
  172. }
  173. int EQ2Emu_lua_PlaySound(lua_State* state) {
  174. if (!lua_interface)
  175. return 0;
  176. Spawn* spawn = lua_interface->GetSpawn(state);
  177. string sound_string = lua_interface->GetStringValue(state, 2);
  178. float x = lua_interface->GetFloatValue(state, 3);
  179. float y = lua_interface->GetFloatValue(state, 4);
  180. float z = lua_interface->GetFloatValue(state, 5);
  181. Spawn* player = lua_interface->GetSpawn(state, 6);
  182. if (spawn && sound_string.length() > 0) {
  183. Client* client = 0;
  184. if (player && player->IsPlayer())
  185. client = spawn->GetZone()->GetClientBySpawn(player);
  186. if (client)
  187. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  188. else
  189. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  190. }
  191. return 0;
  192. }
  193. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  194. if (!lua_interface)
  195. return 0;
  196. Spawn* spawn = lua_interface->GetSpawn(state);
  197. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  198. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  199. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  200. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  201. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  202. if (!spawn) {
  203. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  204. return 0;
  205. }
  206. if (quest_id > 0) {
  207. //Add this quest to the list of required quests for this spawn
  208. spawn->SetQuestsRequired(quest_id, quest_step);
  209. //If private spawn value set
  210. if (private_spawn) {
  211. //Set the spawn to be private when not granted access through this quest
  212. spawn->AddAllowAccessSpawn(spawn);
  213. spawn->SetPrivateQuestSpawn(true);
  214. }
  215. //This value allows access after a quest step, or the whole quest has been completed
  216. if (continued_access)
  217. spawn->SetQuestsRequiredContinuedAccess(true);
  218. //This value will override vis_flags in the vis packet
  219. if (flag_override > 0)
  220. spawn->SetQuestsRequiredOverride(flag_override);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. float max_distance = lua_interface->GetFloatValue(state, 2);
  229. string variable = lua_interface->GetStringValue(state, 3);
  230. string value = lua_interface->GetStringValue(state, 4);
  231. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  232. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  233. return 0;
  234. }
  235. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  236. if (!lua_interface)
  237. return 0;
  238. Client* client = 0;
  239. Spawn* player = lua_interface->GetSpawn(state);
  240. if (!player) {
  241. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  242. return 0;
  243. }
  244. if (!player->IsPlayer()) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  246. return 0;
  247. }
  248. if (player->GetZone())
  249. client = player->GetZone()->GetClientBySpawn(player);
  250. if (!client) {
  251. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  252. return 0;
  253. }
  254. float intensity = lua_interface->GetFloatValue(state, 2);
  255. int8 direction = lua_interface->GetInt8Value(state, 3);
  256. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  257. if (packet) {
  258. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  259. v1 = *(float *)(a1 + 4);
  260. if ( v1 > 0.0 )
  261. v2 = fminf(v1, 1.0);
  262. else
  263. v2 = 0.1;
  264. */
  265. packet->setDataByName("intensity", intensity);
  266. if ( client->GetVersion() > 546 )
  267. packet->setDataByName("direction", direction);
  268. client->QueuePacket(packet->serialize());
  269. safe_delete(packet);
  270. }
  271. return 0;
  272. }
  273. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  274. if (!lua_interface)
  275. return 0;
  276. Spawn* dead = lua_interface->GetSpawn(state);
  277. Spawn* killer = lua_interface->GetSpawn(state, 2);
  278. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  279. if (dead && dead->Alive() && dead->GetZone())
  280. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  281. return 0;
  282. }
  283. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  284. if (!lua_interface)
  285. return 0;
  286. Spawn* spawn = lua_interface->GetSpawn(state);
  287. float max_distance = lua_interface->GetFloatValue(state, 2);
  288. bool include_players = lua_interface->GetInt8Value(state, 3);
  289. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  290. if (max_distance > 0 && spawn && spawn->GetZone())
  291. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  292. return 0;
  293. }
  294. int EQ2Emu_lua_Despawn(lua_State* state) {
  295. if (!lua_interface)
  296. return 0;
  297. Spawn* spawn = lua_interface->GetSpawn(state);
  298. int32 delay = lua_interface->GetInt32Value(state, 2);
  299. if (spawn && spawn->GetZone())
  300. spawn->GetZone()->Despawn(spawn, delay);
  301. return 0;
  302. }
  303. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  304. if (!lua_interface)
  305. return 0;
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  308. if (spawn) {
  309. spawn->info_changed = true;
  310. spawn->SetShowHandIcon(displayHandIcon);
  311. }
  312. return 0;
  313. }
  314. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  315. if (!lua_interface)
  316. return 0;
  317. Spawn* spawn = lua_interface->GetSpawn(state);
  318. int32 new_state = lua_interface->GetInt32Value(state, 2);
  319. if (spawn) {
  320. spawn->GetZone()->SendStateCommand(spawn, new_state);
  321. }
  322. return 0;
  323. }
  324. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  325. if (!lua_interface)
  326. return 0;
  327. Spawn* spawn = lua_interface->GetSpawn(state);
  328. string variable = lua_interface->GetStringValue(state, 2);
  329. string value = lua_interface->GetStringValue(state, 3);
  330. 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.
  331. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  332. int32 type = commands.GetSpawnSetType(variable);
  333. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  334. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  335. return 0;
  336. }
  337. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  338. if (!lua_interface)
  339. return 0;
  340. Spawn* spawn = lua_interface->GetSpawn(state);
  341. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  342. if (spawn && spawn_id > 0) {
  343. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  344. if (closest_spawn) {
  345. lua_interface->SetSpawnValue(state, closest_spawn);
  346. return 1;
  347. }
  348. }
  349. return 0;
  350. }
  351. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  352. if (!lua_interface)
  353. return 0;
  354. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  355. int32 position = lua_interface->GetInt32Value(state, 2);
  356. if (spawnList) {
  357. if (spawnList->size() > position) {
  358. lua_interface->SetSpawnValue(state, spawnList->at(position));
  359. return 1;
  360. }
  361. else {
  362. return 0;
  363. }
  364. return spawnList->size();
  365. }
  366. return 0;
  367. }
  368. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  369. if (!lua_interface)
  370. return 0;
  371. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  372. if (spawnList) {
  373. return spawnList->size();
  374. }
  375. return 0;
  376. }
  377. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. vector<Spawn*>* spawnList = new vector<Spawn*>();
  381. lua_interface->SetSpawnListValue(state, spawnList);
  382. return 1;
  383. }
  384. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  385. if (!lua_interface)
  386. return 0;
  387. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  388. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  389. if (spawnList) {
  390. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  391. if (it == spawnList->end())
  392. spawnList->push_back(spawn);
  393. }
  394. return 0;
  395. }
  396. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  397. if (!lua_interface)
  398. return 0;
  399. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  400. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  401. if (spawnList) {
  402. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  403. if(it != spawnList->end())
  404. spawnList->erase(it);
  405. }
  406. return 0;
  407. }
  408. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  409. if (!lua_interface)
  410. return 0;
  411. Spawn* spawn = lua_interface->GetSpawn(state);
  412. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  413. if (spawn) {
  414. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  415. if (spawns.size() > 0) {
  416. vector<Spawn*>* spawnList = new vector<Spawn*>();
  417. vector<Spawn*>::iterator itr;
  418. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  419. spawnList->push_back(*itr);
  420. }
  421. lua_interface->SetSpawnListValue(state, spawnList);
  422. return 1;
  423. }
  424. }
  425. return 0;
  426. }
  427. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  428. if (!lua_interface)
  429. return 0;
  430. string variable_name = lua_interface->GetStringValue(state);
  431. Variable* var = variables.FindVariable(variable_name);
  432. if (var) {
  433. lua_interface->SetStringValue(state, var->GetValue());
  434. return 1;
  435. }
  436. return 0;
  437. }
  438. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  439. if (!lua_interface)
  440. return 0;
  441. int32 total_coins = lua_interface->GetInt32Value(state);
  442. if (total_coins == 0) {
  443. lua_interface->SetStringValue(state, "0 copper");
  444. return 1;
  445. }
  446. char tmp[64] = { 0 };
  447. string message = "";
  448. int32 val = 0;
  449. if (total_coins >= 1000000) {
  450. val = total_coins / 1000000;
  451. total_coins -= 1000000 * val;
  452. sprintf(tmp, " %u Platinum", val);
  453. message.append(tmp);
  454. memset(tmp, 0, 64);
  455. }
  456. if (total_coins >= 10000) {
  457. val = total_coins / 10000;
  458. total_coins -= 10000 * val;
  459. sprintf(tmp, " %u Gold", val);
  460. message.append(tmp);
  461. memset(tmp, 0, 64);
  462. }
  463. if (total_coins >= 100) {
  464. val = total_coins / 100;
  465. total_coins -= 100 * val;
  466. sprintf(tmp, " %u Silver", val);
  467. message.append(tmp);
  468. memset(tmp, 0, 64);
  469. }
  470. if (total_coins > 0) {
  471. sprintf(tmp, " %u Copper", (int32)total_coins);
  472. message.append(tmp);
  473. }
  474. lua_interface->SetStringValue(state, message.c_str());
  475. return 1;
  476. }
  477. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  478. ZoneServer* zone = lua_interface->GetZone(state);
  479. int32 group_id = lua_interface->GetInt32Value(state, 2);
  480. if (zone) {
  481. Spawn* spawn = zone->GetSpawnGroup(group_id);
  482. if (spawn) {
  483. lua_interface->SetSpawnValue(state, spawn);
  484. return 1;
  485. }
  486. }
  487. return 0;
  488. }
  489. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  490. ZoneServer* zone = lua_interface->GetZone(state);
  491. int32 location_id = lua_interface->GetInt32Value(state, 2);
  492. if (zone) {
  493. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  494. if (spawn) {
  495. lua_interface->SetSpawnValue(state, spawn);
  496. return 1;
  497. }
  498. }
  499. return 0;
  500. }
  501. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  502. Spawn* spawn = lua_interface->GetSpawn(state);
  503. if (spawn) {
  504. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  505. return 1;
  506. }
  507. return 0;
  508. }
  509. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  510. Spawn* spawn = lua_interface->GetSpawn(state);
  511. if (spawn) {
  512. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  513. return 1;
  514. }
  515. return 0;
  516. }
  517. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  518. Spawn* spawn = lua_interface->GetSpawn(state);
  519. if (spawn) {
  520. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  521. return 1;
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  526. Spawn* spawn = lua_interface->GetSpawn(state);
  527. if (spawn) {
  528. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  529. return 1;
  530. }
  531. return 0;
  532. }
  533. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  534. Player* player = (Player*)lua_interface->GetSpawn(state);
  535. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  536. if (player && player->IsPlayer() && faction_id > 0) {
  537. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  538. return 1;
  539. }
  540. return 0;
  541. }
  542. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  543. if (!lua_interface)
  544. return 0;
  545. Spawn* spawn = lua_interface->GetSpawn(state);
  546. int32 value = lua_interface->GetInt32Value(state, 2);
  547. if (spawn) {
  548. spawn->SetFactionID(value);
  549. }
  550. return 0;
  551. }
  552. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  553. Spawn* spawn = lua_interface->GetSpawn(state);
  554. if (spawn) {
  555. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  556. return 1;
  557. }
  558. return 0;
  559. }
  560. int EQ2Emu_lua_GetGender(lua_State* state) {
  561. Spawn* spawn = lua_interface->GetSpawn(state);
  562. if (spawn) {
  563. lua_interface->SetInt32Value(state, spawn->GetGender());
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_GetTarget(lua_State* state) {
  569. Spawn* spawn = lua_interface->GetSpawn(state);
  570. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  571. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  577. if (!lua_interface)
  578. return 0;
  579. Spawn* spawn = lua_interface->GetSpawn(state);
  580. string mp3_string = lua_interface->GetStringValue(state, 2);
  581. int32 key1 = lua_interface->GetInt32Value(state, 3);
  582. int32 key2 = lua_interface->GetInt32Value(state, 4);
  583. Spawn* player = lua_interface->GetSpawn(state, 5);
  584. if (spawn && mp3_string.length() > 0) {
  585. Client* client = 0;
  586. if (player && player->IsPlayer())
  587. client = spawn->GetZone()->GetClientBySpawn(player);
  588. if (client) {
  589. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  590. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  591. }
  592. else
  593. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  594. }
  595. return 0;
  596. }
  597. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  598. if (!lua_interface)
  599. return 0;
  600. Spawn* spawn = lua_interface->GetSpawn(state);
  601. if (spawn) {
  602. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  603. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  604. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  605. return 3;
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  610. if (!lua_interface)
  611. return 0;
  612. Spawn* spawn = lua_interface->GetSpawn(state);
  613. if (spawn) {
  614. int32 item_id = lua_interface->GetInt32Value(state, 2);
  615. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  616. return 1;
  617. }
  618. return 0;
  619. }
  620. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  621. if (!lua_interface)
  622. return 0;
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. if (spawn && spawn->IsEntity()) {
  625. int32 item_id = lua_interface->GetInt32Value(state, 2);
  626. int16 charges = lua_interface->GetInt16Value(state, 3);
  627. if (charges == 0)
  628. charges = 1;
  629. ((Entity*)spawn)->AddLootItem(item_id, charges);
  630. }
  631. return 0;
  632. }
  633. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  634. if (!lua_interface)
  635. return 0;
  636. Spawn* spawn = lua_interface->GetSpawn(state);
  637. if (spawn && spawn->IsEntity()) {
  638. int32 item_id = lua_interface->GetInt32Value(state, 2);
  639. spawn->LootItem(item_id);
  640. }
  641. return 0;
  642. }
  643. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  644. if (!lua_interface)
  645. return 0;
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. if (spawn) {
  648. int32 val = lua_interface->GetInt32Value(state, 2);
  649. spawn->AddLootCoins(val);
  650. }
  651. return 0;
  652. }
  653. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  654. if (!lua_interface)
  655. return 0;
  656. Spawn* entity = lua_interface->GetSpawn(state);
  657. Spawn* player = lua_interface->GetSpawn(state, 2);
  658. if (entity && player && player->IsPlayer()) {
  659. int32 coins = lua_interface->GetInt32Value(state, 3);
  660. vector<Item*>* items = 0;
  661. int i = 0;
  662. int32 item_id = 0;
  663. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  664. if (items == 0)
  665. items = new vector<Item*>;
  666. if (master_item_list.GetItem(item_id))
  667. items->push_back(master_item_list.GetItem(item_id));
  668. i++;
  669. }
  670. Client* client = 0;
  671. client = player->GetZone()->GetClientBySpawn(player);
  672. if (client)
  673. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  674. if(coins > 0)
  675. entity->AddLootCoins(coins);
  676. safe_delete(items);
  677. }
  678. return 0;
  679. }
  680. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  681. if (!lua_interface)
  682. return 0;
  683. Spawn* entity = lua_interface->GetSpawn(state);
  684. Spawn* player = lua_interface->GetSpawn(state, 2);
  685. int32 item_id = lua_interface->GetInt32Value(state, 3);
  686. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  687. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  688. return 1;
  689. }
  690. return 0;
  691. }
  692. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  693. if (!lua_interface)
  694. return 0;
  695. Spawn* entity = lua_interface->GetSpawn(state);
  696. Spawn* player = lua_interface->GetSpawn(state, 2);
  697. if (entity && player && player->IsPlayer()) {
  698. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  699. return 1;
  700. }
  701. return 0;
  702. }
  703. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  704. if (!lua_interface)
  705. return 0;
  706. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  707. safe_delete(conversation);
  708. conversation = new vector<ConversationOption>();
  709. lua_interface->SetConversationValue(state, conversation);
  710. return 1;
  711. }
  712. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  713. if (!lua_interface)
  714. return 0;
  715. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  716. if (conversation) {
  717. ConversationOption conv_option;
  718. conv_option.option = lua_interface->GetStringValue(state, 2);
  719. conv_option.function = lua_interface->GetStringValue(state, 3);
  720. if (conv_option.option.length() > 0)
  721. conversation->push_back(conv_option);
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  726. if (!lua_interface)
  727. return 0;
  728. Spawn* npc = lua_interface->GetSpawn(state);
  729. Spawn* player = lua_interface->GetSpawn(state, 2);
  730. if (npc && player && player->IsPlayer() && player->GetZone()) {
  731. Client* client = player->GetZone()->GetClientBySpawn(player);
  732. if (client) {
  733. int32 conversation_id = client->GetConversationID(npc, 0);
  734. client->CloseDialog(conversation_id);
  735. }
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  740. if (!lua_interface)
  741. return 0;
  742. Item* item = lua_interface->GetItem(state);
  743. Spawn* player = lua_interface->GetSpawn(state, 2);
  744. if (item && player && player->IsPlayer() && player->GetZone()) {
  745. Client* client = player->GetZone()->GetClientBySpawn(player);
  746. if (client) {
  747. int32 conversation_id = client->GetConversationID(0, item);
  748. client->CloseDialog(conversation_id);
  749. }
  750. }
  751. return 0;
  752. }
  753. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  754. if (!lua_interface)
  755. return 0;
  756. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  757. Spawn* spawn = 0;
  758. Item* item = 0;
  759. int8 type = lua_interface->GetInt8Value(state, 2);
  760. if (type == 1 || type == 3)
  761. spawn = lua_interface->GetSpawn(state, 3);
  762. else if (type == 2 || type == 4)
  763. item = lua_interface->GetItem(state, 3);
  764. Spawn* player = lua_interface->GetSpawn(state, 4);
  765. string text = lua_interface->GetStringValue(state, 5);
  766. string mp3 = lua_interface->GetStringValue(state, 6);
  767. int32 key1 = lua_interface->GetInt32Value(state, 7);
  768. int32 key2 = lua_interface->GetInt32Value(state, 8);
  769. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  770. Client* client = player->GetZone()->GetClientBySpawn(player);
  771. if (client) {
  772. if (spawn) {
  773. // Need to do this so the function works the same as it did before
  774. if (type == 1)
  775. type++;
  776. if (mp3.length() > 0)
  777. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  778. else
  779. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  780. }
  781. else {
  782. if (mp3.length() > 0)
  783. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  784. else
  785. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  786. }
  787. }
  788. }
  789. safe_delete(conversation);
  790. lua_interface->SetConversationValue(state, NULL);
  791. return 0;
  792. }
  793. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  794. if(!lua_interface)
  795. return 0;
  796. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  797. Item* item = lua_interface->GetItem(state, 2);
  798. Spawn* player = lua_interface->GetSpawn(state, 3);
  799. string text = lua_interface->GetStringValue(state, 4);
  800. string mp3 = lua_interface->GetStringValue(state, 5);
  801. int32 key1 = lua_interface->GetInt32Value(state, 6);
  802. int32 key2 = lua_interface->GetInt32Value(state, 7);
  803. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  804. Client* client = player->GetZone()->GetClientBySpawn(player);
  805. if(client){
  806. if(mp3.length() > 0)
  807. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  808. else
  809. client->DisplayConversation(item, conversation, (char*)text.c_str());
  810. }
  811. safe_delete(conversation);
  812. }
  813. return 0;
  814. }*/
  815. int EQ2Emu_lua_StartConversation(lua_State* state) {
  816. if (!lua_interface)
  817. return 0;
  818. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  819. Spawn* npc = lua_interface->GetSpawn(state, 2);
  820. Spawn* player = lua_interface->GetSpawn(state, 3);
  821. string text = lua_interface->GetStringValue(state, 4);
  822. string mp3 = lua_interface->GetStringValue(state, 5);
  823. int32 key1 = lua_interface->GetInt32Value(state, 6);
  824. int32 key2 = lua_interface->GetInt32Value(state, 7);
  825. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  826. Client* client = npc->GetZone()->GetClientBySpawn(player);
  827. if (mp3.length() > 0)
  828. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  829. else
  830. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  831. safe_delete(conversation);
  832. lua_interface->SetConversationValue(state, NULL);
  833. }
  834. else
  835. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  836. return 0;
  837. }
  838. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  839. if (!lua_interface)
  840. return 0;
  841. Spawn* spawn = lua_interface->GetSpawn(state);
  842. float distance = lua_interface->GetFloatValue(state, 2);
  843. string in_range_function = lua_interface->GetStringValue(state, 3);
  844. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  845. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  846. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  847. return 0;
  848. }
  849. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  850. ZoneServer* zone = lua_interface->GetZone(state);
  851. float x = lua_interface->GetFloatValue(state, 2);
  852. float y = lua_interface->GetFloatValue(state, 3);
  853. float z = lua_interface->GetFloatValue(state, 4);
  854. float max_variation = lua_interface->GetFloatValue(state, 5);
  855. string in_range_function = lua_interface->GetStringValue(state, 6);
  856. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  857. if (zone && in_range_function.length() > 0)
  858. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  859. return 0;
  860. }
  861. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  862. if (!lua_interface)
  863. return 0;
  864. Spawn* spawn = lua_interface->GetSpawn(state);
  865. if (spawn && spawn->IsEntity()) {
  866. int32 val = lua_interface->GetInt32Value(state, 2);
  867. ((Entity*)spawn)->SetLootCoins(val);
  868. }
  869. return 0;
  870. }
  871. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* spawn = lua_interface->GetSpawn(state);
  875. if (spawn && spawn->IsEntity()) {
  876. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  877. return 1;
  878. }
  879. return 0;
  880. }
  881. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  882. if (!lua_interface)
  883. return 0;
  884. Spawn* spawn = lua_interface->GetSpawn(state);
  885. float x = lua_interface->GetFloatValue(state, 2);
  886. float y = lua_interface->GetFloatValue(state, 3);
  887. float z = lua_interface->GetFloatValue(state, 4);
  888. float speed = lua_interface->GetFloatValue(state, 5);
  889. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  890. string function = lua_interface->GetStringValue(state, 7);
  891. if (spawn) {
  892. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  893. spawn->GetZone()->AddMovementNPC(spawn);
  894. }
  895. lua_interface->ResetFunctionStack(state);
  896. return 0;
  897. }
  898. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  899. if (!lua_interface)
  900. return 0;
  901. Spawn* spawn = lua_interface->GetSpawn(state);
  902. if (spawn) {
  903. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  904. return 1;
  905. }
  906. return 0;
  907. }
  908. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  909. if (!lua_interface)
  910. return 0;
  911. Spawn* spawn = lua_interface->GetSpawn(state);
  912. Spawn* target = lua_interface->GetSpawn(state, 2);
  913. if (spawn && target) {
  914. if (spawn->IsEntity())
  915. // ((Entity*)spawn)->FaceTarget(target);
  916. static_cast<Entity*>(spawn)->FaceTarget(target);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* spawn = lua_interface->GetSpawn(state);
  925. float x = lua_interface->GetFloatValue(state, 2);
  926. float y = lua_interface->GetFloatValue(state, 3);
  927. float z = lua_interface->GetFloatValue(state, 4);
  928. float speed = lua_interface->GetFloatValue(state, 5);
  929. string lua_function = lua_interface->GetStringValue(state, 6);
  930. bool more_points = lua_interface->GetBooleanValue(state, 7);
  931. if (spawn) {
  932. if (speed == 0)
  933. speed = spawn->GetSpeed();
  934. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  935. }
  936. lua_interface->ResetFunctionStack(state);
  937. return 0;
  938. }
  939. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  940. if (!lua_interface)
  941. return 0;
  942. Spawn* spawn = lua_interface->GetSpawn(state);
  943. if (spawn) {
  944. spawn->ClearRunningLocations();
  945. }
  946. return 0;
  947. }
  948. int EQ2Emu_lua_Say(lua_State* state) {
  949. if (!lua_interface)
  950. return 0;
  951. Spawn* spawn = lua_interface->GetSpawn(state);
  952. string message = lua_interface->GetStringValue(state, 2);
  953. Spawn* player = lua_interface->GetSpawn(state, 3);
  954. int32 language = lua_interface->GetInt32Value(state, 4);
  955. if (spawn && message.length() > 0) {
  956. Client* client = 0;
  957. if (player && player->IsPlayer())
  958. client = spawn->GetZone()->GetClientBySpawn(player);
  959. if (client)
  960. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  961. else
  962. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  963. }
  964. lua_interface->ResetFunctionStack(state);
  965. return 0;
  966. }
  967. int EQ2Emu_lua_Shout(lua_State* state) {
  968. if (!lua_interface)
  969. return 0;
  970. Spawn* spawn = lua_interface->GetSpawn(state);
  971. string message = lua_interface->GetStringValue(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. if (spawn && message.length() > 0) {
  974. Client* client = 0;
  975. if (player && player->IsPlayer())
  976. client = spawn->GetZone()->GetClientBySpawn(player);
  977. if (client)
  978. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  979. else
  980. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  981. }
  982. lua_interface->ResetFunctionStack(state);
  983. return 0;
  984. }
  985. int EQ2Emu_lua_SayOOC(lua_State* state) {
  986. if (!lua_interface)
  987. return 0;
  988. Spawn* spawn = lua_interface->GetSpawn(state);
  989. string message = lua_interface->GetStringValue(state, 2);
  990. Spawn* player = lua_interface->GetSpawn(state, 3);
  991. if (spawn && message.length() > 0) {
  992. Client* client = 0;
  993. if (player && player->IsPlayer())
  994. client = spawn->GetZone()->GetClientBySpawn(player);
  995. if (client)
  996. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  997. else
  998. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  999. }
  1000. lua_interface->ResetFunctionStack(state);
  1001. return 0;
  1002. }
  1003. int EQ2Emu_lua_Emote(lua_State* state) {
  1004. if (!lua_interface)
  1005. return 0;
  1006. Spawn* spawn = lua_interface->GetSpawn(state);
  1007. string message = lua_interface->GetStringValue(state, 2);
  1008. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1009. Spawn* player = lua_interface->GetSpawn(state, 4);
  1010. char* to = 0;
  1011. if (spawn2)
  1012. to = spawn2->GetName();
  1013. if (spawn && message.length() > 0) {
  1014. Client* client = 0;
  1015. if (player && player->IsPlayer())
  1016. client = spawn->GetZone()->GetClientBySpawn(player);
  1017. if (client)
  1018. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1019. else
  1020. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1021. }
  1022. lua_interface->ResetFunctionStack(state);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1029. if (!luaspell)
  1030. return 0;
  1031. Spawn* caster = luaspell->caster;
  1032. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1033. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1034. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1035. Spawn* target = lua_interface->GetSpawn(state, 4);
  1036. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1037. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1038. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1039. lua_interface->ResetFunctionStack(state);
  1040. if (caster && caster->IsEntity()) {
  1041. bool success = false;
  1042. luaspell->resisted = false;
  1043. if (target) {
  1044. float distance = caster->GetDistance(target, true);
  1045. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1046. success = true;
  1047. }
  1048. if (luaspell->targets.size() > 0) {
  1049. Spawn* target = 0;
  1050. ZoneServer* zone = luaspell->caster->GetZone();
  1051. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1052. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1053. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1054. float distance = caster->GetDistance(target, true);
  1055. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1056. }
  1057. }
  1058. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1059. success = true;
  1060. }
  1061. if (success) {
  1062. if (caster->GetZone())
  1063. caster->GetZone()->TriggerCharSheetTimer();
  1064. }
  1065. }
  1066. return 0;
  1067. }
  1068. int EQ2Emu_lua_AddItem(lua_State* state) {
  1069. if (!lua_interface)
  1070. return 0;
  1071. Spawn* spawn = lua_interface->GetSpawn(state);
  1072. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1073. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1074. // default of 1 quantity to add
  1075. if (quantity == 0)
  1076. quantity = 1;
  1077. if (spawn && spawn->IsPlayer()) {
  1078. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1079. if (client && item_id > 0) {
  1080. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1081. return 1;
  1082. }
  1083. }
  1084. lua_interface->SetBooleanValue(state, false);
  1085. return 1;
  1086. }
  1087. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1088. if (!lua_interface)
  1089. return 0;
  1090. Spawn* spawn = lua_interface->GetSpawn(state);
  1091. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1092. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1093. string location = lua_interface->GetStringValue(state, 4);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1096. if (client && item_id > 0) {
  1097. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1098. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1099. else
  1100. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1101. if (send_messages) {
  1102. Item* item = master_item_list.GetItem(item_id);
  1103. if (item) {
  1104. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1105. string popup_text = "You receive " + item->name;
  1106. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1107. }
  1108. }
  1109. return 1;
  1110. }
  1111. }
  1112. lua_interface->SetBooleanValue(state, false);
  1113. return 1;
  1114. }
  1115. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1116. Spawn* spawn = lua_interface->GetSpawn(state);
  1117. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1118. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1119. // default of 1 to remove
  1120. if (quantity == 0)
  1121. quantity = 1;
  1122. Client* client;
  1123. Item* item;
  1124. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1125. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1126. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1127. if (client->RemoveItem(item, quantity)) {
  1128. lua_interface->SetBooleanValue(state, true);
  1129. return 1;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. lua_interface->SetBooleanValue(state, false);
  1135. return 1;
  1136. }
  1137. int EQ2Emu_lua_HasItem(lua_State* state) {
  1138. Spawn* player = lua_interface->GetSpawn(state);
  1139. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1140. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1141. if (player && player->IsPlayer()) {
  1142. bool hasItem = false;
  1143. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1144. if (!hasItem)
  1145. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1146. lua_interface->SetBooleanValue(state, hasItem);
  1147. return 1;
  1148. }
  1149. lua_interface->SetBooleanValue(state, false);
  1150. return 1;
  1151. }
  1152. int EQ2Emu_lua_Spawn(lua_State* state) {
  1153. if (!lua_interface)
  1154. return 0;
  1155. ZoneServer* zone = lua_interface->GetZone(state);
  1156. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1157. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1158. float x = lua_interface->GetFloatValue(state, 4);
  1159. float y = lua_interface->GetFloatValue(state, 5);
  1160. float z = lua_interface->GetFloatValue(state, 6);
  1161. float heading = lua_interface->GetFloatValue(state, 7);
  1162. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1163. Spawn* spawn = zone->GetSpawn(spawn_id);
  1164. if (!spawn)
  1165. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1166. else {
  1167. spawn->SetX(x);
  1168. spawn->SetZ(z);
  1169. spawn->SetY(y,true,true);
  1170. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1171. spawn->SetHeading(heading);
  1172. if (restricted_npc)
  1173. spawn->AddAllowAccessSpawn(spawn);
  1174. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1175. bool scriptActive = false;
  1176. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1177. scriptActive = true;
  1178. spawn->SetSpawnScript(string(spawn_script));
  1179. }
  1180. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1181. zone->AddSpawn(spawn);
  1182. if (scriptActive) {
  1183. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1184. }
  1185. lua_interface->SetSpawnValue(state, spawn);
  1186. return 1;
  1187. }
  1188. }
  1189. else {
  1190. string output = "Invalid paramaters to LUA Spawn command: \n";
  1191. if (!zone)
  1192. output = output.append("\t").append("Missing zone reference. \n");
  1193. if (spawn_id == 0)
  1194. output = output.append("\t").append("Missing spawn_id.");
  1195. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1196. }
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. ZoneServer* zone = lua_interface->GetZone(state);
  1203. if (zone) {
  1204. lua_interface->SetStringValue(state, zone->GetZoneName());
  1205. return 1;
  1206. }
  1207. return 0;
  1208. }
  1209. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1210. if (!lua_interface)
  1211. return 0;
  1212. ZoneServer* zone = lua_interface->GetZone(state);
  1213. if (zone) {
  1214. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1215. return 1;
  1216. }
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_GetZone(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. int32 zone_id = lua_interface->GetInt32Value(state);
  1223. ZoneServer* zone = 0;
  1224. if (zone_id > 0)
  1225. zone = zone_list.Get(zone_id);
  1226. else {
  1227. string zone_name = lua_interface->GetStringValue(state);
  1228. if (zone_name.length() > 0) {
  1229. zone = zone_list.Get(zone_name.c_str());
  1230. }
  1231. else {
  1232. Spawn* spawn = lua_interface->GetSpawn(state);
  1233. if (spawn)
  1234. zone = spawn->GetZone();
  1235. }
  1236. }
  1237. if (zone) {
  1238. lua_interface->SetZoneValue(state, zone);
  1239. return 1;
  1240. }
  1241. return 0;
  1242. }
  1243. int EQ2Emu_lua_AddHate(lua_State* state) {
  1244. Spawn* entity = lua_interface->GetSpawn(state);
  1245. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1246. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1247. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if (entity && entity->IsEntity() && amount != 0) {
  1250. if (luaspell) {
  1251. ZoneServer* zone = luaspell->caster->GetZone();
  1252. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1253. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1254. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1255. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1256. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1257. if (send_packet)
  1258. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1259. }
  1260. }
  1261. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1262. }
  1263. else if (npc && npc->IsNPC() && npc->GetZone())
  1264. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_Zone(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. ZoneServer* zone = lua_interface->GetZone(state);
  1272. Spawn* player = lua_interface->GetSpawn(state, 2);
  1273. Client* client = 0;
  1274. if (player && player->IsPlayer())
  1275. client = player->GetZone()->GetClientBySpawn(player);
  1276. float x = lua_interface->GetFloatValue(state, 3);
  1277. float y = lua_interface->GetFloatValue(state, 4);
  1278. float z = lua_interface->GetFloatValue(state, 5);
  1279. float heading = lua_interface->GetFloatValue(state, 6);
  1280. if (zone && client) {
  1281. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1282. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1283. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1284. {
  1285. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1286. return 0;
  1287. }
  1288. if (x != 0 || y != 0 || z != 0) {
  1289. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1290. player->SetX(x);
  1291. player->SetY(y);
  1292. player->SetZ(z);
  1293. player->SetHeading(heading);
  1294. client->Zone(zone->GetZoneName(), false);
  1295. }
  1296. else
  1297. client->Zone(zone->GetZoneName());
  1298. }
  1299. else
  1300. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1301. return 0;
  1302. }
  1303. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1304. if (!lua_interface)
  1305. return 0;
  1306. Spawn* spawn = lua_interface->GetSpawn(state);
  1307. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1308. if (spawn && spawn2)
  1309. spawn->AddAllowAccessSpawn(spawn2);
  1310. return 0;
  1311. }
  1312. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1313. if (!lua_interface)
  1314. return 0;
  1315. Spawn* target = lua_interface->GetSpawn(state);
  1316. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1317. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1318. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1319. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1320. if (!target) {
  1321. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1322. return 0;
  1323. }
  1324. if (!target->IsEntity()) {
  1325. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1326. return 0;
  1327. }
  1328. if (spell_id <= 0) {
  1329. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1330. return 0;
  1331. }
  1332. if (caster && !caster->IsEntity()) {
  1333. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1334. return 0;
  1335. }
  1336. if (spell_tier == 0)
  1337. spell_tier = 1;
  1338. if (!caster)
  1339. caster = target;
  1340. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1341. return 0;
  1342. }
  1343. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1344. if (!lua_interface)
  1345. return 0;
  1346. Spawn* target = lua_interface->GetSpawn(state);
  1347. int32 target_id = 0;
  1348. if (target)
  1349. target_id = target->GetID();
  1350. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1351. if (!luaspell)
  1352. return 0;
  1353. Spawn* caster = luaspell->caster;
  1354. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1355. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1356. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1357. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1358. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1359. //lua_interface->ResetFunctionStack(state);
  1360. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1361. vector<int16> faction_req;
  1362. vector<int16> race_req;
  1363. int32 class_req = 0;
  1364. int32 i = 0;
  1365. int8 f = 0;
  1366. int8 r = 0;
  1367. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1368. if (class_id < 100) {
  1369. class_req += pow(2.0, double(class_id - 1));
  1370. }
  1371. else if (class_id > 100 && class_id < 1000) {
  1372. race_req.push_back(class_id);
  1373. r++;
  1374. }
  1375. else {
  1376. faction_req.push_back(class_id);
  1377. f++;
  1378. }
  1379. i++;
  1380. }
  1381. if (caster && caster->IsEntity()) {
  1382. bool race_match = false;
  1383. bool success = false;
  1384. luaspell->resisted = false;
  1385. if (luaspell->initial_target == target_id) {
  1386. int xxx = 0;
  1387. }
  1388. if (luaspell->targets.size() > 0) {
  1389. ZoneServer* zone = luaspell->caster->GetZone();
  1390. Spawn* target = 0;
  1391. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1392. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1393. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1394. if (race_req.size() > 0) {
  1395. for (int8 i = 0; i < race_req.size(); i++) {
  1396. int32 xxx = target->GetLuaRaceId();
  1397. if (target->GetLuaRaceId() == race_req[i]) {
  1398. race_match = true;
  1399. }
  1400. }
  1401. }
  1402. else
  1403. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1404. if (race_match == true) {
  1405. float distance = caster->GetDistance(target, true);
  1406. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1407. }
  1408. }
  1409. }
  1410. success = true;
  1411. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1412. }
  1413. else if (target) {
  1414. //check class and race/faction here
  1415. if (race_req.size() > 0) {
  1416. for (int8 i = 0; i < race_req.size(); i++) {
  1417. if (target->GetLuaRaceId() == race_req[i]) {
  1418. race_match = true;
  1419. }
  1420. }
  1421. }
  1422. else
  1423. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1424. if (race_match == true) {
  1425. float distance = caster->GetDistance(target, true);
  1426. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1427. success = true;
  1428. }
  1429. }
  1430. if (success) {
  1431. Spell* spell = luaspell->spell;
  1432. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1433. ((Player*)caster)->InCombat(true);
  1434. if (caster->GetZone())
  1435. caster->GetZone()->TriggerCharSheetTimer();
  1436. }
  1437. }
  1438. }
  1439. return 0;
  1440. }
  1441. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1442. if (!lua_interface)
  1443. return 0;
  1444. Spawn* spawn = lua_interface->GetSpawn(state);
  1445. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1446. lua_interface->ResetFunctionStack(state);
  1447. if (spawn && value != 0) {
  1448. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1449. spawn->SetPower(spawn->GetTotalPower());
  1450. else
  1451. spawn->SetPower(spawn->GetPower() + value);
  1452. }
  1453. return 0;
  1454. }
  1455. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. Spawn* spawn = lua_interface->GetSpawn(state);
  1459. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1460. lua_interface->ResetFunctionStack(state);
  1461. if (spawn && value != 0) {
  1462. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1463. spawn->SetHP(spawn->GetTotalHP());
  1464. else
  1465. spawn->SetHP(spawn->GetHP() + value);
  1466. }
  1467. return 0;
  1468. }
  1469. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1470. if (!lua_interface)
  1471. return 0;
  1472. Spawn* spawn = lua_interface->GetSpawn(state);
  1473. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1474. lua_interface->ResetFunctionStack(state);
  1475. if (spawn && value != 0) {
  1476. spawn->SetPower(spawn->GetPower() + value);
  1477. if (value > spawn->GetTotalHPBase())
  1478. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1479. }
  1480. return 0;
  1481. }
  1482. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1483. if (!lua_interface)
  1484. return 0;
  1485. Spawn* spawn = lua_interface->GetSpawn(state);
  1486. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1487. lua_interface->ResetFunctionStack(state);
  1488. if (spawn && value != 0) {
  1489. spawn->SetHP(spawn->GetHP() + value);
  1490. if (value > spawn->GetTotalHPBase())
  1491. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1492. }
  1493. return 0;
  1494. }
  1495. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1496. if (!lua_interface)
  1497. return 0;
  1498. Spawn* spawn = lua_interface->GetSpawn(state);
  1499. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1500. lua_interface->ResetFunctionStack(state);
  1501. if (spawn && value > 0) {
  1502. spawn->SetHP(value);
  1503. if (value > spawn->GetTotalHPBase())
  1504. spawn->SetTotalHP(value);
  1505. }
  1506. return 0;
  1507. }
  1508. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1509. if (!lua_interface)
  1510. return 0;
  1511. Spawn* spawn = lua_interface->GetSpawn(state);
  1512. float value = lua_interface->GetFloatValue(state, 2);
  1513. lua_interface->ResetFunctionStack(state);
  1514. if (spawn && spawn->IsEntity() && value > 0)
  1515. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1516. if (spawn->IsPlayer())
  1517. ((Player*)spawn)->SetCharSheetChanged(true);
  1518. return 0;
  1519. }
  1520. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1521. if (!lua_interface)
  1522. return 0;
  1523. Spawn* spawn = lua_interface->GetSpawn(state);
  1524. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1525. lua_interface->ResetFunctionStack(state);
  1526. if (spawn && spawn->IsEntity() && value > 0)
  1527. ((Entity*)spawn)->SetTotalHPBase(value);
  1528. return 0;
  1529. }
  1530. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1531. if (!lua_interface)
  1532. return 0;
  1533. Spawn* spawn = lua_interface->GetSpawn(state);
  1534. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1535. lua_interface->ResetFunctionStack(state);
  1536. if (spawn && value > 0) {
  1537. spawn->SetPower(value);
  1538. if (value > spawn->GetTotalPowerBase())
  1539. spawn->SetTotalPower(value);
  1540. }
  1541. return 0;
  1542. }
  1543. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1544. if (!lua_interface)
  1545. return 0;
  1546. Spawn* spawn = lua_interface->GetSpawn(state);
  1547. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1548. lua_interface->ResetFunctionStack(state);
  1549. if (spawn && spawn->IsEntity() && value > 0)
  1550. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1551. return 0;
  1552. }
  1553. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1554. if (!lua_interface)
  1555. return 0;
  1556. Spawn* spawn = lua_interface->GetSpawn(state);
  1557. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1558. lua_interface->ResetFunctionStack(state);
  1559. if (spawn && spawn->IsEntity() && value > 0)
  1560. ((Entity*)spawn)->SetTotalPowerBase(value);
  1561. return 0;
  1562. }
  1563. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1564. if (!lua_interface)
  1565. return 0;
  1566. Spawn* spawn = lua_interface->GetSpawn(state);
  1567. float x = lua_interface->GetFloatValue(state, 2);
  1568. float y = lua_interface->GetFloatValue(state, 3);
  1569. float z = lua_interface->GetFloatValue(state, 4);
  1570. float heading = lua_interface->GetFloatValue(state, 5);
  1571. lua_interface->ResetFunctionStack(state);
  1572. if (spawn) {
  1573. spawn->SetX(x);
  1574. spawn->SetY(y);
  1575. spawn->SetZ(z);
  1576. if (heading != 0)
  1577. spawn->SetHeading(heading);
  1578. spawn->SetSpawnOrigX(spawn->GetX());
  1579. spawn->SetSpawnOrigY(spawn->GetY());
  1580. spawn->SetSpawnOrigZ(spawn->GetZ());
  1581. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1582. if (spawn->IsPlayer()) {
  1583. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1584. if (client) {
  1585. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1586. client->QueuePacket(packet);
  1587. }
  1588. }
  1589. }
  1590. return 0;
  1591. }
  1592. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1593. if (!lua_interface)
  1594. return 0;
  1595. Spawn* spawn = lua_interface->GetSpawn(state);
  1596. float value = lua_interface->GetFloatValue(state, 2);
  1597. lua_interface->ResetFunctionStack(state);
  1598. if (spawn) {
  1599. spawn->SetHeading(value);
  1600. if (spawn->IsPlayer()) {
  1601. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1602. if (client) {
  1603. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1604. client->QueuePacket(packet);
  1605. }
  1606. }
  1607. }
  1608. return 0;
  1609. }
  1610. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1611. if (!lua_interface)
  1612. return 0;
  1613. Spawn* spawn = lua_interface->GetSpawn(state);
  1614. int16 value = lua_interface->GetInt16Value(state, 2);
  1615. lua_interface->ResetFunctionStack(state);
  1616. if (spawn)
  1617. spawn->SetModelType(value);
  1618. return 0;
  1619. }
  1620. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1621. if (!lua_interface)
  1622. return 0;
  1623. Spawn* spawn = lua_interface->GetSpawn(state);
  1624. int8 value = lua_interface->GetInt8Value(state, 2);
  1625. lua_interface->ResetFunctionStack(state);
  1626. if (spawn) {
  1627. if (spawn->IsPlayer())
  1628. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1629. else
  1630. spawn->SetAdventureClass(value);
  1631. }
  1632. return 0;
  1633. }
  1634. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1635. if (!lua_interface)
  1636. return 0;
  1637. Spawn* spawn = lua_interface->GetSpawn(state);
  1638. int8 value = lua_interface->GetInt8Value(state, 2);
  1639. lua_interface->ResetFunctionStack(state);
  1640. if (spawn) {
  1641. spawn->SetTradeskillClass(value);
  1642. if (spawn->IsEntity()) {
  1643. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1644. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1645. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1646. }
  1647. if (spawn->IsPlayer())
  1648. ((Player*)spawn)->SetCharSheetChanged(true);
  1649. }
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_SetMount(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* spawn = lua_interface->GetSpawn(state);
  1656. int16 value = lua_interface->GetInt16Value(state, 2);
  1657. if (spawn && spawn->IsEntity()) {
  1658. ((Entity*)spawn)->SetMount(value);
  1659. EQ2_Color color;
  1660. color.red = 255;
  1661. color.green = 255;
  1662. color.blue = 255;
  1663. ((Entity*)spawn)->SetMountColor(&color);
  1664. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1665. }
  1666. return 0;
  1667. }
  1668. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1669. if (!lua_interface)
  1670. return 0;
  1671. Spawn* spawn = lua_interface->GetSpawn(state);
  1672. EQ2_Color mount_color;
  1673. EQ2_Color saddle_color;
  1674. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1675. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1676. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1677. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1678. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1679. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1680. if (spawn && spawn->IsEntity()) {
  1681. ((Entity*)spawn)->SetMountColor(&mount_color);
  1682. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1683. }
  1684. return 0;
  1685. }
  1686. int EQ2Emu_lua_GetMount(lua_State* state) {
  1687. if (!lua_interface)
  1688. return 0;
  1689. Spawn* spawn = lua_interface->GetSpawn(state);
  1690. if (spawn && spawn->IsEntity()) {
  1691. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1692. return 1;
  1693. }
  1694. return 0;
  1695. }
  1696. int EQ2Emu_lua_GetRace(lua_State* state) {
  1697. if (!lua_interface)
  1698. return 0;
  1699. Spawn* spawn = lua_interface->GetSpawn(state);
  1700. if (spawn)
  1701. {
  1702. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1703. lua_interface->SetInt32Value(state, spawn->GetRace());
  1704. return 1;
  1705. }
  1706. return 0;
  1707. }
  1708. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1709. if (!lua_interface)
  1710. return 0;
  1711. Spawn* spawn = lua_interface->GetSpawn(state);
  1712. if (spawn) {
  1713. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1714. return 1;
  1715. }
  1716. return 0;
  1717. }
  1718. int EQ2Emu_lua_GetClass(lua_State* state) {
  1719. Spawn* spawn = lua_interface->GetSpawn(state);
  1720. if (spawn) {
  1721. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1722. return 1;
  1723. }
  1724. return 0;
  1725. }
  1726. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1727. Spawn* spawn = lua_interface->GetSpawn(state);
  1728. if (spawn) {
  1729. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1730. return 1;
  1731. }
  1732. return 0;
  1733. }
  1734. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1735. if (!lua_interface)
  1736. return 0;
  1737. Spawn* spawn = lua_interface->GetSpawn(state);
  1738. float value = lua_interface->GetFloatValue(state, 2);
  1739. lua_interface->ResetFunctionStack(state);
  1740. if (spawn) {
  1741. spawn->SetSpeed(value);
  1742. ((Entity*)spawn)->SetSpeed(value);
  1743. if (spawn->IsPlayer()) {
  1744. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1745. if (client) {
  1746. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1747. if (packet) {
  1748. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1749. packet->setDataByName("speed", value);
  1750. packet->setDataByName("size", 0.51);
  1751. EQ2Packet* app = packet->serialize();
  1752. client->QueuePacket(app);
  1753. safe_delete(packet);
  1754. }
  1755. }
  1756. }
  1757. }
  1758. return 0;
  1759. }
  1760. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1761. if (!lua_interface)
  1762. return 0;
  1763. Spawn* spawn = lua_interface->GetSpawn(state);
  1764. const int16 type = lua_interface->GetInt16Value(state, 2);
  1765. const float value = lua_interface->GetFloatValue(state, 3);
  1766. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1767. int64 class_req = 0;
  1768. int32 class_id = 0;
  1769. vector<int16> faction_req;
  1770. vector<int16> race_req;
  1771. int32 i = 0;
  1772. int8 f = 0;
  1773. int8 r = 0;
  1774. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1775. if (class_id < 100) {
  1776. class_req += pow(2.0, double(class_id - 1));
  1777. }
  1778. else if (class_id > 100 && class_id < 1000) {
  1779. race_req.push_back(class_id);
  1780. r++;
  1781. }
  1782. else {
  1783. faction_req.push_back(class_id);
  1784. f++;
  1785. }
  1786. i++;
  1787. }
  1788. if (value != 0 && type >= 0) {
  1789. if (luaspell && luaspell->spell && luaspell->caster) {
  1790. ZoneServer* zone = luaspell->caster->GetZone();
  1791. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1792. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1793. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1794. if (target) {
  1795. if (target->IsPlayer()) {
  1796. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1797. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1798. if (((Player*)target)->GetGroupMemberInfo())
  1799. ((Player*)target)->UpdateGroupMemberInfo();
  1800. ((Player*)target)->SetCharSheetChanged(true);
  1801. }
  1802. else if (target->IsNPC())
  1803. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1804. else
  1805. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1806. }
  1807. }
  1808. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1809. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1810. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1811. }
  1812. else if (spawn && spawn->IsEntity()) {
  1813. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1814. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1815. if (spawn->IsPlayer())
  1816. ((Player*)spawn)->SetCharSheetChanged(true);
  1817. }
  1818. else
  1819. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1820. }
  1821. else
  1822. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1823. return 0;
  1824. }
  1825. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1826. if (!lua_interface)
  1827. return 0;
  1828. Spawn* spawn = lua_interface->GetSpawn(state);
  1829. int16 type = lua_interface->GetInt16Value(state, 2);
  1830. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1831. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1832. if (!spawn) {
  1833. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1834. return 0;
  1835. }
  1836. if (!spawn->IsEntity()) {
  1837. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1838. return 0;
  1839. }
  1840. if (value == 0) {
  1841. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1842. return 0;
  1843. }
  1844. if (!luaspell || !luaspell->spell) {
  1845. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1846. return 0;
  1847. }
  1848. int32 class_req = 0;
  1849. vector<int16> faction_req;
  1850. vector<int16> race_req;
  1851. int32 class_id = 0;
  1852. int32 i = 0;
  1853. int8 f = 0;
  1854. int8 r = 0;
  1855. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1856. if (class_id < 100) {
  1857. class_req += pow(2.0, double(class_id - 1));
  1858. }
  1859. else if (class_id > 100 && class_id < 1000) {
  1860. race_req.push_back(class_id);
  1861. r++;
  1862. }
  1863. else {
  1864. faction_req.push_back(class_id);
  1865. f++;
  1866. }
  1867. i++;
  1868. }
  1869. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1870. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1871. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1872. if (spawn->IsPlayer())
  1873. ((Player*)spawn)->SetCharSheetChanged(true);
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1881. if (luaspell && luaspell->spell) {
  1882. ZoneServer* zone = luaspell->caster->GetZone();
  1883. Spawn* target = 0;
  1884. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1885. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1886. target = zone->GetSpawnByID(luaspell->targets[i]);
  1887. if (target && target->IsEntity()) {
  1888. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1889. if (target->IsPlayer())
  1890. ((Player*)target)->SetCharSheetChanged(true);
  1891. }
  1892. }
  1893. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1894. }
  1895. else if (spawn && spawn->IsEntity()) {
  1896. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1897. if (spawn->IsPlayer())
  1898. ((Player*)spawn)->SetCharSheetChanged(true);
  1899. }
  1900. return 0;
  1901. }
  1902. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1903. if (!lua_interface)
  1904. return 0;
  1905. Spawn* spawn = lua_interface->GetSpawn(state);
  1906. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1907. float value = lua_interface->GetFloatValue(state, 3);
  1908. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1909. if (value != 0) {
  1910. int32 spell_id = 0;
  1911. if (luaspell && luaspell->spell && luaspell->caster) {
  1912. spell_id = luaspell->spell->GetSpellID();
  1913. ZoneServer* zone = luaspell->caster->GetZone();
  1914. Spawn* target = 0;
  1915. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1916. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1917. target = zone->GetSpawnByID(luaspell->targets[i]);
  1918. if (target && target->Alive()) {
  1919. if (target->IsPlayer()) {
  1920. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1921. Client* client = target->GetZone()->GetClientBySpawn(target);
  1922. if (client) {
  1923. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1924. if (packet)
  1925. client->QueuePacket(packet);
  1926. }
  1927. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1928. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1929. }
  1930. else if (target->IsNPC()) {
  1931. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1932. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1933. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1934. }
  1935. else
  1936. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1937. }
  1938. }
  1939. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1940. }
  1941. else if (spawn) {
  1942. if (spawn->IsPlayer()) {
  1943. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1944. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1945. if (client) {
  1946. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1947. if (packet)
  1948. client->QueuePacket(packet);
  1949. }
  1950. }
  1951. else if (spawn->IsNPC())
  1952. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1953. else
  1954. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1955. }
  1956. }
  1957. else
  1958. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1959. return 0;
  1960. }
  1961. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1962. if (!lua_interface)
  1963. return 0;
  1964. Spawn* spawn = lua_interface->GetSpawn(state);
  1965. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1966. if (spawn && spawn->IsPlayer()) {
  1967. int32 spell_id = 0;
  1968. if (luaspell && luaspell->spell) {
  1969. spell_id = luaspell->spell->GetSpellID();
  1970. ZoneServer* zone = luaspell->caster->GetZone();
  1971. Spawn* target = 0;
  1972. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1973. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1974. target = zone->GetSpawnByID(luaspell->targets[i]);
  1975. if (target) {
  1976. if (target->IsPlayer()) {
  1977. ((Player*)target)->RemoveSkillBonus(spell_id);
  1978. Client* client = target->GetZone()->GetClientBySpawn(target);
  1979. if (client) {
  1980. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1981. if (packet)
  1982. client->QueuePacket(packet);
  1983. }
  1984. }
  1985. else if (target->IsNPC())
  1986. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1987. else
  1988. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1989. }
  1990. }
  1991. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1992. }
  1993. else if (spawn) {
  1994. if (spawn->IsPlayer()) {
  1995. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1996. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1997. if (client) {
  1998. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1999. if (packet)
  2000. client->QueuePacket(packet);
  2001. }
  2002. }
  2003. else if (spawn->IsNPC())
  2004. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2005. else
  2006. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2007. }
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2012. if (!lua_interface)
  2013. return 0;
  2014. Spawn* spawn = lua_interface->GetSpawn(state);
  2015. int8 type = lua_interface->GetInt32Value(state, 2);
  2016. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2017. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2018. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2019. ZoneServer* zone = luaspell->caster->GetZone();
  2020. Spawn* target = 0;
  2021. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2022. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2023. target = zone->GetSpawnByID(luaspell->targets[i]);
  2024. if (target && target->IsEntity()) {
  2025. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2026. ((Entity*)target)->AddMezSpell(luaspell);
  2027. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2028. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2029. if (target->IsNPC())
  2030. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2031. }
  2032. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2033. ((Entity*)target)->AddStifleSpell(luaspell);
  2034. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2035. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2036. if (target->IsNPC())
  2037. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2038. }
  2039. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2040. ((Entity*)target)->AddDazeSpell(luaspell);
  2041. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2042. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2043. if (target->IsNPC())
  2044. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2045. }
  2046. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2047. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2048. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2049. ((Entity*)target)->AddStunSpell(luaspell);
  2050. if (target->IsNPC())
  2051. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2052. }
  2053. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2054. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2055. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2056. ((Entity*)target)->AddRootSpell(luaspell);
  2057. if (target->IsNPC())
  2058. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2059. }
  2060. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2061. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2062. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2063. ((Entity*)target)->AddFearSpell(luaspell);
  2064. if (target->IsNPC())
  2065. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2066. }
  2067. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2068. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2069. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2070. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2071. }
  2072. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2073. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2074. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2075. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2076. }
  2077. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2078. ((Entity*)target)->AddSnareSpell(luaspell);
  2079. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2080. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2081. if (target->IsNPC())
  2082. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2083. }
  2084. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2085. ((Entity*)target)->AddFlightSpell(luaspell);
  2086. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2087. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2088. }
  2089. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2090. ((Entity*)target)->AddGlideSpell(luaspell);
  2091. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2092. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2093. }
  2094. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2095. ((Entity*)target)->AddSafefallSpell(luaspell);
  2096. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2097. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2098. }
  2099. else
  2100. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2101. }
  2102. else
  2103. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2104. }
  2105. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2106. }
  2107. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2108. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2109. ((Entity*)spawn)->AddMezSpell(luaspell);
  2110. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2111. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2112. }
  2113. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2114. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2115. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2116. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2117. }
  2118. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2119. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2120. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2121. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2122. }
  2123. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2124. ((Entity*)spawn)->AddStunSpell(luaspell);
  2125. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2126. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2127. }
  2128. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2129. ((Entity*)spawn)->AddRootSpell(luaspell);
  2130. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2131. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2132. }
  2133. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2134. ((Entity*)spawn)->AddFearSpell(luaspell);
  2135. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2136. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2137. }
  2138. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2139. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2140. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2141. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2142. }
  2143. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2144. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2145. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2146. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2147. }
  2148. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2149. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2150. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2151. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2152. }
  2153. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2154. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2155. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2156. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2157. }
  2158. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2159. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2160. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2161. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2162. }
  2163. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2164. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2165. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2166. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2167. }
  2168. else
  2169. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2170. }
  2171. else
  2172. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2173. return 0;
  2174. }
  2175. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2176. if (!lua_interface)
  2177. return 0;
  2178. Spawn* spawn = lua_interface->GetSpawn(state);
  2179. int8 type = lua_interface->GetInt8Value(state, 2);
  2180. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2181. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2182. if (spawn && spawn->IsEntity()) {
  2183. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2184. ZoneServer* zone = luaspell->caster->GetZone();
  2185. Spawn* target = 0;
  2186. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2187. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2188. target = zone->GetSpawnByID(luaspell->targets[i]);
  2189. if (target) {
  2190. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2191. ((Entity*)target)->RemoveMezSpell(luaspell);
  2192. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2193. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2194. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2195. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2196. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2197. ((Entity*)target)->RemoveStunSpell(luaspell);
  2198. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2199. ((Entity*)target)->RemoveRootSpell(luaspell);
  2200. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2201. ((Entity*)target)->RemoveFearSpell(luaspell);
  2202. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2203. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2204. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2205. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2206. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2207. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2208. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2209. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2210. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2211. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2212. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2213. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2214. else
  2215. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2216. }
  2217. }
  2218. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2219. }
  2220. else if (only_remove_spawn) {
  2221. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2222. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2223. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2224. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2225. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2226. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2227. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2228. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2229. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2230. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2231. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2232. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2233. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2234. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2235. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2236. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2237. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2238. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2239. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2240. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2241. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2242. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2243. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2244. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2245. else
  2246. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2247. }
  2248. }
  2249. return 0;
  2250. }
  2251. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2252. if (!lua_interface)
  2253. return 0;
  2254. Spawn* spawn = lua_interface->GetSpawn(state);
  2255. int8 type = lua_interface->GetInt8Value(state, 2);
  2256. bool hasEffect = false;
  2257. if (!spawn)
  2258. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2259. else if (!spawn->IsEntity())
  2260. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2261. else if (type < CONTROL_MAX_EFFECTS)
  2262. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2263. else
  2264. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2265. lua_interface->SetBooleanValue(state, hasEffect);
  2266. return 1;
  2267. }
  2268. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2269. if (!lua_interface)
  2270. return 0;
  2271. Spawn* spawn = lua_interface->GetSpawn(state);
  2272. float distance = 0.0f;
  2273. if (!spawn)
  2274. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2275. else if (!spawn->IsNPC())
  2276. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2277. else
  2278. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2279. lua_interface->SetFloatValue(state, distance);
  2280. return 1;
  2281. }
  2282. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2283. if (!lua_interface)
  2284. return 0;
  2285. Spawn* spawn = lua_interface->GetSpawn(state);
  2286. float distance = 0.0f;
  2287. if (!spawn)
  2288. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2289. else if (!spawn->IsNPC())
  2290. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2291. else
  2292. distance = ((NPC*)spawn)->GetAggroRadius();
  2293. lua_interface->SetFloatValue(state, distance);
  2294. return 1;
  2295. }
  2296. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2297. if (!lua_interface)
  2298. return 0;
  2299. Spawn* spawn = lua_interface->GetSpawn(state);
  2300. float distance = lua_interface->GetFloatValue(state, 2);
  2301. bool override = lua_interface->GetBooleanValue(state, 3);
  2302. bool result = false;
  2303. lua_interface->ResetFunctionStack(state);
  2304. if (!spawn)
  2305. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2306. else if (!spawn->IsNPC())
  2307. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2308. else
  2309. {
  2310. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2311. result = true;
  2312. }
  2313. lua_interface->SetBooleanValue(state, result);
  2314. return 1;
  2315. }
  2316. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2317. if (!lua_interface)
  2318. return 0;
  2319. Spawn* spawn = lua_interface->GetSpawn(state);
  2320. int16 value = lua_interface->GetInt16Value(state, 2);
  2321. if (spawn && spawn->IsEntity()) {
  2322. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2323. if (spawn->IsPlayer())
  2324. ((Player*)spawn)->SetCharSheetChanged(true);
  2325. }
  2326. return 0;
  2327. }
  2328. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2329. if (!lua_interface)
  2330. return 0;
  2331. Spawn* spawn = lua_interface->GetSpawn(state);
  2332. int16 value = lua_interface->GetInt16Value(state, 2);
  2333. if (spawn && spawn->IsEntity()) {
  2334. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2335. if (spawn->IsPlayer())
  2336. ((Player*)spawn)->SetCharSheetChanged(true);
  2337. }
  2338. return 0;
  2339. }
  2340. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2341. if (!lua_interface)
  2342. return 0;
  2343. Spawn* spawn = lua_interface->GetSpawn(state);
  2344. int16 value = lua_interface->GetInt16Value(state, 2);
  2345. if (spawn && spawn->IsEntity()) {
  2346. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2347. if (spawn->IsPlayer())
  2348. ((Player*)spawn)->SetCharSheetChanged(true);
  2349. }
  2350. return 0;
  2351. }
  2352. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2353. if (!lua_interface)
  2354. return 0;
  2355. Spawn* spawn = lua_interface->GetSpawn(state);
  2356. int16 value = lua_interface->GetInt16Value(state, 2);
  2357. if (spawn && spawn->IsEntity()) {
  2358. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2359. if (spawn->IsPlayer())
  2360. ((Player*)spawn)->SetCharSheetChanged(true);
  2361. }
  2362. return 0;
  2363. }
  2364. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2365. if (!lua_interface)
  2366. return 0;
  2367. Spawn* spawn = lua_interface->GetSpawn(state);
  2368. int16 value = lua_interface->GetInt16Value(state, 2);
  2369. if (spawn && spawn->IsEntity()) {
  2370. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2371. if (spawn->IsPlayer())
  2372. ((Player*)spawn)->SetCharSheetChanged(true);
  2373. }
  2374. return 0;
  2375. }
  2376. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2377. if (!lua_interface)
  2378. return 0;
  2379. Spawn* spawn = lua_interface->GetSpawn(state);
  2380. int8 value = lua_interface->GetInt8Value(state, 2);
  2381. if (spawn && spawn->IsEntity()) {
  2382. ((Entity*)spawn)->SetDeity(value);
  2383. if (spawn->IsPlayer())
  2384. ((Player*)spawn)->SetCharSheetChanged(true);
  2385. }
  2386. lua_interface->ResetFunctionStack(state);
  2387. return 0;
  2388. }
  2389. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2390. if (!lua_interface)
  2391. return 0;
  2392. Spawn* spawn = lua_interface->GetSpawn(state);
  2393. if (spawn && spawn->IsEntity()) {
  2394. int8 deity = ((Entity*)spawn)->GetDeity();
  2395. lua_interface->SetInt32Value(state, deity);
  2396. return 1;
  2397. }
  2398. return 0;
  2399. }
  2400. int EQ2Emu_lua_SetInt(lua_State* state) {
  2401. if (!lua_interface)
  2402. return 0;
  2403. Spawn* spawn = lua_interface->GetSpawn(state);
  2404. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2405. if (spawn && spawn->IsEntity()) {
  2406. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2407. if (spawn->IsPlayer())
  2408. ((Player*)spawn)->SetCharSheetChanged(true);
  2409. }
  2410. return 0;
  2411. }
  2412. int EQ2Emu_lua_SetWis(lua_State* state) {
  2413. if (!lua_interface)
  2414. return 0;
  2415. Spawn* spawn = lua_interface->GetSpawn(state);
  2416. float value = lua_interface->GetFloatValue(state, 2);
  2417. if (spawn && spawn->IsEntity()) {
  2418. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2419. if (spawn->IsPlayer())
  2420. ((Player*)spawn)->SetCharSheetChanged(true);
  2421. }
  2422. return 0;
  2423. }
  2424. int EQ2Emu_lua_SetSta(lua_State* state) {
  2425. if (!lua_interface)
  2426. return 0;
  2427. Spawn* spawn = lua_interface->GetSpawn(state);
  2428. float value = lua_interface->GetFloatValue(state, 2);
  2429. if (spawn && spawn->IsEntity()) {
  2430. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2431. if (spawn->IsPlayer())
  2432. ((Player*)spawn)->SetCharSheetChanged(true);
  2433. }
  2434. return 0;
  2435. }
  2436. int EQ2Emu_lua_SetStr(lua_State* state) {
  2437. if (!lua_interface)
  2438. return 0;
  2439. Spawn* spawn = lua_interface->GetSpawn(state);
  2440. float value = lua_interface->GetFloatValue(state, 2);
  2441. if (spawn && spawn->IsEntity()) {
  2442. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2443. if (spawn->IsPlayer())
  2444. ((Player*)spawn)->SetCharSheetChanged(true);
  2445. }
  2446. return 0;
  2447. }
  2448. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2449. if (!lua_interface)
  2450. return 0;
  2451. Spawn* spawn = lua_interface->GetSpawn(state);
  2452. float value = lua_interface->GetFloatValue(state, 2);
  2453. if (spawn && spawn->IsEntity()) {
  2454. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2455. if (spawn->IsPlayer())
  2456. ((Player*)spawn)->SetCharSheetChanged(true);
  2457. }
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. if (spawn) {
  2465. lua_interface->SetInt32Value(state, spawn->GetHP());
  2466. return 1;
  2467. }
  2468. return 0;
  2469. }
  2470. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2471. if (!lua_interface)
  2472. return 0;
  2473. Spawn* spawn = lua_interface->GetSpawn(state);
  2474. if (spawn) {
  2475. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2476. return 1;
  2477. }
  2478. return 0;
  2479. }
  2480. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2481. if (!lua_interface)
  2482. return 0;
  2483. Spawn* spawn = lua_interface->GetSpawn(state);
  2484. if (spawn) {
  2485. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2486. return 1;
  2487. }
  2488. return 0;
  2489. }
  2490. int EQ2Emu_lua_GetName(lua_State* state) {
  2491. if (!lua_interface)
  2492. return 0;
  2493. Spawn* spawn = lua_interface->GetSpawn(state);
  2494. if (spawn) {
  2495. lua_interface->SetStringValue(state, spawn->GetName());
  2496. return 1;
  2497. }
  2498. return 0;
  2499. }
  2500. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2501. Spawn* spawn = lua_interface->GetSpawn(state);
  2502. if (spawn) {
  2503. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2504. return 1;
  2505. }
  2506. return 0;
  2507. }
  2508. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2509. if (!lua_interface)
  2510. return 0;
  2511. Spawn* spawn = lua_interface->GetSpawn(state);
  2512. if (spawn) {
  2513. lua_interface->SetInt32Value(state, spawn->GetPower());
  2514. return 1;
  2515. }
  2516. return 0;
  2517. }
  2518. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2519. if (!lua_interface)
  2520. return 0;
  2521. Spawn* spawn = lua_interface->GetSpawn(state);
  2522. if (spawn) {
  2523. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2524. return 1;
  2525. }
  2526. return 0;
  2527. }
  2528. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2529. if (!lua_interface)
  2530. return 0;
  2531. Spawn* spawn = lua_interface->GetSpawn(state);
  2532. if (spawn) {
  2533. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2534. return 1;
  2535. }
  2536. return 0;
  2537. }
  2538. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2539. if (!lua_interface)
  2540. return 0;
  2541. Spawn* spawn = lua_interface->GetSpawn(state);
  2542. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2543. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2544. if (spawn && spawn2) {
  2545. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2546. lua_interface->SetFloatValue(state, distance);
  2547. return 1;
  2548. }
  2549. return 0;
  2550. }
  2551. int EQ2Emu_lua_GetX(lua_State* state) {
  2552. if (!lua_interface)
  2553. return 0;
  2554. Spawn* spawn = lua_interface->GetSpawn(state);
  2555. if (spawn) {
  2556. lua_interface->SetFloatValue(state, spawn->GetX());
  2557. return 1;
  2558. }
  2559. return 0;
  2560. }
  2561. int EQ2Emu_lua_GetY(lua_State* state) {
  2562. if (!lua_interface)
  2563. return 0;
  2564. Spawn* spawn = lua_interface->GetSpawn(state);
  2565. if (spawn) {
  2566. lua_interface->SetFloatValue(state, spawn->GetY());
  2567. return 1;
  2568. }
  2569. return 0;
  2570. }
  2571. int EQ2Emu_lua_GetZ(lua_State* state) {
  2572. if (!lua_interface)
  2573. return 0;
  2574. Spawn* spawn = lua_interface->GetSpawn(state);
  2575. if (spawn) {
  2576. lua_interface->SetFloatValue(state, spawn->GetZ());
  2577. return 1;
  2578. }
  2579. return 0;
  2580. }
  2581. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2582. if (!lua_interface)
  2583. return 0;
  2584. Spawn* spawn = lua_interface->GetSpawn(state);
  2585. if (spawn) {
  2586. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2587. return 1;
  2588. }
  2589. return 0;
  2590. }
  2591. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2592. if (!lua_interface)
  2593. return 0;
  2594. Spawn* spawn = lua_interface->GetSpawn(state);
  2595. if (spawn) {
  2596. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2597. return 1;
  2598. }
  2599. return 0;
  2600. }
  2601. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2602. if (!lua_interface)
  2603. return 0;
  2604. Spawn* spawn = lua_interface->GetSpawn(state);
  2605. if (spawn) {
  2606. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2607. return 1;
  2608. }
  2609. return 0;
  2610. }
  2611. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2612. if (!lua_interface)
  2613. return 0;
  2614. Spawn* spawn = lua_interface->GetSpawn(state);
  2615. if (spawn && spawn->IsEntity()) {
  2616. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2617. return 1;
  2618. }
  2619. return 0;
  2620. }
  2621. int EQ2Emu_lua_GetInt(lua_State* state) {
  2622. if (!lua_interface)
  2623. return 0;
  2624. Spawn* spawn = lua_interface->GetSpawn(state);
  2625. if (spawn && spawn->IsEntity()) {
  2626. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2627. return 1;
  2628. }
  2629. return 0;
  2630. }
  2631. int EQ2Emu_lua_GetWis(lua_State* state) {
  2632. if (!lua_interface)
  2633. return 0;
  2634. Spawn* spawn = lua_interface->GetSpawn(state);
  2635. if (spawn && spawn->IsEntity()) {
  2636. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2637. return 1;
  2638. }
  2639. return 0;
  2640. }
  2641. int EQ2Emu_lua_GetSta(lua_State* state) {
  2642. if (!lua_interface)
  2643. return 0;
  2644. Spawn* spawn = lua_interface->GetSpawn(state);
  2645. if (spawn && spawn->IsEntity()) {
  2646. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2647. return 1;
  2648. }
  2649. return 0;
  2650. }
  2651. int EQ2Emu_lua_GetStr(lua_State* state) {
  2652. if (!lua_interface)
  2653. return 0;
  2654. Spawn* spawn = lua_interface->GetSpawn(state);
  2655. if (spawn && spawn->IsEntity()) {
  2656. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2657. return 1;
  2658. }
  2659. return 0;
  2660. }
  2661. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2662. if (!lua_interface)
  2663. return 0;
  2664. Spawn* spawn = lua_interface->GetSpawn(state);
  2665. if (spawn && spawn->IsEntity()) {
  2666. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2667. return 1;
  2668. }
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Spawn* spawn = lua_interface->GetSpawn(state);
  2675. if (spawn && spawn->IsEntity()) {
  2676. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2677. return 1;
  2678. }
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* spawn = lua_interface->GetSpawn(state);
  2685. if (spawn && spawn->IsEntity()) {
  2686. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2687. return 1;
  2688. }
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Spawn* spawn = lua_interface->GetSpawn(state);
  2695. if (spawn && spawn->IsEntity()) {
  2696. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2697. return 1;
  2698. }
  2699. return 0;
  2700. }
  2701. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2702. if (!lua_interface)
  2703. return 0;
  2704. Spawn* spawn = lua_interface->GetSpawn(state);
  2705. if (spawn && spawn->IsEntity()) {
  2706. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2707. return 1;
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Spawn* spawn = lua_interface->GetSpawn(state);
  2715. if (spawn && spawn->IsEntity()) {
  2716. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2717. return 1;
  2718. }
  2719. return 0;
  2720. }
  2721. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2722. if (!lua_interface)
  2723. return 0;
  2724. Spawn* player = lua_interface->GetSpawn(state);
  2725. if (!player || !player->IsPlayer()) {
  2726. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2727. return 0;
  2728. }
  2729. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2730. if (quest_id <= 0) {
  2731. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2732. return 0;
  2733. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2734. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2735. return 0;
  2736. }
  2737. int32 step = lua_interface->GetInt32Value(state, 3);
  2738. if (step > 0) {
  2739. Client* client = player->GetZone()->GetClientBySpawn(player);
  2740. if (client)
  2741. client->AddPendingQuestUpdate(quest_id, step);
  2742. } else {
  2743. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2748. Spawn* player = lua_interface->GetSpawn(state);
  2749. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2750. int32 step = lua_interface->GetInt32Value(state, 3);
  2751. int32 progress = lua_interface->GetInt32Value(state, 4);
  2752. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2753. Client* client = player->GetZone()->GetClientBySpawn(player);
  2754. if (client)
  2755. client->AddPendingQuestUpdate(quest_id, step, progress);
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* player = lua_interface->GetSpawn(state);
  2763. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2764. if (player && player->IsPlayer() && quest_id > 0) {
  2765. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2766. return 1;
  2767. }
  2768. return 0;
  2769. }
  2770. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2771. if (!lua_interface)
  2772. return 0;
  2773. Spawn* player = lua_interface->GetSpawn(state);
  2774. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2775. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2776. if (player && player->IsPlayer() && quest_id > 0) {
  2777. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2778. return 1;
  2779. }
  2780. return 0;
  2781. }
  2782. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2783. if (!lua_interface)
  2784. return 0;
  2785. Spawn* player = lua_interface->GetSpawn(state);
  2786. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2787. if (player && player->IsPlayer() && quest_id > 0) {
  2788. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2789. return 1;
  2790. }
  2791. return 0;
  2792. }
  2793. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2794. if (!lua_interface)
  2795. return 0;
  2796. Quest* quest = lua_interface->GetQuest(state);
  2797. string name = lua_interface->GetStringValue(state, 2);
  2798. string type = lua_interface->GetStringValue(state, 3);
  2799. string zone = lua_interface->GetStringValue(state, 4);
  2800. int16 level = lua_interface->GetInt16Value(state, 5);
  2801. string description = lua_interface->GetStringValue(state, 6);
  2802. bool load = true;
  2803. if (!quest) {
  2804. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2805. load = false;
  2806. }
  2807. if (load && name.length() == 0) {
  2808. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2809. load = false;
  2810. }
  2811. if (load && type.length() == 0) {
  2812. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2813. load = false;
  2814. }
  2815. if (load && zone.length() == 0) {
  2816. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2817. load = false;
  2818. }
  2819. if (load && description.length() == 0) {
  2820. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2821. load = false;
  2822. }
  2823. if (load && level == 0) {
  2824. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2825. load = false;
  2826. }
  2827. if (load)
  2828. quest->RegisterQuest(name, type, zone, level, description);
  2829. return 0;
  2830. }
  2831. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2832. if (!lua_interface)
  2833. return 0;
  2834. Quest* quest = lua_interface->GetQuest(state);
  2835. if (quest) {
  2836. int8 level = lua_interface->GetInt16Value(state, 2);
  2837. quest->SetPrereqLevel(level);
  2838. }
  2839. return 0;
  2840. }
  2841. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2842. if (!lua_interface)
  2843. return 0;
  2844. Quest* quest = lua_interface->GetQuest(state);
  2845. if (quest) {
  2846. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2847. quest->AddPrereqQuest(quest_id);
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2852. if (!lua_interface)
  2853. return 0;
  2854. Quest* quest = lua_interface->GetQuest(state);
  2855. if (quest) {
  2856. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2857. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2858. if (quantity == 0)
  2859. quantity = 1;
  2860. Item* master_item = master_item_list.GetItem(item_id);
  2861. if (master_item) {
  2862. Item* item = new Item(master_item);
  2863. item->details.count = quantity;
  2864. quest->AddPrereqItem(item);
  2865. }
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* player = lua_interface->GetSpawn(state);
  2873. if(!player || !player->IsPlayer()) {
  2874. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2875. return 0;
  2876. }
  2877. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2878. if (quest_id > 0) {
  2879. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2880. return 1;
  2881. } else {
  2882. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2883. }
  2884. return 0;
  2885. }
  2886. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2887. if (!lua_interface)
  2888. return 0;
  2889. Quest* quest = lua_interface->GetQuest(state);
  2890. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2891. if (quest && spawn_id > 0)
  2892. quest->SetQuestReturnNPC(spawn_id);
  2893. return 0;
  2894. }
  2895. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2896. if (!lua_interface)
  2897. return 0;
  2898. Spawn* spawn = lua_interface->GetSpawn(state);
  2899. if (!spawn) {
  2900. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2901. return 0;
  2902. }
  2903. int32 time = lua_interface->GetInt32Value(state, 2);
  2904. if (time <= 0) {
  2905. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2906. return 0;
  2907. }
  2908. string function = lua_interface->GetStringValue(state, 3);
  2909. if (function.length() == 0) {
  2910. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2911. return 0;
  2912. }
  2913. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2914. Spawn* player = lua_interface->GetSpawn(state, 5);
  2915. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2916. timer->timer = Timer::GetCurrentTime2() + time;
  2917. timer->function = function;
  2918. timer->spawn = spawn->GetID();
  2919. timer->player = player ? player->GetID() : 0;
  2920. if (max_count == 0)
  2921. max_count = 1;
  2922. timer->max_count = max_count;
  2923. timer->current_count = 0;
  2924. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2925. return 0;
  2926. }
  2927. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2928. if (!lua_interface)
  2929. return 0;
  2930. Spawn* player = lua_interface->GetSpawn(state);
  2931. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2932. if (player && player->IsPlayer() && quest_id > 0) {
  2933. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2934. return 1;
  2935. }
  2936. return 0;
  2937. }
  2938. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2939. if (!lua_interface)
  2940. return 0;
  2941. Spawn* player = lua_interface->GetSpawn(state);
  2942. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2943. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2944. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2945. if (quest)
  2946. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2947. return 1;
  2948. }
  2949. return 0;
  2950. }
  2951. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2952. if (!lua_interface)
  2953. return 0;
  2954. Spawn* player = lua_interface->GetSpawn(state);
  2955. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2956. if (player && player->IsPlayer() && quest_id > 0) {
  2957. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* npc = lua_interface->GetSpawn(state);
  2966. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2967. if (npc && !npc->IsPlayer() && quest_id > 0)
  2968. npc->AddProvidedQuest(quest_id);
  2969. return 0;
  2970. }
  2971. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2972. if (!lua_interface)
  2973. return 0;
  2974. Spawn* npc = lua_interface->GetSpawn(state);
  2975. Spawn* player = lua_interface->GetSpawn(state, 2);
  2976. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2977. bool forced = lua_interface->GetBooleanValue(state, 4);
  2978. /* NPC is allowed to be null */
  2979. if (player && player->IsPlayer() && quest_id > 0) {
  2980. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2981. if (master_quest) {
  2982. Client* client = player->GetZone()->GetClientBySpawn(player);
  2983. if (!client) {
  2984. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  2985. }
  2986. Quest* quest = new Quest(master_quest);
  2987. if (!quest) {
  2988. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  2989. }
  2990. if (client && quest) {
  2991. if (npc)
  2992. quest->SetQuestGiver(npc->GetDatabaseID());
  2993. else
  2994. quest->SetQuestGiver(0);
  2995. client->AddPendingQuest(quest, forced);
  2996. }
  2997. }
  2998. else {
  2999. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3000. }
  3001. }
  3002. else {
  3003. 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);
  3004. }
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Quest* quest = lua_interface->GetQuest(state);
  3011. if (quest) {
  3012. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3013. quest->AddPrereqClass(class_id);
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Quest* quest = lua_interface->GetQuest(state);
  3021. if (quest) {
  3022. int8 race = lua_interface->GetInt8Value(state, 2);
  3023. quest->AddPrereqRace(race);
  3024. }
  3025. return 0;
  3026. }
  3027. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3028. if (!lua_interface)
  3029. return 0;
  3030. Quest* quest = lua_interface->GetQuest(state);
  3031. if (quest) {
  3032. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3033. quest->AddPrereqModelType(model_type);
  3034. }
  3035. return 0;
  3036. }
  3037. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3038. if (!lua_interface)
  3039. return 0;
  3040. Quest* quest = lua_interface->GetQuest(state);
  3041. if (!quest) {
  3042. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3043. return 0;
  3044. }
  3045. int8 level = lua_interface->GetInt8Value(state, 2);
  3046. quest->SetPrereqTSLevel(level);
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3050. if (!lua_interface)
  3051. return 0;
  3052. Quest* quest = lua_interface->GetQuest(state);
  3053. if (!quest) {
  3054. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3055. return 0;
  3056. }
  3057. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3058. quest->AddPrereqTradeskillClass(class_id);
  3059. return 0;
  3060. }
  3061. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3062. if (!lua_interface)
  3063. return 0;
  3064. Quest* quest = lua_interface->GetQuest(state);
  3065. if (quest) {
  3066. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3067. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3068. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3069. quest->AddPrereqFaction(faction_id, min, max);
  3070. }
  3071. return 0;
  3072. }
  3073. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3074. if (!lua_interface)
  3075. return 0;
  3076. Quest* quest = lua_interface->GetQuest(state);
  3077. if (quest) {
  3078. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3079. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3080. if (quantity == 0)
  3081. quantity = 1;
  3082. Item* master_item = master_item_list.GetItem(item_id);
  3083. if (master_item) {
  3084. Item* item = new Item(master_item);
  3085. item->details.count = quantity;
  3086. quest->AddSelectableRewardItem(item);
  3087. }
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Quest* quest = lua_interface->GetQuest(state);
  3095. if (quest) {
  3096. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3097. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3098. if (quantity == 0)
  3099. quantity = 1;
  3100. Item* master_item = master_item_list.GetItem(item_id);
  3101. if (master_item) {
  3102. Item* item = new Item(master_item);
  3103. item->details.count = quantity;
  3104. quest->AddRewardItem(item);
  3105. }
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Quest* quest = lua_interface->GetQuest(state);
  3113. if (quest) {
  3114. int32 copper = lua_interface->GetInt32Value(state, 2);
  3115. int32 silver = lua_interface->GetInt32Value(state, 3);
  3116. int32 gold = lua_interface->GetInt32Value(state, 4);
  3117. int32 plat = lua_interface->GetInt32Value(state, 5);
  3118. quest->AddRewardCoins(copper, silver, gold, plat);
  3119. }
  3120. return 0;
  3121. }
  3122. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3123. if (!lua_interface)
  3124. return 0;
  3125. Quest* quest = lua_interface->GetQuest(state);
  3126. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3127. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3128. if (quest && faction_id > 0 && amount != 0)
  3129. quest->AddRewardFaction(faction_id, amount);
  3130. return 0;
  3131. }
  3132. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3133. if (!lua_interface)
  3134. return 0;
  3135. Quest* quest = lua_interface->GetQuest(state);
  3136. if (quest) {
  3137. int32 status = lua_interface->GetInt32Value(state, 2);
  3138. quest->SetRewardStatus(status);
  3139. }
  3140. return 0;
  3141. }
  3142. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3143. if (!lua_interface)
  3144. return 0;
  3145. Quest* quest = lua_interface->GetQuest(state);
  3146. if (quest) {
  3147. string comment = lua_interface->GetStringValue(state, 2);
  3148. quest->SetRewardComment(comment);
  3149. }
  3150. return 0;
  3151. }
  3152. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3153. if (!lua_interface)
  3154. return 0;
  3155. Quest* quest = lua_interface->GetQuest(state);
  3156. if (quest) {
  3157. int32 exp = lua_interface->GetInt32Value(state, 2);
  3158. quest->SetRewardXP(exp);
  3159. }
  3160. return 0;
  3161. }
  3162. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3163. Quest* quest = lua_interface->GetQuest(state);
  3164. if (quest) {
  3165. int32 step = lua_interface->GetInt32Value(state, 2);
  3166. string description = lua_interface->GetStringValue(state, 3);
  3167. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3168. float percentage = lua_interface->GetFloatValue(state, 5);
  3169. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3170. int16 icon = lua_interface->GetInt16Value(state, 7);
  3171. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3172. const char* taskgroup = 0;
  3173. if (str_taskgroup.length() > 0)
  3174. taskgroup = str_taskgroup.c_str();
  3175. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3176. if (quest_step && icon && quantity > 0)
  3177. quest_step->SetIcon(icon);
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Quest* quest = lua_interface->GetQuest(state);
  3185. if (quest) {
  3186. int32 step = lua_interface->GetInt32Value(state, 2);
  3187. string description = lua_interface->GetStringValue(state, 3);
  3188. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3189. float percentage = lua_interface->GetFloatValue(state, 5);
  3190. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3191. int16 icon = lua_interface->GetInt16Value(state, 7);
  3192. const char* taskgroup = 0;
  3193. if (str_taskgroup.length() > 0)
  3194. taskgroup = str_taskgroup.c_str();
  3195. int32 npc_id = 0;
  3196. vector<int32>* ids = 0;
  3197. Spawn* spawn = nullptr;
  3198. int i = 0;
  3199. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3200. if (ids == 0)
  3201. ids = new vector<int32>;
  3202. ids->push_back(npc_id);
  3203. i++;
  3204. }
  3205. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3206. if (quest_step && icon > 0 && quantity > 0)
  3207. quest_step->SetIcon(icon);
  3208. if (quest->GetPlayer()) {
  3209. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3210. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3211. }
  3212. }
  3213. return 0;
  3214. }
  3215. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3216. if (!lua_interface)
  3217. return 0;
  3218. Quest* quest = lua_interface->GetQuest(state);
  3219. if (quest) {
  3220. int32 step = lua_interface->GetInt32Value(state, 2);
  3221. string description = lua_interface->GetStringValue(state, 3);
  3222. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3223. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3224. int16 icon = lua_interface->GetInt16Value(state, 6);
  3225. const char* taskgroup = 0;
  3226. if (str_taskgroup.length() > 0)
  3227. taskgroup = str_taskgroup.c_str();
  3228. int32 npc_id = 0;
  3229. vector<int32>* ids = 0;
  3230. int i = 0;
  3231. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3232. if (ids == 0)
  3233. ids = new vector<int32>;
  3234. ids->push_back(npc_id);
  3235. i++;
  3236. }
  3237. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3238. if (quest_step && icon > 0)
  3239. quest_step->SetIcon(icon);
  3240. if (quest->GetPlayer()) {
  3241. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3242. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3243. }
  3244. }
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Quest* quest = lua_interface->GetQuest(state);
  3251. if (quest) {
  3252. int32 step = lua_interface->GetInt32Value(state, 2);
  3253. string description = lua_interface->GetStringValue(state, 3);
  3254. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3255. float percentage = lua_interface->GetFloatValue(state, 5);
  3256. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3257. int16 icon = lua_interface->GetInt16Value(state, 7);
  3258. const char* taskgroup = 0;
  3259. if (str_taskgroup.length() > 0)
  3260. taskgroup = str_taskgroup.c_str();
  3261. int32 item_id = 0;
  3262. vector<int32>* ids = 0;
  3263. int i = 0;
  3264. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3265. if (ids == 0)
  3266. ids = new vector<int32>;
  3267. ids->push_back(item_id);
  3268. i++;
  3269. }
  3270. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3271. if (quest_step && icon > 0 && quantity > 0)
  3272. quest_step->SetIcon(icon);
  3273. if (quest->GetPlayer()) {
  3274. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3275. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3276. }
  3277. }
  3278. return 0;
  3279. }
  3280. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3281. if (!lua_interface)
  3282. return 0;
  3283. Quest* quest = lua_interface->GetQuest(state);
  3284. if (quest) {
  3285. int32 step = lua_interface->GetInt32Value(state, 2);
  3286. string description = lua_interface->GetStringValue(state, 3);
  3287. float max_variation = lua_interface->GetFloatValue(state, 4);
  3288. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3289. int16 icon = lua_interface->GetInt16Value(state, 6);
  3290. const char* taskgroup = 0;
  3291. if (str_taskgroup.length() > 0)
  3292. taskgroup = str_taskgroup.c_str();
  3293. vector<Location>* locations = 0;
  3294. int i = 7;
  3295. while (true) {
  3296. Location loc;
  3297. loc.x = lua_interface->GetFloatValue(state, i);
  3298. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3299. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3300. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3301. break;
  3302. if (locations == 0)
  3303. locations = new vector<Location>;
  3304. locations->push_back(loc);
  3305. i += 3;
  3306. }
  3307. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3308. if (quest_step && icon > 0)
  3309. quest_step->SetIcon(icon);
  3310. if (quest->GetPlayer()) {
  3311. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3312. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3313. }
  3314. }
  3315. return 0;
  3316. }
  3317. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3318. if (!lua_interface)
  3319. return 0;
  3320. Quest* quest = lua_interface->GetQuest(state);
  3321. if (quest) {
  3322. int32 step = lua_interface->GetInt32Value(state, 2);
  3323. string description = lua_interface->GetStringValue(state, 3);
  3324. float max_variation = lua_interface->GetFloatValue(state, 4);
  3325. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3326. int16 icon = lua_interface->GetInt16Value(state, 6);
  3327. const char* taskgroup = 0;
  3328. if (str_taskgroup.length() > 0)
  3329. taskgroup = str_taskgroup.c_str();
  3330. vector<Location>* locations = 0;
  3331. int i = 7;
  3332. while (true) {
  3333. Location loc;
  3334. loc.x = lua_interface->GetFloatValue(state, i);
  3335. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3336. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3337. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3338. break;
  3339. if (locations == 0)
  3340. locations = new vector<Location>;
  3341. locations->push_back(loc);
  3342. i += 3;
  3343. }
  3344. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3345. if (quest_step && icon > 0)
  3346. quest_step->SetIcon(icon);
  3347. if (quest->GetPlayer()) {
  3348. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3349. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3350. }
  3351. }
  3352. return 0;
  3353. }
  3354. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3355. Quest* quest = lua_interface->GetQuest(state);
  3356. if (quest) {
  3357. int32 step = lua_interface->GetInt32Value(state, 2);
  3358. string description = lua_interface->GetStringValue(state, 3);
  3359. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3360. float percentage = lua_interface->GetFloatValue(state, 5);
  3361. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3362. int16 icon = lua_interface->GetInt16Value(state, 7);
  3363. const char* taskgroup = 0;
  3364. if (str_taskgroup.length() > 0)
  3365. taskgroup = str_taskgroup.c_str();
  3366. int32 spell_id = 0;
  3367. vector<int32>* ids = 0;
  3368. int i = 0;
  3369. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3370. if (ids == 0)
  3371. ids = new vector<int32>;
  3372. ids->push_back(spell_id);
  3373. i++;
  3374. }
  3375. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3376. if (quest_step && icon > 0 && quantity > 0)
  3377. quest_step->SetIcon(icon);
  3378. if (quest->GetPlayer()) {
  3379. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3380. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3381. }
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Quest* quest = lua_interface->GetQuest(state);
  3389. if (quest) {
  3390. int32 step = lua_interface->GetInt32Value(state, 2);
  3391. string description = lua_interface->GetStringValue(state, 3);
  3392. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3393. float percentage = lua_interface->GetFloatValue(state, 5);
  3394. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3395. int16 icon = lua_interface->GetInt16Value(state, 7);
  3396. const char* taskgroup = 0;
  3397. if (str_taskgroup.length() > 0)
  3398. taskgroup = str_taskgroup.c_str();
  3399. int32 item_id = 0;
  3400. vector<int32>* ids = 0;
  3401. int i = 0;
  3402. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3403. if (ids == 0)
  3404. ids = new vector<int32>;
  3405. ids->push_back(item_id);
  3406. i++;
  3407. }
  3408. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3409. if (quest_step && icon > 0 && quantity > 0)
  3410. quest_step->SetIcon(icon);
  3411. if (quest->GetPlayer()) {
  3412. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3413. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3414. }
  3415. }
  3416. return 0;
  3417. }
  3418. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3419. if (!lua_interface)
  3420. return 0;
  3421. Quest* quest = lua_interface->GetQuest(state);
  3422. if (quest) {
  3423. int32 step = lua_interface->GetInt32Value(state, 2);
  3424. string description = lua_interface->GetStringValue(state, 3);
  3425. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3426. float percentage = lua_interface->GetFloatValue(state, 5);
  3427. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3428. int16 icon = lua_interface->GetInt16Value(state, 7);
  3429. const char* taskgroup = 0;
  3430. if (str_taskgroup.length() > 0)
  3431. taskgroup = str_taskgroup.c_str();
  3432. int32 item_id = 0;
  3433. vector<int32>* ids = 0;
  3434. int i = 0;
  3435. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3436. if (ids == 0)
  3437. ids = new vector<int32>;
  3438. ids->push_back(item_id);
  3439. i++;
  3440. }
  3441. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3442. if (quest_step && icon > 0 && quantity > 0)
  3443. quest_step->SetIcon(icon);
  3444. if (quest->GetPlayer()) {
  3445. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3446. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3447. }
  3448. }
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Quest* quest = lua_interface->GetQuest(state);
  3455. if (quest) {
  3456. string action = lua_interface->GetStringValue(state, 2);
  3457. if (action.length() > 0)
  3458. quest->SetCompleteAction(action);
  3459. }
  3460. return 0;
  3461. }
  3462. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3463. if (!lua_interface)
  3464. return 0;
  3465. Quest* quest = lua_interface->GetQuest(state);
  3466. if (quest) {
  3467. int32 step = lua_interface->GetInt32Value(state, 2);
  3468. string action = lua_interface->GetStringValue(state, 3);
  3469. if (step > 0 && action.length() > 0)
  3470. quest->AddCompleteAction(step, action);
  3471. }
  3472. return 0;
  3473. }
  3474. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Quest* quest = lua_interface->GetQuest(state);
  3478. if (quest) {
  3479. int32 step = lua_interface->GetInt32Value(state, 2);
  3480. string action = lua_interface->GetStringValue(state, 3);
  3481. if (step > 0 && action.length() > 0)
  3482. quest->AddProgressAction(step, action);
  3483. }
  3484. return 0;
  3485. }
  3486. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3487. if (!lua_interface)
  3488. return 0;
  3489. Quest* quest = lua_interface->GetQuest(state);
  3490. string description = lua_interface->GetStringValue(state, 2);
  3491. if (quest && description.length() > 0)
  3492. quest->SetDescription(description);
  3493. return 0;
  3494. }
  3495. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. string description = lua_interface->GetStringValue(state, 2);
  3500. if (quest && description.length() > 0)
  3501. quest->SetCompletedDescription(description);
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Quest* quest = lua_interface->GetQuest(state);
  3508. int32 step = lua_interface->GetInt32Value(state, 2);
  3509. string description = lua_interface->GetStringValue(state, 3);
  3510. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3511. if (quest && step > 0 && description.length() > 0) {
  3512. quest->SetTaskGroupDescription(step, description, display_bullets);
  3513. if (quest->GetPlayer()) {
  3514. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3515. if (client)
  3516. client->SendQuestUpdateStep(quest, step, false);
  3517. }
  3518. }
  3519. return 0;
  3520. }
  3521. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3522. if (!lua_interface)
  3523. return 0;
  3524. Quest* quest = lua_interface->GetQuest(state);
  3525. int32 step = lua_interface->GetInt32Value(state, 2);
  3526. string description = lua_interface->GetStringValue(state, 3);
  3527. if (quest && step > 0 && description.length() > 0) {
  3528. quest->SetStepDescription(step, description);
  3529. if (quest->GetPlayer()) {
  3530. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3531. if (client)
  3532. client->SendQuestUpdateStepImmediately(quest, step);
  3533. }
  3534. }
  3535. return 0;
  3536. }
  3537. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3538. Quest* quest = lua_interface->GetQuest(state);
  3539. string zone = lua_interface->GetStringValue(state, 2);
  3540. if (quest && zone.length() > 0)
  3541. quest->SetZone(zone);
  3542. return 0;
  3543. }
  3544. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3545. if (!lua_interface)
  3546. return 0;
  3547. Quest* quest = lua_interface->GetQuest(state);
  3548. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3549. int32 coin = lua_interface->GetInt32Value(state, 3);
  3550. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3551. string rewards_str = lua_interface->GetStringValue(state, 5);
  3552. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3553. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3554. string text = lua_interface->GetStringValue(state, 8);
  3555. int32 source_id = 0;
  3556. if (quest)
  3557. source_id = quest->GetQuestID();
  3558. if (playerSpawn && playerSpawn->IsPlayer()) {
  3559. Player* player = (Player*)playerSpawn;
  3560. Client* client = player->GetZone()->GetClientBySpawn(player);
  3561. if (client) {
  3562. vector<Item*> reward_items;
  3563. vector<Item*> selectable_reward_items;
  3564. if (rewards_str.length() > 0) {
  3565. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3566. map<unsigned int, unsigned short>::iterator itr;
  3567. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3568. if (itr->first > 0) {
  3569. Item* item = new Item(master_item_list.GetItem(itr->first));
  3570. if (item) {
  3571. if (itr->second > 0)
  3572. item->stack_count = itr->second;
  3573. reward_items.push_back(item);
  3574. }
  3575. }
  3576. }
  3577. }
  3578. if (select_rewards_str.length() > 0) {
  3579. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3580. map<unsigned int, unsigned short>::iterator itr;
  3581. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3582. if (itr->first > 0) {
  3583. Item* item = new Item(master_item_list.GetItem(itr->first));
  3584. if (item) {
  3585. if (itr->second > 0)
  3586. item->stack_count = itr->second;
  3587. selectable_reward_items.push_back(item);
  3588. }
  3589. }
  3590. }
  3591. }
  3592. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3593. const char* reward_type = "Quest Reward!";
  3594. if (!quest)
  3595. reward_type = "Reward!";
  3596. client->DisplayQuestRewards(0, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3597. }
  3598. }
  3599. /*PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", client->GetVersion());
  3600. if (packet2) {
  3601. player->AddCoins(coin);
  3602. client->PlaySound("coin_cha_ching");
  3603. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  3604. if(quest)
  3605. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  3606. else
  3607. packet2->setSubstructDataByName("reward_data", "reward", "Reward!");
  3608. packet2->setSubstructDataByName("reward_data", "coin", coin);
  3609. if (player->GetGuild()) {
  3610. player->GetInfoStruct()->status_points += status_points;
  3611. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  3612. }
  3613. if (rewards_str.length() > 0) {
  3614. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3615. vector<Item*> reward_items;
  3616. map<unsigned int, unsigned short>::iterator itr;
  3617. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3618. if (itr->first > 0) {
  3619. Item* item = new Item(master_item_list.GetItem(itr->first));
  3620. if (item) {
  3621. if (itr->second > 0)
  3622. item->stack_count = itr->second;
  3623. reward_items.push_back(item);
  3624. }
  3625. }
  3626. }
  3627. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", reward_items.size());
  3628. for (int i = 0; i < reward_items.size(); i++) {
  3629. Item* item = reward_items[i];
  3630. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  3631. packet2->setItemArrayDataByName("item", item, client->GetPlayer(), i, 0, -1);
  3632. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  3633. }
  3634. }
  3635. if (select_rewards_str.length() > 0) {
  3636. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3637. vector<Item*> reward_items;
  3638. map<unsigned int, unsigned short>::iterator itr;
  3639. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3640. if (itr->first > 0) {
  3641. Item* item = new Item(master_item_list.GetItem(itr->first));
  3642. if (item) {
  3643. if (itr->second > 0)
  3644. item->stack_count = itr->second;
  3645. reward_items.push_back(item);
  3646. }
  3647. }
  3648. }
  3649. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", reward_items.size());
  3650. for (int i = 0; i < reward_items.size(); i++) {
  3651. Item* item = reward_items[i];
  3652. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  3653. packet2->setItemArrayDataByName("select_item", item, client->GetPlayer(), i, 0, -1);
  3654. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  3655. }
  3656. }
  3657. if (factions_map_str.length() > 0) {
  3658. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3659. map<unsigned int, signed int>::iterator itr;
  3660. map<Faction*, signed int> factions;
  3661. for (itr = faction_rewards.begin(); itr != faction_rewards.end(); itr++) {
  3662. Faction* faction = master_faction_list.GetFaction(itr->first);
  3663. if (faction)
  3664. factions[faction] = itr->second;
  3665. }
  3666. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions.size());
  3667. map<Faction*, signed int>::iterator faction_itr;
  3668. int8 i = 0;
  3669. for (faction_itr = factions.begin(); faction_itr != factions.end(); faction_itr++) {
  3670. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  3671. sint32 amount = faction_itr->second;
  3672. packet2->setArrayDataByName("amount", amount, i);
  3673. if (amount > 0)
  3674. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  3675. else
  3676. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  3677. i++;
  3678. }
  3679. }
  3680. client->QueuePacket(packet2->serialize());
  3681. safe_delete(packet2);
  3682. }*/
  3683. return 0;
  3684. }
  3685. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3686. if (!lua_interface)
  3687. return 0;
  3688. Quest* quest = lua_interface->GetQuest(state);
  3689. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3690. if (quest && spawn) {
  3691. if (spawn->IsPlayer()) {
  3692. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3693. if (client)
  3694. client->AddPendingQuestReward(quest);
  3695. }
  3696. }
  3697. return 0;
  3698. }
  3699. int EQ2Emu_lua_Harvest(lua_State* state) {
  3700. if (!lua_interface)
  3701. return 0;
  3702. Spawn* player = lua_interface->GetSpawn(state);
  3703. Spawn* node = lua_interface->GetSpawn(state, 2);
  3704. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3705. Client* client = player->GetZone()->GetClientBySpawn(player);
  3706. if (client) {
  3707. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3708. ((GroundSpawn*)node)->ProcessHarvest(client);
  3709. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3710. player->GetZone()->RemoveSpawn(true, node, true);
  3711. }
  3712. }
  3713. else if (player && player->IsPlayer()) {
  3714. Client* client = player->GetZone()->GetClientBySpawn(player);
  3715. if (client)
  3716. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3717. }
  3718. return 0;
  3719. }
  3720. int EQ2Emu_lua_Bind(lua_State* state) {
  3721. if (!lua_interface)
  3722. return 0;
  3723. Spawn* spawn = lua_interface->GetSpawn(state);
  3724. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3725. float x = lua_interface->GetFloatValue(state, 3);
  3726. float y = lua_interface->GetFloatValue(state, 4);
  3727. float z = lua_interface->GetFloatValue(state, 5);
  3728. float h = lua_interface->GetFloatValue(state, 6);
  3729. if (!spawn) {
  3730. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3731. return 0;
  3732. }
  3733. if (!spawn->IsPlayer()) {
  3734. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3735. return 0;
  3736. }
  3737. if (zone_id == 0) {
  3738. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3739. if (!client) {
  3740. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3741. return 0;
  3742. }
  3743. if (!client->Bind())
  3744. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3745. }
  3746. else {
  3747. Player* player = (Player*)spawn;
  3748. player->GetPlayerInfo()->SetBindZone(zone_id);
  3749. player->GetPlayerInfo()->SetBindX(x);
  3750. player->GetPlayerInfo()->SetBindY(y);
  3751. player->GetPlayerInfo()->SetBindZ(z);
  3752. player->GetPlayerInfo()->SetBindHeading(h);
  3753. }
  3754. return 0;
  3755. }
  3756. int EQ2Emu_lua_Gate(lua_State* state) {
  3757. if (!lua_interface)
  3758. return 0;
  3759. Spawn* spawn = lua_interface->GetSpawn(state);
  3760. if (spawn) {
  3761. if (spawn->IsPlayer()) {
  3762. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3763. if (client) {
  3764. if (!client->Gate())
  3765. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3766. }
  3767. }
  3768. }
  3769. return 0;
  3770. }
  3771. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3772. if (!lua_interface)
  3773. return 0;
  3774. bool ret = false;
  3775. Spawn* spawn = lua_interface->GetSpawn(state);
  3776. if (spawn) {
  3777. if (spawn->IsPlayer()) {
  3778. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3779. if (client)
  3780. ret = client->BindAllowed();
  3781. }
  3782. }
  3783. lua_interface->SetBooleanValue(state, ret);
  3784. return 1;
  3785. }
  3786. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3787. if (!lua_interface)
  3788. return 0;
  3789. bool ret = false;
  3790. Spawn* spawn = lua_interface->GetSpawn(state);
  3791. if (spawn) {
  3792. if (spawn->IsPlayer()) {
  3793. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3794. if (client)
  3795. ret = client->GateAllowed();
  3796. }
  3797. }
  3798. lua_interface->SetBooleanValue(state, ret);
  3799. return 1;
  3800. }
  3801. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3802. Spawn* spawn = lua_interface->GetSpawn(state);
  3803. if (spawn) {
  3804. lua_interface->SetBooleanValue(state, spawn->Alive());
  3805. return 1;
  3806. }
  3807. return 0;
  3808. }
  3809. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3810. if (!lua_interface)
  3811. return 0;
  3812. Spawn* spawn = lua_interface->GetSpawn(state);
  3813. if (spawn && spawn->IsEntity()) {
  3814. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3815. return 1;
  3816. }
  3817. return 0;
  3818. }
  3819. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3820. Spawn* spawn = lua_interface->GetSpawn(state);
  3821. string message = lua_interface->GetStringValue(state, 2);
  3822. string color_str = lua_interface->GetStringValue(state, 3);
  3823. int8 color = CHANNEL_NARRATIVE;
  3824. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3825. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3826. if (client) {
  3827. if (color_str.length() > 0) {
  3828. // leave for backwards compat, but all future should just use the number
  3829. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3830. color = CHANNEL_COLOR_RED;
  3831. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3832. color = CHANNEL_COLOR_YELLOW;
  3833. else
  3834. {
  3835. // use a number to specify the channel as per Commands/Commands.h defines
  3836. color = (int8)atoul(color_str.c_str());
  3837. }
  3838. }
  3839. client->SimpleMessage(color, message.c_str());
  3840. }
  3841. }
  3842. return 0;
  3843. }
  3844. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3845. Spawn* spawn = lua_interface->GetSpawn(state);
  3846. string message = lua_interface->GetStringValue(state, 2);
  3847. int8 red = lua_interface->GetInt8Value(state, 3);
  3848. int8 green = lua_interface->GetInt8Value(state, 4);
  3849. int8 blue = lua_interface->GetInt8Value(state, 5);
  3850. if (!spawn) {
  3851. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3852. return 0;
  3853. }
  3854. int32 words = ::CountWordsInString(message.c_str());
  3855. if (words < 5)
  3856. words = 5;
  3857. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3858. if (client)
  3859. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3860. return 0;
  3861. }
  3862. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3863. Spawn* spawn = lua_interface->GetSpawn(state);
  3864. int8 param = lua_interface->GetInt8Value(state, 2);
  3865. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3866. int8 value = lua_interface->GetInt8Value(state, 4);
  3867. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3868. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3869. if (client) {
  3870. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3871. switch (param) {
  3872. case 1: {
  3873. packet->setDataByName("parameter1", param_value);
  3874. break;
  3875. }
  3876. case 2: {
  3877. packet->setDataByName("parameter2", param_value);
  3878. break;
  3879. }
  3880. case 3: {
  3881. packet->setDataByName("parameter3", param_value);
  3882. break;
  3883. }
  3884. case 4: {
  3885. packet->setDataByName("parameter4", param_value);
  3886. break;
  3887. }
  3888. case 5: {
  3889. packet->setDataByName("parameter5", param_value);
  3890. break;
  3891. }
  3892. }
  3893. packet->setDataByName("value", value);
  3894. client->QueuePacket(packet->serialize());
  3895. safe_delete(packet);
  3896. }
  3897. }
  3898. return 0;
  3899. }
  3900. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3901. Spawn* spawn = lua_interface->GetSpawn(state);
  3902. if (spawn && spawn->IsPlayer()) {
  3903. if (((Player*)spawn)->GetIsTracking())
  3904. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3905. else
  3906. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3907. }
  3908. return 0;
  3909. }
  3910. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3911. Spawn* player = lua_interface->GetSpawn(state);
  3912. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3913. string name = lua_interface->GetStringValue(state, 3);
  3914. float distance = lua_interface->GetFloatValue(state, 4);
  3915. string command = lua_interface->GetStringValue(state, 5);
  3916. string error_text = lua_interface->GetStringValue(state, 6);
  3917. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3918. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3919. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3920. if (spawn) {
  3921. if (distance == 0)
  3922. distance = 10.0f;
  3923. if (command.length() == 0)
  3924. command = name;
  3925. if (command.length() < 1 && name.length() < 1)
  3926. {
  3927. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3928. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3929. spawn->RemovePrimaryCommands();
  3930. }
  3931. else
  3932. {
  3933. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3934. }
  3935. }
  3936. return 0;
  3937. }
  3938. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3939. if (!lua_interface)
  3940. return 0;
  3941. Spawn* player = lua_interface->GetSpawn(state);
  3942. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3943. int16 tier = lua_interface->GetInt16Value(state, 3);
  3944. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3945. if (player && spell && player->IsPlayer()) {
  3946. Client* client = player->GetZone()->GetClientBySpawn(player);
  3947. if (client) {
  3948. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3949. {
  3950. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3951. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3952. client->GetPlayer()->UnlockSpell(spell);
  3953. client->SendSpellUpdate(spell);
  3954. }
  3955. else
  3956. {
  3957. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3958. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3959. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3960. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3961. client->GetPlayer()->UnlockSpell(spell);
  3962. client->SendSpellUpdate(spell);
  3963. }
  3964. //if (client ) {
  3965. // ((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);
  3966. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3967. if (outapp)
  3968. client->QueuePacket(outapp);
  3969. }
  3970. }
  3971. return 0;
  3972. }
  3973. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3974. if (!lua_interface)
  3975. return 0;
  3976. Spawn* player = lua_interface->GetSpawn(state);
  3977. if (player && player->IsPlayer()) {
  3978. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3979. return 1;
  3980. }
  3981. return 0;
  3982. }
  3983. int EQ2Emu_lua_Attack(lua_State* state) {
  3984. if (lua_interface) {
  3985. Spawn* npc = lua_interface->GetSpawn(state);
  3986. Spawn* player = lua_interface->GetSpawn(state, 2);
  3987. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3988. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3989. }
  3990. return 0;
  3991. }
  3992. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3993. if (lua_interface) {
  3994. Spawn* target = lua_interface->GetSpawn(state);
  3995. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3996. if (target && target->GetZone())
  3997. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3998. }
  3999. return 0;
  4000. }
  4001. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4002. Spawn* player;
  4003. if (lua_interface) {
  4004. player = lua_interface->GetSpawn(state);
  4005. if (player && player->IsPlayer()) {
  4006. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4007. return 1;
  4008. }
  4009. }
  4010. return 0;
  4011. }
  4012. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4013. Spawn* player;
  4014. Client* client;
  4015. if (lua_interface) {
  4016. player = lua_interface->GetSpawn(state);
  4017. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4018. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4019. client->HandInCollections();
  4020. }
  4021. return 0;
  4022. }
  4023. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4024. Spawn* widget;
  4025. if (lua_interface) {
  4026. widget = lua_interface->GetSpawn(state);
  4027. if (widget && widget->IsWidget())
  4028. ((Widget*)widget)->HandleUse(NULL, "");
  4029. }
  4030. return 0;
  4031. }
  4032. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4033. Spawn* spawn = 0;
  4034. int32 primary_list = 0;
  4035. int32 secondary_list = 0;
  4036. if (lua_interface) {
  4037. spawn = lua_interface->GetSpawn(state);
  4038. primary_list = lua_interface->GetInt32Value(state, 2);
  4039. secondary_list = lua_interface->GetInt32Value(state, 3);
  4040. if (!spawn->IsNPC()) {
  4041. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4042. return 0;
  4043. }
  4044. NPC* npc = (NPC*)spawn;
  4045. npc->SetPrimarySpellList(primary_list);
  4046. npc->SetSecondarySpellList(secondary_list);
  4047. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4048. }
  4049. return 0;
  4050. }
  4051. int EQ2Emu_lua_GetPet(lua_State* state) {
  4052. if (!lua_interface)
  4053. return 0;
  4054. Spawn* spawn = lua_interface->GetSpawn(state);
  4055. if (spawn) {
  4056. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4057. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4058. return 1;
  4059. }
  4060. }
  4061. return 0;
  4062. }
  4063. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4064. if (!lua_interface)
  4065. return 0;
  4066. Spawn* spawn = lua_interface->GetSpawn(state);
  4067. if (spawn) {
  4068. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4069. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4070. return 1;
  4071. }
  4072. }
  4073. return 0;
  4074. }
  4075. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4076. if (!lua_interface)
  4077. return 0;
  4078. Spawn* spawn = lua_interface->GetSpawn(state);
  4079. if (spawn) {
  4080. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4081. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4082. return 1;
  4083. }
  4084. }
  4085. return 0;
  4086. }
  4087. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4088. if (!lua_interface)
  4089. return 0;
  4090. Spawn* spawn = lua_interface->GetSpawn(state);
  4091. if (spawn) {
  4092. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4093. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4094. return 1;
  4095. }
  4096. }
  4097. return 0;
  4098. }
  4099. int EQ2Emu_lua_Charm(lua_State* state) {
  4100. if (!lua_interface)
  4101. return 0;
  4102. Spawn* owner = lua_interface->GetSpawn(state);
  4103. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4104. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4105. if (!luaspell) {
  4106. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4107. return 0;
  4108. }
  4109. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4110. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4111. pet->SetPet(true);
  4112. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4113. ((NPC*)pet)->SetOwner((Entity*)owner);
  4114. // If owner is player and player does not have a summoned pet set the players charsheet
  4115. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4116. Player* player = (Player*)owner;
  4117. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4118. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  4119. player->GetInfoStruct()->pet_movement = 2;
  4120. player->GetInfoStruct()->pet_behavior = 3;
  4121. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4122. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4123. // Make sure the values get sent to the client
  4124. player->SetCharSheetChanged(true);
  4125. }
  4126. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4127. pet->SetSpawnScript("");
  4128. // Set faction to the same as the owner
  4129. pet->SetFactionID(owner->GetFactionID());
  4130. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4131. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4132. // Clear hate list
  4133. ((NPC*)pet)->Brain()->ClearHate();
  4134. // Set the brain to a pet brain
  4135. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4136. }
  4137. return 0;
  4138. }
  4139. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4140. if (!lua_interface)
  4141. return 0;
  4142. Spawn* spawn = lua_interface->GetSpawn(state);
  4143. if (!spawn) {
  4144. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4145. return 0;
  4146. }
  4147. vector<Spawn*> groupMembers;
  4148. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4149. groupMembers = *spawn->GetSpawnGroup();
  4150. }
  4151. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4152. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4153. deque<GroupMemberInfo*>::iterator itr;
  4154. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4155. if (group)
  4156. {
  4157. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4158. deque<GroupMemberInfo*>* members = group->GetMembers();
  4159. GroupMemberInfo* info = 0;
  4160. for (itr = members->begin(); itr != members->end(); itr++) {
  4161. info = *itr;
  4162. if (info->client)
  4163. groupMembers.push_back(info->client->GetPlayer());
  4164. }
  4165. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4166. }
  4167. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4168. }
  4169. else
  4170. return 0;
  4171. lua_createtable(state, groupMembers.size(), 0);
  4172. int newTable = lua_gettop(state);
  4173. for (int32 i = 0; i < groupMembers.size(); i++) {
  4174. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4175. lua_rawseti(state, newTable, i + 1);
  4176. }
  4177. return 1;
  4178. }
  4179. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4183. lua_interface->SetOptionWindowValue(state, option_window);
  4184. return 1;
  4185. }
  4186. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4187. if (!lua_interface)
  4188. return 0;
  4189. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4190. if (option_window) {
  4191. OptionWindowOption option_window_option;
  4192. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4193. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4194. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4195. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4196. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4197. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4198. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4199. option_window->push_back(option_window_option);
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4207. Spawn* player = lua_interface->GetSpawn(state, 2);
  4208. string window_title = lua_interface->GetStringValue(state, 3);
  4209. string cancel_command = lua_interface->GetStringValue(state, 4);
  4210. Client* client = player->GetZone()->GetClientBySpawn(player);
  4211. if (option_window && window_title.length() > 0 && client) {
  4212. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4213. if (!packet)
  4214. return 0;
  4215. packet->setDataByName("title_text", window_title.c_str());
  4216. if (cancel_command.length() > 0)
  4217. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4218. packet->setArrayLengthByName("num_selections", option_window->size());
  4219. vector<OptionWindowOption>::iterator itr;
  4220. int8 i = 0;
  4221. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4222. OptionWindowOption opt = *itr;
  4223. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4224. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4225. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4226. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4227. if (opt.optionCommand.length() > 0)
  4228. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4229. if (opt.optionConfirmTitle.length() > 0)
  4230. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4231. i++;
  4232. }
  4233. client->QueuePacket(packet->serialize());
  4234. safe_delete(option_window);
  4235. safe_delete(packet);
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* spawn = lua_interface->GetSpawn(state);
  4243. if (spawn) {
  4244. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4245. return 1;
  4246. }
  4247. else
  4248. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4249. return 0;
  4250. }
  4251. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4252. if (!lua_interface)
  4253. return 0;
  4254. Spawn* spawn = lua_interface->GetSpawn(state);
  4255. if (spawn) {
  4256. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4257. return 1;
  4258. }
  4259. else
  4260. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4261. return 0;
  4262. }
  4263. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4264. if (!lua_interface)
  4265. return 0;
  4266. Spawn* spawn = lua_interface->GetSpawn(state);
  4267. if (spawn) {
  4268. int8 class_id = spawn->GetTradeskillClass();
  4269. // Need to add 42 for the offset in the array
  4270. class_id += 44;
  4271. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4272. return 1;
  4273. }
  4274. else
  4275. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4276. return 0;
  4277. }
  4278. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4279. if (!lua_interface)
  4280. return 0;
  4281. Spawn* spawn = lua_interface->GetSpawn(state);
  4282. int16 level = lua_interface->GetInt8Value(state, 2);
  4283. if (spawn) {
  4284. if (spawn->IsPlayer())
  4285. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4286. else
  4287. spawn->SetTSLevel(level);
  4288. }
  4289. else
  4290. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4291. return 0;
  4292. }
  4293. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4294. if (!lua_interface)
  4295. return 0;
  4296. Spawn* spawn = lua_interface->GetSpawn(state);
  4297. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4298. if (spawn) {
  4299. spawn->SetAttackable(attackable);
  4300. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4301. }
  4302. return 0;
  4303. }
  4304. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4305. // Check to see if we have a valid lua_interface
  4306. if (!lua_interface)
  4307. return 0;
  4308. // Get the spawn that is getting the pet
  4309. Spawn* spawn = lua_interface->GetSpawn(state);
  4310. // Get the DB ID of the pet
  4311. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4312. // The max level the pet can gain
  4313. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4314. // Get the spell that this command was called from
  4315. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4316. // Check to make sure the spawn pointer is valid
  4317. if (!spawn) {
  4318. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4319. return 0;
  4320. }
  4321. // Check to make sure the spawn is an entity
  4322. if (!spawn->IsEntity()) {
  4323. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4324. return 0;
  4325. }
  4326. // Check to make sure the spawn doesn't already have a pet of this type
  4327. if (((Entity*)spawn)->GetPet()) {
  4328. if (spawn->IsPlayer()) {
  4329. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4330. if (client)
  4331. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4332. }
  4333. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4334. return 0;
  4335. }
  4336. // Check to see if the DB ID for the pet is set
  4337. if (pet_id == 0) {
  4338. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4339. return 0;
  4340. }
  4341. // Check to see if the pointer to the spell is valid
  4342. if (!luaspell) {
  4343. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4344. return 0;
  4345. }
  4346. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4347. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4348. if (!pet) {
  4349. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4350. return 0;
  4351. }
  4352. // Check to make sure the pet is an npc
  4353. if (!pet->IsNPC()) {
  4354. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4355. return 0;
  4356. }
  4357. // Spawn the pet at the same location as the owner
  4358. pet->SetX(spawn->GetX());
  4359. pet->SetY(spawn->GetY());
  4360. pet->SetZ(spawn->GetZ());
  4361. pet->SetLocation(spawn->GetLocation());
  4362. pet->SetHeading(spawn->GetHeading());
  4363. spawn->GetZone()->AddSpawn(pet);
  4364. /*
  4365. const char* spawn_script = world.GetSpawnScript(pet_id);
  4366. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4367. spawn->SetSpawnScript(string(spawn_script));
  4368. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4369. }*/
  4370. // Get a random pet name
  4371. string random_pet_name;
  4372. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4373. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4374. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4375. // If player set various values for the char sheet (pet window)
  4376. if (spawn->IsPlayer()) {
  4377. Player* player = (Player*)spawn;
  4378. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4379. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4380. player->GetInfoStruct()->pet_movement = 2;
  4381. player->GetInfoStruct()->pet_behavior = 3;
  4382. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4383. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4384. // Make sure the values get sent to the client
  4385. player->SetCharSheetChanged(true);
  4386. }
  4387. // Set the pets name
  4388. pet->SetName(random_pet_name.c_str());
  4389. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4390. if (max_level > 0)
  4391. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4392. else
  4393. pet->SetLevel(spawn->GetLevel());
  4394. // Set the max level this pet can reach
  4395. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4396. // Set the faction of the pet to the same faction as the owner
  4397. pet->SetFactionID(spawn->GetFactionID());
  4398. // Set the spawn as a pet
  4399. pet->SetPet(true);
  4400. // Give a pointer of the owner to the pet
  4401. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4402. // Give a pointer of the pet to the owner
  4403. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4404. // Set the pet type
  4405. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4406. // Set the spell id used to create this pet
  4407. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4408. // Set the spell tier used to create this pet
  4409. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4410. // Set the pets spawn type to 6
  4411. pet->SetSpawnType(6);
  4412. // Set the pets brain
  4413. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4414. // Check to see if the pet has a subtitle
  4415. if (strlen(pet->GetSubTitle()) > 0) {
  4416. // Add the players name to the front of the sub title
  4417. string pet_subtitle;
  4418. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4419. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4420. // Set the pets subtitle to the new one
  4421. pet->SetSubTitle(pet_subtitle.c_str());
  4422. }
  4423. // Add the "Pet Options" entity command to the pet
  4424. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4425. // Set the pet as the return value for this function
  4426. lua_interface->SetSpawnValue(state, pet);
  4427. return 1;
  4428. }
  4429. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4430. if (!lua_interface)
  4431. return 0;
  4432. Spawn* spawn = lua_interface->GetSpawn(state);
  4433. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4434. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4435. if (!spawn) {
  4436. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4437. return 0;
  4438. }
  4439. if (!spawn->IsEntity()) {
  4440. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4441. return 0;
  4442. }
  4443. if (((Entity*)spawn)->GetDeityPet()) {
  4444. if (spawn->IsPlayer()) {
  4445. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4446. if (client)
  4447. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4448. }
  4449. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4450. return 0;
  4451. }
  4452. if (pet_id == 0) {
  4453. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4454. return 0;
  4455. }
  4456. if (!luaspell) {
  4457. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4458. return 0;
  4459. }
  4460. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4461. if (!pet) {
  4462. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4463. return 0;
  4464. }
  4465. if (!pet->IsNPC()) {
  4466. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4467. return 0;
  4468. }
  4469. pet->SetX(spawn->GetX());
  4470. pet->SetY(spawn->GetY());
  4471. pet->SetZ(spawn->GetZ());
  4472. pet->SetLocation(spawn->GetLocation());
  4473. pet->SetHeading(spawn->GetHeading());
  4474. spawn->GetZone()->AddSpawn(pet);
  4475. string random_pet_name;
  4476. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4477. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4478. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4479. pet->SetName(random_pet_name.c_str());
  4480. pet->SetLevel(spawn->GetLevel());
  4481. pet->SetFactionID(spawn->GetFactionID());
  4482. pet->SetPet(true);
  4483. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4484. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4485. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4486. pet->SetSpawnType(6);
  4487. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4488. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4489. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4490. if (strlen(pet->GetSubTitle()) > 0) {
  4491. string pet_subtitle;
  4492. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4493. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4494. pet->SetSubTitle(pet_subtitle.c_str());
  4495. }
  4496. // deity and cosmetic pets are not attackable
  4497. pet->SetAttackable(false);
  4498. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4499. lua_interface->SetSpawnValue(state, pet);
  4500. return 1;
  4501. }
  4502. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4503. if (!lua_interface)
  4504. return 0;
  4505. Spawn* spawn = lua_interface->GetSpawn(state);
  4506. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4507. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4508. if (!spawn) {
  4509. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4510. return 0;
  4511. }
  4512. if (!spawn->IsEntity()) {
  4513. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4514. return 0;
  4515. }
  4516. if (((Entity*)spawn)->GetCosmeticPet()) {
  4517. if (spawn->IsPlayer()) {
  4518. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4519. if (client)
  4520. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4521. }
  4522. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4523. return 0;
  4524. }
  4525. if (pet_id == 0) {
  4526. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4527. return 0;
  4528. }
  4529. if (!luaspell) {
  4530. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4531. return 0;
  4532. }
  4533. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4534. if (!pet) {
  4535. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4536. return 0;
  4537. }
  4538. if (!pet->IsNPC()) {
  4539. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4540. return 0;
  4541. }
  4542. pet->SetX(spawn->GetX());
  4543. pet->SetY(spawn->GetY());
  4544. pet->SetZ(spawn->GetZ());
  4545. pet->SetLocation(spawn->GetLocation());
  4546. pet->SetHeading(spawn->GetHeading());
  4547. spawn->GetZone()->AddSpawn(pet);
  4548. string random_pet_name;
  4549. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4550. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4551. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4552. pet->SetName(random_pet_name.c_str());
  4553. pet->SetLevel(spawn->GetLevel());
  4554. pet->SetFactionID(spawn->GetFactionID());
  4555. pet->SetPet(true);
  4556. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4557. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4558. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4559. pet->SetSpawnType(6);
  4560. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4561. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4562. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4563. if (strlen(pet->GetSubTitle()) > 0) {
  4564. string pet_subtitle;
  4565. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4566. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4567. pet->SetSubTitle(pet_subtitle.c_str());
  4568. }
  4569. pet->SetAttackable(false);
  4570. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4571. lua_interface->SetSpawnValue(state, pet);
  4572. return 1;
  4573. }
  4574. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4575. if (!lua_interface)
  4576. return 0;
  4577. Spawn* spawn = lua_interface->GetSpawn(state);
  4578. if (!spawn) {
  4579. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4580. return 0;
  4581. }
  4582. if (!spawn->IsPet()) {
  4583. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4584. return 0;
  4585. }
  4586. if (!((NPC*)spawn)->IsDismissing())
  4587. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4588. return 0;
  4589. }
  4590. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4591. if (!lua_interface)
  4592. return 0;
  4593. Quest* quest = lua_interface->GetQuest(state);
  4594. if (!quest) {
  4595. 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));
  4596. return 0;
  4597. }
  4598. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4599. if (feather_color > 0)
  4600. quest->SetFeatherColor(feather_color);
  4601. return 0;
  4602. }
  4603. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4604. if (!lua_interface)
  4605. return 0;
  4606. Spawn* spawn = lua_interface->GetSpawn(state);
  4607. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4608. if (!spawn) {
  4609. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4610. return 0;
  4611. }
  4612. if (!spawn2) {
  4613. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4614. return 0;
  4615. }
  4616. spawn->RemoveSpawnAccess(spawn2);
  4617. return 0;
  4618. }
  4619. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4620. if (!lua_interface)
  4621. return 0;
  4622. ZoneServer* zone = lua_interface->GetZone(state);
  4623. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4624. if (!zone) {
  4625. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4626. return 0;
  4627. }
  4628. if (location_id == 0) {
  4629. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4630. return 0;
  4631. }
  4632. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4633. if (!location) {
  4634. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4635. return 0;
  4636. }
  4637. Spawn* spawn = 0;
  4638. if (location->entities[0]) {
  4639. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4640. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4641. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4642. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4643. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4644. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4645. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4646. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4647. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4648. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4649. if (spawn) {
  4650. const char* script = 0;
  4651. for (int x = 0; x < 3; x++) {
  4652. switch (x) {
  4653. case 0:
  4654. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4655. break;
  4656. case 1:
  4657. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4658. break;
  4659. case 2:
  4660. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4661. break;
  4662. }
  4663. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4664. spawn->SetSpawnScript(string(script));
  4665. break;
  4666. }
  4667. }
  4668. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4669. lua_interface->SetSpawnValue(state, spawn);
  4670. return 1;
  4671. }
  4672. else {
  4673. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4674. safe_delete(spawn);
  4675. }
  4676. }
  4677. return 0;
  4678. }
  4679. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4680. if (!lua_interface)
  4681. return 0;
  4682. Spawn* caster = lua_interface->GetSpawn(state);
  4683. Spawn* target = lua_interface->GetSpawn(state, 2);
  4684. int32 id = lua_interface->GetInt32Value(state, 3);
  4685. string command = lua_interface->GetStringValue(state, 4);
  4686. if (!caster) {
  4687. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4688. return 0;
  4689. }
  4690. if (!target) {
  4691. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4692. return 0;
  4693. }
  4694. if (!caster->IsPlayer()) {
  4695. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4696. return 0;
  4697. }
  4698. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4699. if (!entity_command) {
  4700. 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());
  4701. return 0;
  4702. }
  4703. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4704. if (!client) {
  4705. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4706. return 0;
  4707. }
  4708. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4709. return 0;
  4710. }
  4711. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4712. if (!lua_interface)
  4713. return 0;
  4714. Spawn* spawn = lua_interface->GetSpawn(state);
  4715. if (!spawn) {
  4716. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4717. return 0;
  4718. }
  4719. if (!spawn->IsNPC()) {
  4720. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4721. return 0;
  4722. }
  4723. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4724. return 0;
  4725. }
  4726. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4727. if (!lua_interface)
  4728. return 0;
  4729. Spawn* spawn = lua_interface->GetSpawn(state);
  4730. int16 tick = lua_interface->GetInt16Value(state, 2);
  4731. if (!spawn) {
  4732. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4733. return 0;
  4734. }
  4735. if (!spawn->IsNPC()) {
  4736. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4737. return 0;
  4738. }
  4739. if (tick < 20) {
  4740. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4741. return 0;
  4742. }
  4743. ((NPC*)spawn)->Brain()->SetTick(tick);
  4744. return 0;
  4745. }
  4746. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4747. if (!lua_interface)
  4748. return 0;
  4749. Spawn* spawn = lua_interface->GetSpawn(state);
  4750. Spawn* target = lua_interface->GetSpawn(state, 2);
  4751. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4752. if (!spawn) {
  4753. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4754. return 0;
  4755. }
  4756. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4757. spawn->SetFollowTarget(target, follow_distance);
  4758. return 0;
  4759. }
  4760. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4761. if (!lua_interface)
  4762. return 0;
  4763. Spawn* spawn = lua_interface->GetSpawn(state);
  4764. if (!spawn) {
  4765. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4766. return 0;
  4767. }
  4768. Spawn* target = spawn->GetFollowTarget();
  4769. if (target) {
  4770. lua_interface->SetSpawnValue(state, target);
  4771. return 1;
  4772. }
  4773. return 0;
  4774. }
  4775. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4776. if (!lua_interface)
  4777. return 0;
  4778. Spawn* spawn = lua_interface->GetSpawn(state);
  4779. if (!spawn) {
  4780. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4781. return 0;
  4782. }
  4783. if (spawn->following)
  4784. spawn->following = false;
  4785. else
  4786. spawn->following = true;
  4787. return 0;
  4788. }
  4789. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4790. if (!lua_interface)
  4791. return 0;
  4792. Spawn* spawn = lua_interface->GetSpawn(state);
  4793. if (!spawn) {
  4794. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4795. return 0;
  4796. }
  4797. lua_interface->SetBooleanValue(state, spawn->following);
  4798. return 1;
  4799. }
  4800. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4801. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4802. // I will attempt to explain how this function works for future refrence
  4803. // Fist lets make sure lua_interface is valid, if not return out
  4804. if (!lua_interface)
  4805. return 0;
  4806. // Next we grab the first 2 params same as we usually would
  4807. Spawn* spawn = lua_interface->GetSpawn(state);
  4808. string var = lua_interface->GetStringValue(state, 2);
  4809. // 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
  4810. // 1 = Spawn
  4811. // 2 = Zone
  4812. // 3 = Item
  4813. // 4 = Quest
  4814. // 5 = String
  4815. // 6 = nil (null)
  4816. int8 dataType = 0;
  4817. // Define pointers for each potential type
  4818. Spawn* spawnVal = 0;
  4819. ZoneServer* zone = 0;
  4820. Item* item = 0;
  4821. Quest* quest = 0;
  4822. string val;
  4823. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4824. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4825. // options window are also light user data be we do not handle those.
  4826. // We check with lua_islightuserdata(lua_State*, index)
  4827. if (lua_islightuserdata(state, 3)) {
  4828. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4829. // and convert it to LUAUserData*
  4830. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4831. // Check to make sure the data we got is valid, if not give an error
  4832. if (!data || !data->IsCorrectlyInitialized()) {
  4833. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4834. }
  4835. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4836. else if (data->IsSpawn()) {
  4837. spawnVal = data->spawn;
  4838. dataType = 1;
  4839. }
  4840. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4841. else if (data->IsZone()) {
  4842. zone = data->zone;
  4843. dataType = 2;
  4844. }
  4845. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4846. else if (data->IsItem()) {
  4847. item = data->item;
  4848. dataType = 3;
  4849. }
  4850. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4851. else if (data->IsQuest()) {
  4852. quest = data->quest;
  4853. dataType = 4;
  4854. }
  4855. }
  4856. // Wasn't light user data, check if it is nil(null)
  4857. else if (lua_isnil(state, 3)) {
  4858. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4859. dataType = 6;
  4860. }
  4861. // Wasn't light user data or nil (null), must be a string
  4862. else {
  4863. // Set the string and dataType variable
  4864. val = lua_interface->GetStringValue(state, 3);
  4865. dataType = 5;
  4866. }
  4867. // We now have all the params, lets check to make sure they are valid
  4868. if (!spawn) {
  4869. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4870. return 0;
  4871. }
  4872. if (var.length() == 0) {
  4873. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4874. return 0;
  4875. }
  4876. if (dataType == 0) {
  4877. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4878. return 0;
  4879. }
  4880. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4881. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4882. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4883. switch (dataType) {
  4884. case 1:
  4885. // 1 = Spawn
  4886. spawn->AddTempVariable(var, spawnVal);
  4887. break;
  4888. case 2:
  4889. // 2 = Zone
  4890. spawn->AddTempVariable(var, zone);
  4891. break;
  4892. case 3:
  4893. // 3 = Item
  4894. spawn->AddTempVariable(var, item);
  4895. break;
  4896. case 4:
  4897. // 4 = Quest
  4898. spawn->AddTempVariable(var, quest);
  4899. break;
  4900. case 5:
  4901. // 5 = String
  4902. spawn->AddTempVariable(var, val);
  4903. break;
  4904. case 6:
  4905. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4906. spawn->DeleteTempVariable(var);
  4907. break;
  4908. }
  4909. // And we are done so return out
  4910. return 0;
  4911. }
  4912. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4913. if (!lua_interface)
  4914. return 0;
  4915. Spawn* spawn = lua_interface->GetSpawn(state);
  4916. string var = lua_interface->GetStringValue(state, 2);
  4917. if (!spawn) {
  4918. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4919. return 0;
  4920. }
  4921. if (var.length() == 0) {
  4922. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4923. return 0;
  4924. }
  4925. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4926. int8 type = spawn->GetTempVariableType(var);
  4927. Spawn* spawn2 = 0;
  4928. ZoneServer* zone = 0;
  4929. Item* item = 0;
  4930. Quest* quest = 0;
  4931. // Set the lua function return value based on the type of data the variable contains
  4932. switch (type) {
  4933. case 1:
  4934. spawn2 = spawn->GetTempVariableSpawn(var);
  4935. if (!spawn2)
  4936. return 0;
  4937. lua_interface->SetSpawnValue(state, spawn2);
  4938. break;
  4939. case 2:
  4940. zone = spawn->GetTempVariableZone(var);
  4941. if (!zone)
  4942. return 0;
  4943. lua_interface->SetZoneValue(state, zone);
  4944. break;
  4945. case 3:
  4946. item = spawn->GetTempVariableItem(var);
  4947. if (!item)
  4948. return 0;
  4949. lua_interface->SetItemValue(state, item);
  4950. break;
  4951. case 4:
  4952. quest = spawn->GetTempVariableQuest(var);
  4953. if (!quest)
  4954. return 0;
  4955. lua_interface->SetQuestValue(state, quest);
  4956. break;
  4957. case 5:
  4958. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4959. break;
  4960. default:
  4961. // Not a valid type then the variable was not set so return out
  4962. return 0;
  4963. }
  4964. // Return value was set so return out
  4965. return 1;
  4966. }
  4967. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4968. {
  4969. if (!lua_interface)
  4970. return 0;
  4971. Quest* quest = lua_interface->GetQuest(state);
  4972. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4973. string description = lua_interface->GetStringValue(state, 3);
  4974. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4975. if (!quest) {
  4976. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4977. lua_interface->SetBooleanValue(state, false);
  4978. return 1;
  4979. }
  4980. if (!spawn) {
  4981. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4982. lua_interface->SetBooleanValue(state, false);
  4983. return 1;
  4984. }
  4985. if (!spawn->IsPlayer()) {
  4986. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4987. lua_interface->SetBooleanValue(state, false);
  4988. return 1;
  4989. }
  4990. if (item_id == 0) {
  4991. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4992. lua_interface->SetBooleanValue(state, false);
  4993. return 1;
  4994. }
  4995. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4996. if (!client) {
  4997. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4998. lua_interface->SetBooleanValue(state, false);
  4999. return 1;
  5000. }
  5001. Item* item = master_item_list.GetItem(item_id);
  5002. if (!item) {
  5003. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5004. lua_interface->SetBooleanValue(state, false);
  5005. return 1;
  5006. }
  5007. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  5008. if (packet) {
  5009. packet->setDataByName("title", "Quest Reward!");
  5010. packet->setDataByName("name", quest->GetName());
  5011. packet->setDataByName("description", description.c_str());
  5012. packet->setDataByName("level", quest->GetLevel());
  5013. packet->setArrayLengthByName("num_rewards", 1);
  5014. packet->setArrayDataByName("reward_id", item->details.item_id);
  5015. if (client->GetVersion() < 860)
  5016. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  5017. else if (client->GetVersion() < 1193)
  5018. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  5019. else
  5020. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  5021. client->QueuePacket(packet->serialize());
  5022. safe_delete(packet);
  5023. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5024. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5025. return 1;
  5026. }
  5027. lua_interface->SetBooleanValue(state, false);
  5028. return 1;
  5029. }
  5030. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5031. if (!lua_interface)
  5032. return 0;
  5033. Quest* quest = lua_interface->GetQuest(state);
  5034. if (!quest) {
  5035. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5036. return 0;
  5037. }
  5038. quest->SetRepeatable(true);
  5039. return 0;
  5040. }
  5041. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5042. if (!lua_interface)
  5043. return 0;
  5044. Spawn* spawn = lua_interface->GetSpawn(state);
  5045. if (!spawn) {
  5046. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5047. return 0;
  5048. }
  5049. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5050. string ret = classes.GetClassNameCase(base_class);
  5051. if (ret.length() > 0) {
  5052. lua_interface->SetStringValue(state, ret.c_str());
  5053. return 1;
  5054. }
  5055. return 0;
  5056. }
  5057. int EQ2Emu_lua_AddWard(lua_State* state) {
  5058. if (!lua_interface)
  5059. return 0;
  5060. int32 damage = lua_interface->GetInt32Value(state);
  5061. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5062. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5063. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5064. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5065. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5066. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5067. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5068. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5069. bool ward_was_added = false;
  5070. ZoneServer* zone = spell->caster->GetZone();
  5071. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5072. for (int32 i = 0; i < spell->targets.size(); i++) {
  5073. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5074. if (!target)
  5075. continue;
  5076. if (target->IsEntity()) {
  5077. // If the ward is already active remove it
  5078. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5079. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5080. // Create new ward info
  5081. WardInfo* ward = new WardInfo;
  5082. ward->Spell = spell;
  5083. ward->BaseDamage = damage;
  5084. ward->DamageLeft = damage;
  5085. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5086. ward->keepWard = keepWard;
  5087. ward->WardType = wardType;
  5088. if (damageAbsorptionPercent > 100)
  5089. damageAbsorptionPercent = 100;
  5090. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5091. if (damageAbsorptionMaxHealthPercent > 100)
  5092. damageAbsorptionMaxHealthPercent = 100;
  5093. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5094. ward->RedirectDamagePercent = redirectDamagePercent;
  5095. ward->LastRedirectDamage = 0;
  5096. ward->LastAbsorbedDamage = 0;
  5097. ward->HitCount = 0;
  5098. spell->num_triggers = maxHitCount;
  5099. spell->had_triggers = true;
  5100. spell->cancel_after_all_triggers = false;
  5101. ward->MaxHitCount = maxHitCount;
  5102. if (wardType == WARD_TYPE_MAGICAL)
  5103. ward->DamageType = damageTypes;
  5104. // Add the ward to the entity
  5105. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5106. ward_was_added = true;
  5107. }
  5108. }
  5109. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5110. if (ward_was_added && spell->caster->IsPlayer()) {
  5111. spell->had_dmg_remaining = true;
  5112. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5113. }
  5114. return 0;
  5115. }
  5116. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5117. if (!lua_interface)
  5118. return 0;
  5119. int32 amount = lua_interface->GetInt32Value(state);
  5120. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5121. WardInfo* ward = 0;
  5122. ZoneServer* zone = spell->caster->GetZone();
  5123. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5124. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5125. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5126. ward = target->GetWard(spell->spell->GetSpellID());
  5127. if (ward) {
  5128. ward->DamageLeft += amount;
  5129. if (ward->DamageLeft > ward->BaseDamage)
  5130. ward->DamageLeft = ward->BaseDamage;
  5131. for (int32 i = 0; i < spell->targets.size(); i++) {
  5132. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5133. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5134. }
  5135. }
  5136. }
  5137. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5138. if (ward && spell->caster->IsPlayer())
  5139. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5140. return 0;
  5141. }
  5142. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5143. if (!lua_interface)
  5144. return 0;
  5145. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5146. if (!spell) {
  5147. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5148. return 0;
  5149. }
  5150. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5151. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5152. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5153. if (ward) {
  5154. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5155. return 1;
  5156. }
  5157. }
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5164. if (!spell) {
  5165. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. string type = lua_interface->GetStringValue(state, 2);
  5169. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5170. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5171. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5172. if (ward) {
  5173. if (boost::iequals(type, "damageleft"))
  5174. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5175. else if (boost::iequals(type, "basedamage"))
  5176. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5177. else if (boost::iequals(type, "keepward"))
  5178. lua_interface->SetBooleanValue(state, ward->keepWard);
  5179. else if (boost::iequals(type, "wardtype"))
  5180. lua_interface->SetInt32Value(state, ward->WardType);
  5181. else if (boost::iequals(type, "dmgabsorptionpct"))
  5182. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5183. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5184. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5185. else if (boost::iequals(type, "redirectdamagepercent"))
  5186. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5187. else if (boost::iequals(type, "lastredirectdamage"))
  5188. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5189. else if (boost::iequals(type, "lastabsorbeddamage"))
  5190. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5191. else if (boost::iequals(type, "hitcount"))
  5192. lua_interface->SetInt32Value(state, ward->HitCount);
  5193. else if (boost::iequals(type, "maxhitcount"))
  5194. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5195. else
  5196. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5197. return 1;
  5198. }
  5199. }
  5200. return 0;
  5201. }
  5202. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5203. if (!lua_interface)
  5204. return 0;
  5205. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5206. ZoneServer* zone = spell->caster->GetZone();
  5207. Spawn* target = 0;
  5208. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5209. for (int32 i = 0; i < spell->targets.size(); i++) {
  5210. target = zone->GetSpawnByID(spell->targets.at(i));
  5211. if (target && target->IsEntity()) {
  5212. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5213. }
  5214. }
  5215. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5216. return 0;
  5217. }
  5218. int EQ2Emu_lua_Interrupt(lua_State* state)
  5219. {
  5220. if (!lua_interface)
  5221. return 0;
  5222. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5223. Spawn* target = lua_interface->GetSpawn(state, 2);
  5224. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5225. if (!caster)
  5226. {
  5227. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5228. return 0;
  5229. }
  5230. if (!target)
  5231. {
  5232. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5233. return 0;
  5234. }
  5235. if (!spell) {
  5236. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5237. return 0;
  5238. }
  5239. if (!target->IsEntity() && !spell)
  5240. {
  5241. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5242. return 0;
  5243. }
  5244. if (!target && spell) {
  5245. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5246. for (int8 i = 0; i < spell->targets.size(); i++) {
  5247. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5248. if (!target || !target->IsEntity())
  5249. continue;
  5250. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5251. }
  5252. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5253. }
  5254. else
  5255. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5256. return 0;
  5257. }
  5258. int EQ2Emu_lua_Stealth(lua_State* state) {
  5259. if (!lua_interface)
  5260. return 0;
  5261. int8 type = lua_interface->GetInt8Value(state);
  5262. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5263. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5264. if (!spell) {
  5265. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5266. return 0;
  5267. }
  5268. ZoneServer* zone = spell->caster->GetZone();
  5269. if (spawn) {
  5270. if (spawn->IsEntity()) {
  5271. if (type == 1) {
  5272. ((Entity*)spawn)->AddStealthSpell(spell);
  5273. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5274. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5275. }
  5276. else if (type == 2) {
  5277. ((Entity*)spawn)->AddInvisSpell(spell);
  5278. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5279. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5280. }
  5281. return 0;
  5282. }
  5283. else {
  5284. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5285. return 0;
  5286. }
  5287. }
  5288. else {
  5289. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5290. for (int32 i = 0; i < spell->targets.size(); i++) {
  5291. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5292. if (!spawn || !spawn->IsEntity())
  5293. continue;
  5294. if (type == 1) {
  5295. ((Entity*)spawn)->AddStealthSpell(spell);
  5296. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5297. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5298. }
  5299. else if (type == 2) {
  5300. ((Entity*)spawn)->AddInvisSpell(spell);
  5301. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5302. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5303. }
  5304. else {
  5305. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5306. break;
  5307. }
  5308. }
  5309. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5310. }
  5311. return 0;
  5312. }
  5313. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5314. if (!lua_interface)
  5315. return 0;
  5316. Spawn* spawn = lua_interface->GetSpawn(state);
  5317. if (!spawn) {
  5318. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (spawn->IsEntity()) {
  5322. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5323. return 1;
  5324. }
  5325. else
  5326. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5327. return 0;
  5328. }
  5329. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5330. if (!lua_interface)
  5331. return 0;
  5332. Spawn* spawn = lua_interface->GetSpawn(state);
  5333. if (!spawn) {
  5334. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5335. return 0;
  5336. }
  5337. if (spawn->IsEntity()) {
  5338. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5339. return 1;
  5340. }
  5341. else
  5342. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5343. return 0;
  5344. }
  5345. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5346. if (!lua_interface)
  5347. return 0;
  5348. Spawn* player = lua_interface->GetSpawn(state);
  5349. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5350. if (!player->IsPlayer()) {
  5351. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5352. return 0;
  5353. }
  5354. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5355. return 1;
  5356. }
  5357. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5358. if (!lua_interface)
  5359. return 0;
  5360. Spawn* player = lua_interface->GetSpawn(state);
  5361. int8 slot = lua_interface->GetInt8Value(state, 2);
  5362. if (!player) {
  5363. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5364. return 0;
  5365. }
  5366. if (!player->IsPlayer()) {
  5367. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5371. if (!item) {
  5372. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5373. return 0;
  5374. }
  5375. lua_interface->SetItemValue(state, item);
  5376. return 1;
  5377. }
  5378. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5379. if (!lua_interface)
  5380. return 0;
  5381. Spawn* player = lua_interface->GetSpawn(state);
  5382. int32 id = lua_interface->GetInt32Value(state, 2);
  5383. if (!player) {
  5384. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5385. return 0;
  5386. }
  5387. if (!player->IsPlayer()) {
  5388. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5389. return 0;
  5390. }
  5391. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5392. if (!item) {
  5393. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. lua_interface->SetItemValue(state, item);
  5397. return 1;
  5398. }
  5399. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5400. if (!lua_interface)
  5401. return 0;
  5402. Spawn* player = lua_interface->GetSpawn(state);
  5403. int32 id = lua_interface->GetInt32Value(state, 2);
  5404. int8 count = lua_interface->GetInt8Value(state, 3);
  5405. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5406. if (!player) {
  5407. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5408. return 0;
  5409. }
  5410. if (!player->IsPlayer()) {
  5411. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5412. return 0;
  5413. }
  5414. if (!count)
  5415. count = 1;
  5416. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5417. if (!item) {
  5418. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5419. return 0;
  5420. }
  5421. lua_interface->SetItemValue(state, item);
  5422. return 1;
  5423. }
  5424. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5425. if (!lua_interface)
  5426. return 0;
  5427. Spawn* spawn = lua_interface->GetSpawn(state);
  5428. int32 anim = lua_interface->GetInt32Value(state, 2);
  5429. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5430. int8 type = lua_interface->GetInt8Value(state, 4);
  5431. if (!spawn) {
  5432. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5433. return 0;
  5434. }
  5435. if (spawn2) {
  5436. if (spawn2->IsPlayer()) {
  5437. if (type != 1 && type != 2)
  5438. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5439. else
  5440. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5441. return 0;
  5442. }
  5443. else {
  5444. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5445. return 0;
  5446. }
  5447. }
  5448. else
  5449. spawn->GetZone()->PlayAnimation(spawn, anim);
  5450. return 0;
  5451. }
  5452. int EQ2Emu_lua_IsPet(lua_State* state) {
  5453. if (!lua_interface)
  5454. return 0;
  5455. Spawn* spawn = lua_interface->GetSpawn(state);
  5456. if (!spawn) {
  5457. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5458. return 0;
  5459. }
  5460. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5461. return 1;
  5462. }
  5463. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5464. if (!lua_interface)
  5465. return 0;
  5466. Spawn* spawn = lua_interface->GetSpawn(state);
  5467. if (!spawn) {
  5468. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5469. return 0;
  5470. }
  5471. if (!spawn->IsNPC()) {
  5472. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5473. return 0;
  5474. }
  5475. if (((NPC*)spawn)->GetOwner()) {
  5476. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5477. return 1;
  5478. }
  5479. return 0;
  5480. }
  5481. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5482. if (!lua_interface)
  5483. return 0;
  5484. Spawn* spawn = lua_interface->GetSpawn(state);
  5485. Spawn* target = lua_interface->GetSpawn(state, 2);
  5486. if (!spawn) {
  5487. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5488. return 0;
  5489. }
  5490. if (!spawn) {
  5491. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5492. return 0;
  5493. }
  5494. spawn->SetTarget(target);
  5495. return 0;
  5496. }
  5497. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5498. if (!lua_interface)
  5499. return 0;
  5500. Spawn* spawn = lua_interface->GetSpawn(state);
  5501. bool val = lua_interface->GetBooleanValue(state, 2);
  5502. if (!spawn) {
  5503. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5504. return 0;
  5505. }
  5506. if (!spawn->IsEntity()) {
  5507. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. ((Entity*)spawn)->InCombat(val);
  5511. if (val) {
  5512. spawn->ClearRunningLocations();
  5513. spawn->CalculateRunningLocation(true);
  5514. }
  5515. return 0;
  5516. }
  5517. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5518. if (!lua_interface)
  5519. return 0;
  5520. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5521. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5522. if (!spawn1) {
  5523. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. if (!spawn2) {
  5527. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5528. return 0;
  5529. }
  5530. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5531. return 1;
  5532. }
  5533. int EQ2Emu_lua_Runback(lua_State* state) {
  5534. if (!lua_interface)
  5535. return 0;
  5536. Spawn* spawn = lua_interface->GetSpawn(state);
  5537. if (!spawn) {
  5538. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5539. return 0;
  5540. }
  5541. if (!spawn->IsNPC()) {
  5542. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. ((NPC*)spawn)->Runback();
  5546. return 0;
  5547. }
  5548. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5549. if (!lua_interface)
  5550. return 0;
  5551. Spawn* spawn = lua_interface->GetSpawn(state);
  5552. if (!spawn) {
  5553. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5554. return 0;
  5555. }
  5556. if (!spawn->IsNPC()) {
  5557. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5558. return 0;
  5559. }
  5560. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5561. return 1;
  5562. }
  5563. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5564. if (!lua_interface)
  5565. return 0;
  5566. Spawn* spawn = lua_interface->GetSpawn(state);
  5567. if (!spawn) {
  5568. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5569. return 0;
  5570. }
  5571. if (!spawn->IsEntity()) {
  5572. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5573. return 0;
  5574. }
  5575. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5576. return 1;
  5577. }
  5578. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5579. if (!lua_interface)
  5580. return 0;
  5581. Spawn* spawn = lua_interface->GetSpawn(state);
  5582. if (!spawn) {
  5583. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5584. return 0;
  5585. }
  5586. if (!spawn->IsEntity()) {
  5587. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5588. return 0;
  5589. }
  5590. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5591. return 1;
  5592. }
  5593. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5594. if (!lua_interface)
  5595. return 0;
  5596. Spawn* spawn = lua_interface->GetSpawn(state);
  5597. if (!spawn) {
  5598. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5599. return 0;
  5600. }
  5601. if (!spawn->IsEntity()) {
  5602. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5603. return 0;
  5604. }
  5605. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5606. return 1;
  5607. }
  5608. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5609. if (!lua_interface)
  5610. return 0;
  5611. Spawn* spawn = lua_interface->GetSpawn(state);
  5612. if (!spawn) {
  5613. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5614. return 0;
  5615. }
  5616. if (!spawn->IsEntity()) {
  5617. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5618. return 0;
  5619. }
  5620. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5621. return 1;
  5622. }
  5623. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5624. if (!lua_interface)
  5625. return 0;
  5626. Spawn* spawn = lua_interface->GetSpawn(state);
  5627. Spawn* target = lua_interface->GetSpawn(state, 2);
  5628. float distance = lua_interface->GetFloatValue(state, 3);
  5629. if (!spawn) {
  5630. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. if (!target) {
  5634. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5635. return 0;
  5636. }
  5637. if (!spawn->IsNPC()) {
  5638. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5639. return 0;
  5640. }
  5641. if (!target->IsEntity()) {
  5642. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5643. return 0;
  5644. }
  5645. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5646. return 1;
  5647. }
  5648. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5649. if (!lua_interface)
  5650. return 0;
  5651. Spawn* spawn = lua_interface->GetSpawn(state);
  5652. Spawn* target = lua_interface->GetSpawn(state, 2);
  5653. float distance = lua_interface->GetFloatValue(state, 3);
  5654. if (!spawn) {
  5655. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5656. return 0;
  5657. }
  5658. if (!target) {
  5659. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5660. return 0;
  5661. }
  5662. if (!spawn->IsNPC()) {
  5663. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5664. return 0;
  5665. }
  5666. if (!target->IsEntity()) {
  5667. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5668. return 0;
  5669. }
  5670. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5671. return 0;
  5672. }
  5673. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5674. if (!lua_interface)
  5675. return 0;
  5676. Spawn* spawn = lua_interface->GetSpawn(state);
  5677. if (!spawn) {
  5678. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5679. return 0;
  5680. }
  5681. if (!spawn->IsNPC()) {
  5682. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5683. return 0;
  5684. }
  5685. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5686. return 1;
  5687. }
  5688. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5689. if (!lua_interface)
  5690. return 0;
  5691. Spawn* spawn = lua_interface->GetSpawn(state);
  5692. if (!spawn) {
  5693. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5694. return 0;
  5695. }
  5696. if (!spawn->IsNPC()) {
  5697. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5698. return 0;
  5699. }
  5700. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5701. return 1;
  5702. }
  5703. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5704. if (!lua_interface)
  5705. return 0;
  5706. Spawn* spawn = lua_interface->GetSpawn(state);
  5707. if (!spawn) {
  5708. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5709. return 0;
  5710. }
  5711. if (!spawn->IsNPC()) {
  5712. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5713. return 0;
  5714. }
  5715. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5716. if (hated) {
  5717. lua_interface->SetSpawnValue(state, hated);
  5718. return 1;
  5719. }
  5720. return 0;
  5721. }
  5722. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5723. if (!lua_interface)
  5724. return 0;
  5725. Spawn* spawn = lua_interface->GetSpawn(state);
  5726. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5727. if (!spawn) {
  5728. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. if (!spawn->IsNPC()) {
  5732. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5733. return 0;
  5734. }
  5735. if (!hated) {
  5736. ((NPC*)spawn)->Brain()->ClearHate();
  5737. return 0;
  5738. }
  5739. else
  5740. {
  5741. if (!hated->IsEntity()) {
  5742. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5746. return 0;
  5747. }
  5748. return 0;
  5749. }
  5750. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5751. if (!lua_interface)
  5752. return 0;
  5753. Spawn* spawn = lua_interface->GetSpawn(state);
  5754. if (!spawn) {
  5755. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5756. return 0;
  5757. }
  5758. if (!spawn->IsNPC()) {
  5759. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5760. return 0;
  5761. }
  5762. ((NPC*)spawn)->Brain()->ClearEncounter();
  5763. return 0;
  5764. }
  5765. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5766. if (!lua_interface)
  5767. return 0;
  5768. Spawn* spawn = lua_interface->GetSpawn(state);
  5769. if (!spawn) {
  5770. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5771. return 0;
  5772. }
  5773. if (!spawn->IsNPC()) {
  5774. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5775. return 0;
  5776. }
  5777. // Temp list to store hate list
  5778. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5779. if (encounterList->size() == 0) {
  5780. safe_delete(encounterList);
  5781. return 0;
  5782. }
  5783. lua_createtable(state, encounterList->size(), 0);
  5784. int newTable = lua_gettop(state);
  5785. for (int32 i = 0; i < encounterList->size(); i++) {
  5786. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5787. if (temp)
  5788. lua_interface->SetSpawnValue(state, temp);
  5789. lua_rawseti(state, newTable, i + 1);
  5790. }
  5791. safe_delete(encounterList);
  5792. return 1;
  5793. }
  5794. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5795. if (!lua_interface)
  5796. return 0;
  5797. Spawn* spawn = lua_interface->GetSpawn(state);
  5798. if (!spawn) {
  5799. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5800. return 0;
  5801. }
  5802. if (!spawn->IsNPC()) {
  5803. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5804. return 0;
  5805. }
  5806. // Temp list to store hate list
  5807. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5808. if (hateList->size() == 0) {
  5809. safe_delete(hateList);
  5810. return 0;
  5811. }
  5812. lua_createtable(state, hateList->size(), 0);
  5813. int newTable = lua_gettop(state);
  5814. for (int32 i = 0; i < hateList->size(); i++) {
  5815. lua_interface->SetSpawnValue(state, hateList->at(i));
  5816. lua_rawseti(state, newTable, i + 1);
  5817. }
  5818. safe_delete(hateList);
  5819. return 1;
  5820. }
  5821. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5822. if (!lua_interface)
  5823. return 0;
  5824. Spawn* spawn = lua_interface->GetSpawn(state);
  5825. if (!spawn) {
  5826. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5827. return 0;
  5828. }
  5829. if (spawn->IsPlayer()) {
  5830. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5831. lua_interface->SetBooleanValue(state, true);
  5832. else
  5833. lua_interface->SetBooleanValue(state, false);
  5834. return 1;
  5835. }
  5836. else {
  5837. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5838. return 1;
  5839. }
  5840. }
  5841. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5842. if (!lua_interface)
  5843. return 0;
  5844. Quest* quest = lua_interface->GetQuest(state);
  5845. if (!quest) {
  5846. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5847. return 0;
  5848. }
  5849. quest->SetCompletedFlag(true);
  5850. return 0;
  5851. }
  5852. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5853. if (!lua_interface)
  5854. return 0;
  5855. Spawn* spawn = lua_interface->GetSpawn(state);
  5856. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5857. int8 tier = lua_interface->GetInt8Value(state, 3);
  5858. if (!spawn) {
  5859. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5860. return 0;
  5861. }
  5862. if (!spawn->IsEntity()) {
  5863. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5864. return 0;
  5865. }
  5866. if (spellID == 0) {
  5867. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5871. if (effect) {
  5872. if (tier > 0) {
  5873. // If a tier was passed chec to see if it is the same as the effect
  5874. if (tier == effect->tier)
  5875. lua_interface->SetBooleanValue(state, true);
  5876. else
  5877. lua_interface->SetBooleanValue(state, false);
  5878. return 1;
  5879. }
  5880. else {
  5881. // Have an effect but no tier was passed so return true
  5882. lua_interface->SetBooleanValue(state, true);
  5883. }
  5884. return 1;
  5885. }
  5886. // no effect so return false
  5887. lua_interface->SetBooleanValue(state, false);
  5888. return 1;
  5889. }
  5890. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5891. if (!lua_interface)
  5892. return 0;
  5893. Spawn* spawn = lua_interface->GetSpawn(state);
  5894. int32 id = lua_interface->GetInt32Value(state, 2);
  5895. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5896. Spawn* spawn2 = 0;
  5897. vector<Spawn*> list;
  5898. if (!spawn) {
  5899. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5900. return 0;
  5901. }
  5902. //If zone not provided, use spawn's zone
  5903. if (!zone)
  5904. zone = spawn->GetZone();
  5905. list = zone->GetSpawnsByID(id);
  5906. if (list.size() == 0) {
  5907. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. vector<Spawn*>::iterator itr = list.begin();
  5911. for (int8 i = 0; i < list.size(); i++) {
  5912. spawn2 = itr[i];
  5913. if (spawn2)
  5914. spawn2->AddAllowAccessSpawn(spawn);
  5915. }
  5916. return 0;
  5917. }
  5918. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5919. if (!lua_interface)
  5920. return 0;
  5921. Spawn* spawn = lua_interface->GetSpawn(state);
  5922. int32 id = lua_interface->GetInt32Value(state, 2);
  5923. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5924. Spawn* spawn2 = 0;
  5925. if (!spawn) {
  5926. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5927. return 0;
  5928. }
  5929. //If zone not provided, use spawn's zone
  5930. if (!zone)
  5931. zone = spawn->GetZone();
  5932. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5933. vector<Spawn*>::iterator itr = list.begin();
  5934. if (list.size() == 0) {
  5935. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5936. return 0;
  5937. }
  5938. for (int8 i = 0; i < list.size(); i++) {
  5939. spawn2 = itr[i];
  5940. if (spawn2)
  5941. spawn2->RemoveSpawnAccess(spawn);
  5942. }
  5943. return 0;
  5944. }
  5945. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5946. if (!lua_interface)
  5947. return 0;
  5948. Quest* quest = lua_interface->GetQuest(state);
  5949. if (!quest) {
  5950. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5951. return 0;
  5952. }
  5953. quest->SetYellowName(true);
  5954. return 0;
  5955. }
  5956. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5957. if (!lua_interface)
  5958. return 0;
  5959. Spawn* spawn = lua_interface->GetSpawn(state);
  5960. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5961. if (!spawn) {
  5962. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5963. return 0;
  5964. }
  5965. if (!spawn->IsPlayer()) {
  5966. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5970. return 1;
  5971. }
  5972. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5973. if (!lua_interface)
  5974. return 0;
  5975. Spawn* spawn = lua_interface->GetSpawn(state);
  5976. if (!spawn) {
  5977. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. if (!spawn->IsPlayer()) {
  5981. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5982. return 0;
  5983. }
  5984. ZoneServer* zone = spawn->GetZone();
  5985. if (!zone) {
  5986. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5987. return 0;
  5988. }
  5989. Instance_Type iType = zone->GetInstanceType();
  5990. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5991. iType == GROUP_LOCKOUT_INSTANCE ||
  5992. iType == RAID_LOCKOUT_INSTANCE ||
  5993. iType == SOLO_PERSIST_INSTANCE ||
  5994. iType == GROUP_PERSIST_INSTANCE ||
  5995. iType == RAID_PERSIST_INSTANCE) {
  5996. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5997. if (data) {
  5998. // Check to see if the timer has already been set, if it has return out.
  5999. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6000. return 0;
  6001. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6002. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6003. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6004. if (client) {
  6005. string time_msg = "";
  6006. int32 time = data->success_lockout_time;
  6007. int16 hour;
  6008. int8 min;
  6009. int8 sec;
  6010. hour = time / 3600;
  6011. time = time % 3600;
  6012. min = time / 60;
  6013. time = time % 60;
  6014. sec = time;
  6015. if (hour > 0) {
  6016. char temp[10];
  6017. sprintf(temp, " %i", hour);
  6018. time_msg.append(temp);
  6019. time_msg.append(" hour");
  6020. time_msg.append((hour > 1) ? "s" : "");
  6021. }
  6022. if (min > 0) {
  6023. char temp[5];
  6024. sprintf(temp, " %i", min);
  6025. time_msg.append(temp);
  6026. time_msg.append(" minute");
  6027. time_msg.append((min > 1) ? "s" : "");
  6028. }
  6029. // Only add seconds if minutes and hours are 0
  6030. if (hour == 0 && min == 0 && sec > 0) {
  6031. char temp[5];
  6032. sprintf(temp, " %i", sec);
  6033. time_msg.append(temp);
  6034. time_msg.append(" second");
  6035. time_msg.append((sec > 1) ? "s" : "");
  6036. }
  6037. 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());
  6038. }
  6039. }
  6040. else
  6041. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6042. }
  6043. else
  6044. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6048. if (!lua_interface)
  6049. return 0;
  6050. Spawn* spawn = lua_interface->GetSpawn(state);
  6051. if (!spawn) {
  6052. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. if (!spawn->IsPlayer()) {
  6056. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6057. return 0;
  6058. }
  6059. ZoneServer* zone = spawn->GetZone();
  6060. if (!zone) {
  6061. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6062. return 0;
  6063. }
  6064. Instance_Type iType = zone->GetInstanceType();
  6065. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6066. iType == GROUP_LOCKOUT_INSTANCE ||
  6067. iType == RAID_LOCKOUT_INSTANCE ||
  6068. iType == SOLO_PERSIST_INSTANCE ||
  6069. iType == GROUP_PERSIST_INSTANCE ||
  6070. iType == RAID_PERSIST_INSTANCE) {
  6071. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6072. if (data) {
  6073. // Check to see if the timer has already been set, if it has return out.
  6074. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6075. return 0;
  6076. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6077. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6078. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6079. if (client) {
  6080. string time_msg = "";
  6081. int32 time = data->failure_lockout_time;
  6082. int16 hour;
  6083. int8 min;
  6084. int8 sec;
  6085. hour = time / 3600;
  6086. time = time % 3600;
  6087. min = time / 60;
  6088. time = time % 60;
  6089. sec = time;
  6090. if (hour > 0) {
  6091. char temp[10];
  6092. sprintf(temp, " %i", hour);
  6093. time_msg.append(temp);
  6094. time_msg.append(" hour");
  6095. time_msg.append((hour > 1) ? "s" : "");
  6096. }
  6097. if (min > 0) {
  6098. char temp[5];
  6099. sprintf(temp, " %i", min);
  6100. time_msg.append(temp);
  6101. time_msg.append(" minute");
  6102. time_msg.append((min > 1) ? "s" : "");
  6103. }
  6104. // Only add seconds if minutes and hours are 0
  6105. if (hour == 0 && min == 0 && sec > 0) {
  6106. char temp[5];
  6107. sprintf(temp, " %i", sec);
  6108. time_msg.append(temp);
  6109. time_msg.append(" second");
  6110. time_msg.append((sec > 1) ? "s" : "");
  6111. }
  6112. 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());
  6113. }
  6114. }
  6115. else
  6116. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6117. }
  6118. else
  6119. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6123. if (!lua_interface)
  6124. return 0;
  6125. Spawn* spawn = lua_interface->GetSpawn(state);
  6126. if (!spawn) {
  6127. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6131. return 1;
  6132. }
  6133. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6134. if (!lua_interface)
  6135. return 0;
  6136. Spawn* player = lua_interface->GetSpawn(state);
  6137. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6138. if (!player) {
  6139. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6140. return 0;
  6141. }
  6142. if (!player->IsPlayer()) {
  6143. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. if (!ground) {
  6147. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6148. return 0;
  6149. }
  6150. if (!ground->IsGroundSpawn()) {
  6151. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6152. return 0;
  6153. }
  6154. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6155. if (!groundspawn_entries) {
  6156. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6157. return 0;
  6158. }
  6159. Skill* skill = 0;
  6160. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6161. if (collection_skill == "Collecting")
  6162. skill = ((Player*)player)->GetSkillByName("Gathering");
  6163. else
  6164. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6165. if (!skill) {
  6166. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6167. return 0;
  6168. }
  6169. vector<GroundSpawnEntry*>::iterator itr;
  6170. GroundSpawnEntry* entry = 0;
  6171. bool can_harvest = false;
  6172. sint32 min_skill = -1;
  6173. // first, iterate through groundspawn_entries, discard tables player cannot use
  6174. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6175. {
  6176. entry = *itr;
  6177. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6178. min_skill = entry->min_skill_level;
  6179. // if player lacks skill, skip table
  6180. if (entry->min_skill_level > skill->current_val)
  6181. continue;
  6182. // if bonus, but player lacks level, skip table
  6183. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6184. continue;
  6185. can_harvest = true;
  6186. break;
  6187. }
  6188. lua_interface->SetBooleanValue(state, can_harvest);
  6189. // If false, send the message to the client
  6190. if (!can_harvest) {
  6191. Client* client = player->GetZone()->GetClientBySpawn(player);
  6192. if (client) {
  6193. string msg = "You do not have enough skill to ";
  6194. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6195. msg.append("gather");
  6196. else if (collection_skill == "Mining")
  6197. msg.append("mine");
  6198. else if (collection_skill == "Trapping")
  6199. msg.append("trap");
  6200. else if (collection_skill == "Foresting")
  6201. msg.append("forest");
  6202. else if (collection_skill == "Fishing")
  6203. msg.append("catch");
  6204. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6205. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6206. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6207. }
  6208. }
  6209. return 1;
  6210. }
  6211. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6212. if (!lua_interface)
  6213. return 0;
  6214. Spawn* player = lua_interface->GetSpawn(state);
  6215. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6216. if (!player) {
  6217. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. if (!player->IsPlayer()) {
  6221. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6225. lua_interface->SetBooleanValue(state, ret);
  6226. return 1;
  6227. }
  6228. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6229. // Check to see if we have a valid lua_interface
  6230. if (!lua_interface)
  6231. return 0;
  6232. // Get the spawn that is getting the pet
  6233. Spawn* spawn = lua_interface->GetSpawn(state);
  6234. Spawn* target = lua_interface->GetSpawn(state, 2);
  6235. // Get the DB ID of the pet
  6236. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6237. float x = lua_interface->GetFloatValue(state, 4);
  6238. float y = lua_interface->GetFloatValue(state, 5);
  6239. float z = lua_interface->GetFloatValue(state, 6);
  6240. // Get the spell that this command was called from
  6241. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6242. // Check to make sure the spawn pointer is valid
  6243. if (!spawn) {
  6244. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. // Check to make sure the spawn is an entity
  6248. if (!spawn->IsEntity()) {
  6249. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6250. return 0;
  6251. }
  6252. if (!target) {
  6253. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6254. return 0;
  6255. }
  6256. if (!target->IsEntity()) {
  6257. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. // Check to see if the DB ID for the pet is set
  6261. if (pet_id == 0) {
  6262. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6263. return 0;
  6264. }
  6265. // Check to see if the pointer to the spell is valid
  6266. if (!luaspell) {
  6267. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6271. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6272. if (!pet) {
  6273. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6274. return 0;
  6275. }
  6276. // Check to make sure the pet is an npc
  6277. if (!pet->IsNPC()) {
  6278. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6279. return 0;
  6280. }
  6281. if (x == 0)
  6282. x = spawn->GetX();
  6283. if (y == 0)
  6284. y = spawn->GetY();
  6285. if (z == 0)
  6286. z = spawn->GetZ();
  6287. // Spawn the pet at the same location as the owner
  6288. pet->SetX(x);
  6289. pet->SetY(y);
  6290. pet->SetZ(z);
  6291. pet->SetLocation(spawn->GetLocation());
  6292. pet->SetHeading(spawn->GetHeading());
  6293. spawn->GetZone()->AddSpawn(pet);
  6294. /*
  6295. const char* spawn_script = world.GetSpawnScript(pet_id);
  6296. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6297. spawn->SetSpawnScript(string(spawn_script));
  6298. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6299. }*/
  6300. // Get a random pet name
  6301. string random_pet_name;
  6302. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6303. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6304. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6305. // Set the pets name
  6306. pet->SetName(random_pet_name.c_str());
  6307. // Set the level of the pet to the owners level
  6308. pet->SetLevel(spawn->GetLevel());
  6309. // Set the faction of the pet to the same faction as the owner
  6310. pet->SetFactionID(spawn->GetFactionID());
  6311. // Set the spawn as a pet
  6312. pet->SetPet(true);
  6313. // Give a pointer of the owner to the pet
  6314. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6315. // Set the pet type
  6316. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6317. // Set the spell id used to create this pet
  6318. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6319. // Set the spell tier used to create this pet
  6320. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6321. // Set the pets spawn type to 6
  6322. pet->SetSpawnType(6);
  6323. // Set the pets brain
  6324. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6325. // Check to see if the pet has a subtitle
  6326. if (strlen(pet->GetSubTitle()) > 0) {
  6327. // Add the players name to the front of the sub title
  6328. string pet_subtitle;
  6329. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6330. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6331. // Set the pets subtitle to the new one
  6332. pet->SetSubTitle(pet_subtitle.c_str());
  6333. }
  6334. // Set the pet as the return value for this function
  6335. lua_interface->SetSpawnValue(state, pet);
  6336. return 1;
  6337. }
  6338. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6339. if (!lua_interface)
  6340. return 0;
  6341. Spawn* spawn = lua_interface->GetSpawn(state);
  6342. Spawn* player = lua_interface->GetSpawn(state, 2);
  6343. float max_distance = lua_interface->GetFloatValue(state, 3);
  6344. string type = lua_interface->GetStringValue(state, 4);
  6345. if (!spawn || (spawn && spawn->IsPlayer())) {
  6346. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. if (!player || (player && !player->IsPlayer())) {
  6350. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. Client* client = 0;
  6354. if (player->GetZone())
  6355. client = player->GetZone()->GetClientBySpawn(player);
  6356. if (!client) {
  6357. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6358. return 0;
  6359. }
  6360. //Set max_distance to default if not set or not proper value
  6361. if (max_distance <= 0)
  6362. max_distance = 500;
  6363. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6364. if (packet) {
  6365. float unknown2_3 = 0;
  6366. int8 placement_mode = 0;
  6367. if (type == "wall") {
  6368. placement_mode = 2;
  6369. unknown2_3 = 150;
  6370. }
  6371. else if (type == "ceiling")
  6372. placement_mode = 1;
  6373. packet->setDataByName("placement_mode", placement_mode);
  6374. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6375. packet->setDataByName("model_type", spawn->GetModelType());
  6376. packet->setDataByName("unknown", 1); //size
  6377. packet->setDataByName("unknown2", 1); //size 2
  6378. packet->setDataByName("unknown2", .5, 1); //size 3
  6379. packet->setDataByName("unknown2", 3, 2);
  6380. packet->setDataByName("unknown2", unknown2_3, 3);
  6381. packet->setDataByName("max_distance", max_distance);
  6382. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6383. client->QueuePacket(packet->serialize());
  6384. safe_delete(packet);
  6385. }
  6386. return 0;
  6387. }
  6388. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6389. if (!lua_interface)
  6390. return 0;
  6391. Item* item = lua_interface->GetItem(state);
  6392. if (!item) {
  6393. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6394. return 0;
  6395. }
  6396. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6397. return 1;
  6398. }
  6399. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6400. if (!lua_interface)
  6401. return 0;
  6402. Spawn* spawn = lua_interface->GetSpawn(state);
  6403. if (!spawn) {
  6404. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6405. return 0;
  6406. }
  6407. if (spawn->GetZone())
  6408. spawn->GetZone()->AddTransportSpawn(spawn);
  6409. return 0;
  6410. }
  6411. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6412. if (!lua_interface)
  6413. return 0;
  6414. Skill* skill = lua_interface->GetSkill(state);
  6415. if (!skill) {
  6416. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6417. return 0;
  6418. }
  6419. lua_interface->SetInt32Value(state, skill->current_val);
  6420. return 1;
  6421. }
  6422. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6423. if (!lua_interface)
  6424. return 0;
  6425. Skill* skill = lua_interface->GetSkill(state);
  6426. if (!skill) {
  6427. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6428. return 0;
  6429. }
  6430. lua_interface->SetInt32Value(state, skill->max_val);
  6431. return 1;
  6432. }
  6433. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6434. if (!lua_interface)
  6435. return 0;
  6436. Skill* skill = lua_interface->GetSkill(state);
  6437. if (!skill) {
  6438. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6442. return 1;
  6443. }
  6444. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6445. if (!lua_interface)
  6446. return 0;
  6447. Skill* skill = lua_interface->GetSkill(state);
  6448. int16 value = lua_interface->GetInt16Value(state, 2);
  6449. if (!skill) {
  6450. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6451. return 0;
  6452. }
  6453. skill->max_val = value;
  6454. if (skill->max_val < skill->current_val)
  6455. skill->current_val = skill->max_val;
  6456. return 0;
  6457. }
  6458. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6459. if (!lua_interface)
  6460. return 0;
  6461. Skill* skill = lua_interface->GetSkill(state);
  6462. int16 value = lua_interface->GetInt16Value(state, 2);
  6463. if (!skill) {
  6464. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6465. return 0;
  6466. }
  6467. if (value > skill->max_val)
  6468. skill->current_val = skill->max_val;
  6469. else
  6470. skill->current_val = value;
  6471. return 0;
  6472. }
  6473. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6474. if (!lua_interface)
  6475. return 0;
  6476. Spawn* spawn = lua_interface->GetSpawn(state);
  6477. string name = lua_interface->GetStringValue(state, 2);
  6478. if (!spawn) {
  6479. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. if (!spawn->IsEntity()) {
  6483. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6484. return 0;
  6485. }
  6486. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6487. if (skill) {
  6488. lua_interface->SetSkillValue(state, skill);
  6489. return 1;
  6490. }
  6491. return 0;
  6492. }
  6493. int EQ2Emu_lua_AddProc(lua_State* state) {
  6494. if (!lua_interface)
  6495. return 0;
  6496. Spawn* spawn = lua_interface->GetSpawn(state);
  6497. int8 type = lua_interface->GetInt8Value(state, 2);
  6498. float chance = lua_interface->GetFloatValue(state, 3);
  6499. Item* item = lua_interface->GetItem(state, 4);
  6500. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6501. LuaSpell* spell = 0;
  6502. if (!spawn && (!spell || !use_all_spelltargets)) {
  6503. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6504. return 0;
  6505. }
  6506. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6507. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. if (!item)
  6511. spell = lua_interface->GetCurrentSpell(state);
  6512. if (!item && !spell) {
  6513. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6514. return 0;
  6515. }
  6516. if (spell && use_all_spelltargets) {
  6517. Spawn* target;
  6518. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6519. for (int8 i = 0; i < spell->targets.size(); i++) {
  6520. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6521. if (!target || !target->IsEntity())
  6522. continue;
  6523. ((Entity*)target)->AddProc(type, chance, item, spell);
  6524. }
  6525. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6526. }
  6527. else
  6528. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6529. return 0;
  6530. }
  6531. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6532. if (!lua_interface)
  6533. return 0;
  6534. Spawn* spawn = lua_interface->GetSpawn(state);
  6535. Item* item = lua_interface->GetItem(state, 2);
  6536. LuaSpell* spell = 0;
  6537. if (!spawn) {
  6538. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6539. return 0;
  6540. }
  6541. if (!spawn->IsEntity()) {
  6542. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. if (!item)
  6546. spell = lua_interface->GetCurrentSpell(state);
  6547. if (!item && !spell) {
  6548. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. if (spell) {
  6552. Spawn* target;
  6553. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6554. for (int8 i = 0; i < spell->targets.size(); i++) {
  6555. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6556. if (!target || !target->IsEntity())
  6557. continue;
  6558. ((Entity*)target)->RemoveProc(item, spell);
  6559. }
  6560. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6561. spell->caster->RemoveProc(item, spell);
  6562. }
  6563. else
  6564. ((Entity*)spawn)->RemoveProc(item, spell);
  6565. return 0;
  6566. }
  6567. int EQ2Emu_lua_Knockback(lua_State* state) {
  6568. if (!lua_interface)
  6569. return 0;
  6570. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6571. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6572. int32 duration = lua_interface->GetInt32Value(state, 3);
  6573. float vertical = lua_interface->GetFloatValue(state, 4);
  6574. float horizontal = lua_interface->GetFloatValue(state, 5);
  6575. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6576. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6577. if (!target_spawn) {
  6578. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6579. return 0;
  6580. }
  6581. if (!spawn) {
  6582. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6583. return 0;
  6584. }
  6585. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6586. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6587. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6588. if (packet) {
  6589. packet->setDataByName("target_x", target_spawn->GetX());
  6590. packet->setDataByName("target_y", target_spawn->GetY());
  6591. packet->setDataByName("target_z", target_spawn->GetZ());
  6592. packet->setDataByName("vertical_movement", vertical);
  6593. packet->setDataByName("horizontal_movement", horizontal);
  6594. if (use_heading)
  6595. packet->setDataByName("use_player_heading", 1);
  6596. client->QueuePacket(packet->serialize());
  6597. }
  6598. safe_delete(packet);
  6599. }
  6600. return 0;
  6601. }
  6602. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6603. if (!lua_interface)
  6604. return 0;
  6605. Spawn* spawn = lua_interface->GetSpawn(state);
  6606. if (!spawn) {
  6607. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6608. return 0;
  6609. }
  6610. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6611. return 1;
  6612. }
  6613. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6614. if (!lua_interface)
  6615. return 0;
  6616. Spawn* caster = lua_interface->GetSpawn(state);
  6617. Spawn* target = lua_interface->GetSpawn(state, 2);
  6618. string name = lua_interface->GetStringValue(state, 3);
  6619. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6620. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6621. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6622. string success_msg = lua_interface->GetStringValue(state, 7);
  6623. string effect_msg = lua_interface->GetStringValue(state, 8);
  6624. if (!caster) {
  6625. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6626. return 0;
  6627. }
  6628. if (!caster->IsEntity()) {
  6629. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6630. return 0;
  6631. }
  6632. if (!target) {
  6633. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6634. return 0;
  6635. }
  6636. if (!target->IsEntity()) {
  6637. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. if (name.length() == 0) {
  6641. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6642. return 0;
  6643. }
  6644. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6645. return 0;
  6646. }
  6647. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6648. if (!lua_interface)
  6649. return 0;
  6650. string name = lua_interface->GetStringValue(state);
  6651. if (name.length() == 0) {
  6652. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6653. return 0;
  6654. }
  6655. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6656. if (!skill) {
  6657. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6658. return 0;
  6659. }
  6660. lua_interface->SetInt32Value(state, skill->skill_id);
  6661. return 1;
  6662. }
  6663. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6664. if (!lua_interface)
  6665. return 0;
  6666. Spawn* spawn = lua_interface->GetSpawn(state);
  6667. if (!spawn) {
  6668. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6669. return 0;
  6670. }
  6671. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6672. return 1;
  6673. }
  6674. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6675. if (!lua_interface)
  6676. return 0;
  6677. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6678. if (!luaspell) {
  6679. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6683. return 1;
  6684. }
  6685. int EQ2Emu_lua_IsBehind(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. if (!spawn) {
  6691. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. if (!spawn->IsEntity()) {
  6695. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6696. return 0;
  6697. }
  6698. if (!target) {
  6699. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6700. return 0;
  6701. }
  6702. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6703. return 1;
  6704. }
  6705. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6706. if (!lua_interface)
  6707. return 0;
  6708. Spawn* spawn = lua_interface->GetSpawn(state);
  6709. Spawn* target = lua_interface->GetSpawn(state, 2);
  6710. if (!spawn) {
  6711. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6712. return 0;
  6713. }
  6714. if (!spawn->IsEntity()) {
  6715. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6716. return 0;
  6717. }
  6718. if (!target) {
  6719. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6720. return 0;
  6721. }
  6722. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6723. return 1;
  6724. }
  6725. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6726. if (!lua_interface)
  6727. return 0;
  6728. Item* item = lua_interface->GetItem(state);
  6729. if (!item) {
  6730. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6731. return 0;
  6732. }
  6733. lua_interface->SetInt32Value(state, item->details.count);
  6734. return 1;
  6735. }
  6736. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6737. if (!lua_interface)
  6738. return 0;
  6739. Item* item = lua_interface->GetItem(state);
  6740. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6741. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6742. if (!item) {
  6743. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6744. return 0;
  6745. }
  6746. if (!owner) {
  6747. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6748. return 0;
  6749. }
  6750. if (!owner->IsPlayer()) {
  6751. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6752. return 0;
  6753. }
  6754. if (item->stack_count < new_count) {
  6755. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6756. return 0;
  6757. }
  6758. if (new_count > 0) {
  6759. item->details.count = new_count;
  6760. item->save_needed = true;
  6761. }
  6762. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6763. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6764. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6765. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6766. else
  6767. {
  6768. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6769. return 0;
  6770. }
  6771. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6772. if (!client)
  6773. return 0;
  6774. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6775. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6776. if (app)
  6777. client->QueuePacket(app);
  6778. return 0;
  6779. }
  6780. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6781. if (!lua_interface)
  6782. return 0;
  6783. int32 time = lua_interface->GetInt32Value(state);
  6784. string function = lua_interface->GetStringValue(state, 2);
  6785. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6786. Spawn* target = lua_interface->GetSpawn(state, 4);
  6787. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6788. if (time == 0) {
  6789. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6790. return 0;
  6791. }
  6792. if (function.length() == 0) {
  6793. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. if (!spell) {
  6797. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6798. return 0;
  6799. }
  6800. SpellScriptTimer* timer = new SpellScriptTimer;
  6801. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6802. #ifdef WIN32
  6803. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6804. #else
  6805. bzero(timer, sizeof(SpellScriptTimer));
  6806. #endif*/
  6807. timer->caster = 0;
  6808. timer->deleteWhenDone = false;
  6809. timer->target = 0;
  6810. timer->time = Timer::GetCurrentTime2() + time;
  6811. timer->customFunction = function;
  6812. timer->spell = spell;
  6813. if (caster)
  6814. timer->caster = caster->GetID();
  6815. if (target)
  6816. timer->target = target->GetID();
  6817. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6818. return 0;
  6819. }
  6820. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6821. if (!lua_interface)
  6822. return 0;
  6823. float hp_perc = lua_interface->GetFloatValue(state);
  6824. float power_perc = lua_interface->GetFloatValue(state, 2);
  6825. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6826. Spawn* target = lua_interface->GetSpawn(state, 4);
  6827. string heal_name = lua_interface->GetStringValue(state, 5);
  6828. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6829. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6830. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6831. if (!spell) {
  6832. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. Entity* caster = spell->caster;
  6836. if (!caster) {
  6837. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. Client* client = 0;
  6841. PendingResurrection* rez = 0;
  6842. ZoneServer* zone = spell->caster->GetZone();
  6843. if (!target) {
  6844. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6845. if (spell->targets.size() > 0) {
  6846. vector<int32> spell_targets = spell->targets;
  6847. for (int8 i = 0; i < spell_targets.size(); i++) {
  6848. target = zone->GetSpawnByID(spell_targets.at(i));
  6849. if (!target)
  6850. continue;
  6851. if (!target->IsPlayer())
  6852. continue;
  6853. client = target->GetZone()->GetClientBySpawn(target);
  6854. if (!client)
  6855. continue;
  6856. rez = client->GetCurrentRez();
  6857. if (rez->active)
  6858. continue;
  6859. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6860. rez->active = true;
  6861. rez->caster = caster;
  6862. rez->expire_timer = new Timer;
  6863. int32 duration = spell->spell->GetSpellDuration();
  6864. rez->expire_timer->Start(duration * 100);
  6865. rez->hp_perc = hp_perc;
  6866. rez->mp_perc = power_perc;
  6867. rez->range = spell->spell->GetSpellData()->range;
  6868. rez->spell_name = spell->spell->GetName();
  6869. if (heal_name.length() > 0)
  6870. rez->heal_name = heal_name;
  6871. else
  6872. rez->heal_name = rez->spell_name;
  6873. rez->no_calcs = no_calcs;
  6874. rez->crit_mod = crit_mod;
  6875. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6876. if (send_window)
  6877. client->SendResurrectionWindow();
  6878. else {
  6879. target->GetZone()->ResurrectSpawn(target, client);
  6880. rez->should_delete = true;
  6881. }
  6882. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6883. }
  6884. }
  6885. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6886. }
  6887. else {
  6888. client = target->GetZone()->GetClientBySpawn(target);
  6889. if (!client)
  6890. return 0;
  6891. rez = client->GetCurrentRez();
  6892. if (rez->active)
  6893. return 0;
  6894. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6895. rez->active = true;
  6896. rez->caster = caster;
  6897. rez->expire_timer = new Timer;
  6898. int32 duration = spell->spell->GetSpellDuration();
  6899. rez->expire_timer->Start(duration * 100);
  6900. rez->hp_perc = hp_perc;
  6901. rez->mp_perc = power_perc;
  6902. rez->range = spell->spell->GetSpellData()->range;
  6903. rez->spell_name = spell->spell->GetName();
  6904. if (heal_name.length() > 0)
  6905. rez->heal_name = heal_name;
  6906. else
  6907. rez->heal_name = rez->spell_name;
  6908. rez->no_calcs = no_calcs;
  6909. rez->crit_mod = crit_mod;
  6910. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6911. if (send_window)
  6912. client->SendResurrectionWindow();
  6913. else {
  6914. target->GetZone()->ResurrectSpawn(target, client);
  6915. rez->should_delete = true;
  6916. }
  6917. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6918. }
  6919. return 0;
  6920. }
  6921. int EQ2Emu_lua_SetVision(lua_State* state) {
  6922. if (!lua_interface)
  6923. return 0;
  6924. Spawn* spawn = lua_interface->GetSpawn(state);
  6925. int8 vision = lua_interface->GetInt8Value(state, 2);
  6926. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6927. if (!spawn) {
  6928. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6929. return 0;
  6930. }
  6931. if (!spawn->IsEntity()) {
  6932. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6933. return 0;
  6934. }
  6935. if (spell && spell->targets.size() > 0) {
  6936. ZoneServer* zone = spell->caster->GetZone();
  6937. for (int8 i = 0; i < spell->targets.size(); i++) {
  6938. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6939. if (target->IsEntity()) {
  6940. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6941. if (target->IsPlayer())
  6942. ((Player*)target)->SetCharSheetChanged(true);
  6943. }
  6944. }
  6945. }
  6946. else {
  6947. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6948. if (spawn->IsPlayer())
  6949. ((Player*)spawn)->SetCharSheetChanged(true);
  6950. }
  6951. return 0;
  6952. }
  6953. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6954. if (!lua_interface)
  6955. return 0;
  6956. Spawn* spawn = lua_interface->GetSpawn(state);
  6957. float intensity = lua_interface->GetFloatValue(state, 2);
  6958. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6959. if (!spawn) {
  6960. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6961. return 0;
  6962. }
  6963. if (!spawn->IsEntity()) {
  6964. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6965. return 0;
  6966. }
  6967. if (spell && spell->targets.size() > 0) {
  6968. ZoneServer* zone = spell->caster->GetZone();
  6969. for (int8 i = 0; i < spell->targets.size(); i++) {
  6970. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6971. if (target && target->IsEntity()) {
  6972. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6973. if (target->IsPlayer())
  6974. ((Player*)target)->SetCharSheetChanged(true);
  6975. }
  6976. }
  6977. }
  6978. else {
  6979. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6980. if (spawn->IsPlayer())
  6981. ((Player*)spawn)->SetCharSheetChanged(true);
  6982. }
  6983. return 0;
  6984. }
  6985. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6986. if (!lua_interface)
  6987. return 0;
  6988. Spawn* spawn = lua_interface->GetSpawn(state);
  6989. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6990. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6991. if (!spawn) {
  6992. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. if (!spawn->IsEntity()) {
  6996. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6997. return 0;
  6998. }
  6999. if (spell && spell->targets.size() > 0) {
  7000. ZoneServer* zone = spell->caster->GetZone();
  7001. for (int8 i = 0; i < spell->targets.size(); i++) {
  7002. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7003. if (target->IsEntity()) {
  7004. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7005. if (target->IsPlayer())
  7006. ((Player*)target)->SetCharSheetChanged(true);
  7007. }
  7008. }
  7009. }
  7010. else {
  7011. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7012. if (spawn->IsPlayer())
  7013. ((Player*)spawn)->SetCharSheetChanged(true);
  7014. }
  7015. return 0;
  7016. }
  7017. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7018. if (!lua_interface)
  7019. return 0;
  7020. Item* item = lua_interface->GetItem(state);
  7021. int8 type = lua_interface->GetInt32Value(state, 2);
  7022. if (!item) {
  7023. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7024. return 0;
  7025. }
  7026. if (type == 1)
  7027. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7028. else if (type == 2)
  7029. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7030. return 1;
  7031. }
  7032. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7033. if (!lua_interface)
  7034. return 0;
  7035. Spawn* target = lua_interface->GetSpawn(state);
  7036. float val = lua_interface->GetFloatValue(state, 2);
  7037. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7038. // Added from Gangrenous post
  7039. if (spell && spell->resisted)
  7040. return 0;
  7041. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7042. if (val > 1.0f)
  7043. val = 1.0f - (val / 100.0f);
  7044. if (spell && spell->spell && spell->targets.size() > 0) {
  7045. ZoneServer* zone = spell->caster->GetZone();
  7046. for (int32 i = 0; i != spell->targets.size(); i++) {
  7047. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7048. if (spawn && spawn->IsEntity()) {
  7049. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7050. if (spawn->IsPlayer())
  7051. ((Player*)spawn)->SetCharSheetChanged(true);
  7052. }
  7053. }
  7054. }
  7055. else {
  7056. if (target && target->IsEntity()) {
  7057. ((Entity*)target)->SetSpeedMultiplier(val);
  7058. if (target->IsPlayer())
  7059. ((Player*)target)->SetCharSheetChanged(true);
  7060. }
  7061. }
  7062. return 0;
  7063. }
  7064. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7065. if (!lua_interface)
  7066. return 0;
  7067. Spawn* spawn = lua_interface->GetSpawn(state);
  7068. int16 model = lua_interface->GetInt16Value(state, 2);
  7069. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7070. if (spell && spell->spell && spell->targets.size() > 0) {
  7071. ZoneServer* zone = spell->caster->GetZone();
  7072. for (int32 i = 0; i < spell->targets.size(); i++) {
  7073. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7074. if (target)
  7075. target->SetIllusionModel(model);
  7076. }
  7077. }
  7078. else {
  7079. if (!spawn) {
  7080. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7081. return 0;
  7082. }
  7083. spawn->SetIllusionModel(model);
  7084. }
  7085. return 0;
  7086. }
  7087. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7088. if (!lua_interface)
  7089. return 0;
  7090. Spawn* spawn = lua_interface->GetSpawn(state);
  7091. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7092. if (spell && spell->spell && spell->targets.size() > 0) {
  7093. ZoneServer* zone = spell->caster->GetZone();
  7094. for (int32 i = 0; i < spell->targets.size(); i++) {
  7095. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7096. if (target)
  7097. target->SetIllusionModel(0);
  7098. }
  7099. }
  7100. else {
  7101. if (!spawn) {
  7102. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7103. return 0;
  7104. }
  7105. spawn->SetIllusionModel(0);
  7106. }
  7107. return 0;
  7108. }
  7109. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7110. if (!lua_interface)
  7111. return 0;
  7112. Spawn* caster = lua_interface->GetSpawn(state);
  7113. Spawn* target = lua_interface->GetSpawn(state, 2);
  7114. float chance = lua_interface->GetFloatValue(state, 3);
  7115. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7116. if (!caster) {
  7117. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!caster->IsEntity()) {
  7121. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (!target) {
  7125. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. if (!target->IsEntity()) {
  7129. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7130. return 0;
  7131. }
  7132. if (chance <= 0) {
  7133. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. if (!spell) {
  7137. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7138. return 0;
  7139. }
  7140. if (((Entity*)caster)->GetThreatTransfer()) {
  7141. return 0;
  7142. }
  7143. ThreatTransfer* transfer = new ThreatTransfer;
  7144. transfer->Target = target->GetID();
  7145. transfer->Amount = chance;
  7146. transfer->Spell = spell;
  7147. ((Entity*)caster)->SetThreatTransfer(transfer);
  7148. return 0;
  7149. }
  7150. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7151. if (!lua_interface)
  7152. return 0;
  7153. Spawn* spawn = lua_interface->GetSpawn(state);
  7154. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7155. if (!spawn) {
  7156. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. if (!spell) {
  7160. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7161. return 0;
  7162. }
  7163. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7164. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7165. ((Entity*)spawn)->SetThreatTransfer(0);
  7166. safe_delete(transfer);
  7167. }
  7168. return 0;
  7169. }
  7170. int EQ2Emu_lua_CureByType(lua_State* state) {
  7171. if (!lua_interface)
  7172. return 0;
  7173. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7174. if (!spell) {
  7175. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7176. return 0;
  7177. }
  7178. int8 cure_count = lua_interface->GetInt8Value(state);
  7179. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7180. string cure_name = lua_interface->GetStringValue(state, 3);
  7181. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7182. Spawn* target = lua_interface->GetSpawn(state, 5);
  7183. if (target) {
  7184. if (!target->IsEntity()) {
  7185. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7186. return 0;
  7187. }
  7188. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7189. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7190. }
  7191. else {
  7192. ZoneServer* zone = spell->caster->GetZone();
  7193. vector<int32> targets = spell->targets;
  7194. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7195. for (int8 i = 0; i < targets.size(); i++) {
  7196. target = zone->GetSpawnByID(targets.at(i));
  7197. if (!target || !target->IsEntity())
  7198. continue;
  7199. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7200. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7201. }
  7202. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7203. }
  7204. return 0;
  7205. }
  7206. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7207. if (!lua_interface)
  7208. return 0;
  7209. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7210. if (!spell) {
  7211. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7212. return 0;
  7213. }
  7214. int8 cure_count = lua_interface->GetInt8Value(state);
  7215. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7216. string cure_name = lua_interface->GetStringValue(state, 3);
  7217. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7218. Spawn* target = lua_interface->GetSpawn(state, 5);
  7219. if (target) {
  7220. if (!target->IsEntity()) {
  7221. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7222. return 0;
  7223. }
  7224. if (((Entity*)target)->GetDetCount() > 0)
  7225. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7226. }
  7227. else {
  7228. ZoneServer* zone = spell->caster->GetZone();
  7229. vector<int32> targets = spell->targets;
  7230. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7231. for (int8 i = 0; i < targets.size(); i++) {
  7232. target = zone->GetSpawnByID(targets.at(i));
  7233. if (!target || !target->IsEntity())
  7234. continue;
  7235. if (((Entity*)target)->GetDetCount() > 0)
  7236. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7237. }
  7238. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7239. }
  7240. return 0;
  7241. }
  7242. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7243. if (!lua_interface)
  7244. return 0;
  7245. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7246. if (!spell) {
  7247. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. if (!spell->caster) {
  7251. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7252. return 0;
  7253. }
  7254. if (!spell->caster->GetZone()) {
  7255. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7256. return 0;
  7257. }
  7258. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7259. return 0;
  7260. }
  7261. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7262. if (!lua_interface)
  7263. return 0;
  7264. Spawn* spawn = lua_interface->GetSpawn(state);
  7265. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7266. if (!spell) {
  7267. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if (spawn && spawn->IsEntity())
  7271. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7272. else {
  7273. ZoneServer* zone = spell->caster->GetZone();
  7274. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7275. for (int32 i = 0; i < spell->targets.size(); i++) {
  7276. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7277. if (!spawn || !spawn->IsEntity())
  7278. continue;
  7279. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7280. }
  7281. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7282. }
  7283. return 0;
  7284. }
  7285. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7286. if (!lua_interface)
  7287. return 0;
  7288. Spawn* spawn = lua_interface->GetSpawn(state);
  7289. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7290. if (!spell) {
  7291. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7292. return 0;
  7293. }
  7294. if (spawn && spawn->IsEntity())
  7295. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7296. else {
  7297. ZoneServer* zone = spell->caster->GetZone();
  7298. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7299. for (int32 i = 0; i < spell->targets.size(); i++) {
  7300. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7301. if (!spawn || !spawn->IsEntity())
  7302. continue;
  7303. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7304. }
  7305. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7306. }
  7307. return 0;
  7308. }
  7309. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7310. if (!lua_interface)
  7311. return 0;
  7312. Spawn* caster = lua_interface->GetSpawn(state);
  7313. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7314. if (!caster) {
  7315. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7316. return 0;
  7317. }
  7318. if (!caster->IsPlayer()) {
  7319. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7320. return 0;
  7321. }
  7322. Spawn* target = caster->GetTarget();
  7323. if (!target) {
  7324. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7325. return 0;
  7326. }
  7327. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7328. if (!client) {
  7329. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7330. return 0;
  7331. }
  7332. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7333. if (ho) {
  7334. ho->SetTarget(target->GetID());
  7335. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7336. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7337. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7338. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7339. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7340. deque<GroupMemberInfo*>::iterator itr;
  7341. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7342. if (group)
  7343. {
  7344. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7345. deque<GroupMemberInfo*>* members = group->GetMembers();
  7346. for (itr = members->begin(); itr != members->end(); itr++) {
  7347. if ((*itr)->client)
  7348. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7349. }
  7350. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7351. }
  7352. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7353. }
  7354. else
  7355. safe_delete(ho);
  7356. }
  7357. else {
  7358. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7359. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7360. }
  7361. else
  7362. safe_delete(ho);
  7363. }
  7364. }
  7365. return 0;
  7366. }
  7367. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7368. if (!lua_interface)
  7369. return 0;
  7370. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7371. if (!spell) {
  7372. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7373. return 0;
  7374. }
  7375. int16 triggerCount = lua_interface->GetInt16Value(state);
  7376. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7377. if (!triggerCount) {
  7378. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. spell->num_triggers = triggerCount;
  7382. spell->had_triggers = true;
  7383. spell->cancel_after_all_triggers = cancel_after_triggers;
  7384. return 0;
  7385. }
  7386. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7387. if (!lua_interface)
  7388. return 0;
  7389. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7390. if (!spell) {
  7391. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7392. return 0;
  7393. }
  7394. lua_interface->SetInt32Value(state, spell->num_triggers);
  7395. return 1;
  7396. }
  7397. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7398. if (!lua_interface)
  7399. return 0;
  7400. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7401. if (!spell) {
  7402. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7403. return 0;
  7404. }
  7405. int16 remove_count = lua_interface->GetInt16Value(state);
  7406. if (!remove_count)
  7407. remove_count = 1;
  7408. if (remove_count >= spell->num_triggers) {
  7409. spell->num_triggers = 0;
  7410. if (spell->cancel_after_all_triggers)
  7411. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7412. }
  7413. else {
  7414. spell->num_triggers -= remove_count;
  7415. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7416. }
  7417. return 0;
  7418. }
  7419. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7420. if (!lua_interface)
  7421. return 0;
  7422. Spawn* spawn = lua_interface->GetSpawn(state);
  7423. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7424. if (!spawn) {
  7425. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7426. return 0;
  7427. }
  7428. if (!copy_spawn) {
  7429. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. spawn->CopySpawnAppearance(copy_spawn);
  7433. return 0;
  7434. }
  7435. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7436. if (!lua_interface)
  7437. return 0;
  7438. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7439. int8 type = lua_interface->GetInt8Value(state);
  7440. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7441. if (!spell) {
  7442. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7443. return 0;
  7444. }
  7445. if (spawn) {
  7446. if (!spawn->IsEntity()) {
  7447. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7448. return 0;
  7449. }
  7450. Entity* entity = ((Entity*)spawn);
  7451. switch (type) {
  7452. case IMMUNITY_TYPE_AOE:
  7453. entity->AddAOEImmunity(spell);
  7454. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7455. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7456. break;
  7457. case IMMUNITY_TYPE_STUN:
  7458. entity->AddStunImmunity(spell);
  7459. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7460. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7461. break;
  7462. case IMMUNITY_TYPE_ROOT:
  7463. entity->AddRootImmunity(spell);
  7464. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7465. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7466. break;
  7467. case IMMUNITY_TYPE_DAZE:
  7468. entity->AddDazeImmunity(spell);
  7469. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7470. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7471. break;
  7472. case IMMUNITY_TYPE_FEAR:
  7473. entity->AddFearImmunity(spell);
  7474. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7475. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7476. break;
  7477. case IMMUNITY_TYPE_MEZ:
  7478. entity->AddMezImmunity(spell);
  7479. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7480. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7481. break;
  7482. case IMMUNITY_TYPE_STIFLE:
  7483. entity->AddStifleImmunity(spell);
  7484. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7485. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7486. break;
  7487. default:
  7488. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7489. }
  7490. }
  7491. else {
  7492. bool should_break = false;
  7493. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7494. for (int8 i = 0; i < spell->targets.size(); i++) {
  7495. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7496. if (!spawn || !spawn->IsEntity())
  7497. continue;
  7498. Entity* entity = ((Entity*)spawn);
  7499. switch (type) {
  7500. case IMMUNITY_TYPE_AOE:
  7501. entity->AddAOEImmunity(spell);
  7502. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7503. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7504. break;
  7505. case IMMUNITY_TYPE_STUN:
  7506. entity->AddStunImmunity(spell);
  7507. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7508. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7509. break;
  7510. case IMMUNITY_TYPE_ROOT:
  7511. entity->AddRootImmunity(spell);
  7512. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7513. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7514. break;
  7515. case IMMUNITY_TYPE_DAZE:
  7516. entity->AddDazeImmunity(spell);
  7517. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7518. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7519. break;
  7520. case IMMUNITY_TYPE_FEAR:
  7521. entity->AddFearImmunity(spell);
  7522. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7523. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7524. break;
  7525. case IMMUNITY_TYPE_MEZ:
  7526. entity->AddMezImmunity(spell);
  7527. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7528. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7529. break;
  7530. case IMMUNITY_TYPE_STIFLE:
  7531. entity->AddStifleImmunity(spell);
  7532. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7533. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7534. break;
  7535. default:
  7536. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7537. should_break = true;
  7538. }
  7539. if (should_break)
  7540. break;
  7541. }
  7542. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7543. }
  7544. return 0;
  7545. }
  7546. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7547. if (!lua_interface)
  7548. return 0;
  7549. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7550. int8 type = lua_interface->GetInt8Value(state);
  7551. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7552. if (!spell) {
  7553. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7554. return 0;
  7555. }
  7556. if (spawn) {
  7557. if (!spawn->IsEntity()) {
  7558. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7559. return 0;
  7560. }
  7561. Entity* entity = ((Entity*)spawn);
  7562. switch (type) {
  7563. case IMMUNITY_TYPE_AOE:
  7564. entity->RemoveAOEImmunity(spell);
  7565. break;
  7566. case IMMUNITY_TYPE_STUN:
  7567. entity->RemoveStunImmunity(spell);
  7568. break;
  7569. case IMMUNITY_TYPE_ROOT:
  7570. entity->RemoveRootImmunity(spell);
  7571. break;
  7572. case IMMUNITY_TYPE_DAZE:
  7573. entity->RemoveDazeImmunity(spell);
  7574. break;
  7575. case IMMUNITY_TYPE_FEAR:
  7576. entity->RemoveFearImmunity(spell);
  7577. break;
  7578. case IMMUNITY_TYPE_MEZ:
  7579. entity->RemoveMezImmunity(spell);
  7580. break;
  7581. case IMMUNITY_TYPE_STIFLE:
  7582. entity->RemoveStifleImmunity(spell);
  7583. break;
  7584. default:
  7585. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7586. }
  7587. }
  7588. else {
  7589. bool should_break = false;
  7590. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7591. for (int8 i = 0; i < spell->targets.size(); i++) {
  7592. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7593. if (!spawn || !spawn->IsEntity())
  7594. continue;
  7595. Entity* entity = ((Entity*)spawn);
  7596. switch (type) {
  7597. case IMMUNITY_TYPE_AOE:
  7598. entity->RemoveAOEImmunity(spell);
  7599. break;
  7600. case IMMUNITY_TYPE_STUN:
  7601. entity->RemoveStunImmunity(spell);
  7602. break;
  7603. case IMMUNITY_TYPE_ROOT:
  7604. entity->RemoveRootImmunity(spell);
  7605. break;
  7606. case IMMUNITY_TYPE_DAZE:
  7607. entity->RemoveDazeImmunity(spell);
  7608. break;
  7609. case IMMUNITY_TYPE_FEAR:
  7610. entity->RemoveFearImmunity(spell);
  7611. break;
  7612. case IMMUNITY_TYPE_MEZ:
  7613. entity->RemoveMezImmunity(spell);
  7614. break;
  7615. case IMMUNITY_TYPE_STIFLE:
  7616. entity->RemoveStifleImmunity(spell);
  7617. break;
  7618. default:
  7619. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7620. should_break = true;
  7621. }
  7622. if (should_break)
  7623. break;
  7624. }
  7625. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7626. }
  7627. return 0;
  7628. }
  7629. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7630. if (!lua_interface)
  7631. return 0;
  7632. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7633. if (!spell) {
  7634. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7635. return 0;
  7636. }
  7637. float snare = lua_interface->GetFloatValue(state);
  7638. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7639. // convert the val to the speed multipler value (100 - val)
  7640. float val = 100.0 - snare;
  7641. val /= 100.0;
  7642. if (spawn) {
  7643. if (!spawn->IsEntity()) {
  7644. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7645. return 0;
  7646. }
  7647. ((Entity*)spawn)->SetSnareValue(spell, val);
  7648. }
  7649. else {
  7650. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7651. for (int8 i = 0; i < spell->targets.size(); i++) {
  7652. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7653. if (!spawn || !spawn->IsEntity())
  7654. continue;
  7655. ((Entity*)spawn)->SetSnareValue(spell, val);
  7656. }
  7657. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7658. }
  7659. return 0;
  7660. }
  7661. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7662. if (!lua_interface)
  7663. return 0;
  7664. Spawn* spawn = lua_interface->GetSpawn(state);
  7665. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7666. if (!spawn) {
  7667. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. if (race_id == 0) {
  7671. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7672. return 0;
  7673. }
  7674. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7675. return 1;
  7676. }
  7677. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7678. if (!lua_interface)
  7679. return 0;
  7680. Spawn* spawn = lua_interface->GetSpawn(state);
  7681. if (!spawn) {
  7682. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7683. return 0;
  7684. }
  7685. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7686. return 1;
  7687. }
  7688. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Spawn* spawn = lua_interface->GetSpawn(state);
  7692. if (!spawn) {
  7693. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7694. return 0;
  7695. }
  7696. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7697. return 1;
  7698. }
  7699. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7700. if (!lua_interface)
  7701. return 0;
  7702. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7703. if (!spell) {
  7704. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. lua_interface->SetStringValue(state, spell->spell->GetName());
  7708. return 1;
  7709. }
  7710. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7711. if (!lua_interface)
  7712. return 0;
  7713. Quest* quest = lua_interface->GetQuest(state);
  7714. if (!quest) {
  7715. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7716. return 0;
  7717. }
  7718. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7719. return 1;
  7720. }
  7721. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. Quest* quest = lua_interface->GetQuest(state);
  7725. int32 flags = lua_interface->GetInt32Value(state, 2);
  7726. if (!quest) {
  7727. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7728. return 0;
  7729. }
  7730. quest->SetQuestFlags(flags);
  7731. return 0;
  7732. }
  7733. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7734. if (!lua_interface)
  7735. return 0;
  7736. Quest* quest = lua_interface->GetQuest(state);
  7737. Spawn* player = lua_interface->GetSpawn(state, 2);
  7738. int32 step = lua_interface->GetInt32Value(state, 3);
  7739. int32 duration = lua_interface->GetInt32Value(state, 4);
  7740. string action = lua_interface->GetStringValue(state, 5);
  7741. if (!quest) {
  7742. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7743. return 0;
  7744. }
  7745. if (!player) {
  7746. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7747. return 0;
  7748. }
  7749. if (!player->IsPlayer()) {
  7750. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7751. return 0;
  7752. }
  7753. if (step == 0) {
  7754. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (duration == 0) {
  7758. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. if (action.length() == 0) {
  7762. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7763. return 0;
  7764. }
  7765. Client* client = player->GetZone()->GetClientBySpawn(player);
  7766. if (!client) {
  7767. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. quest->SetTimerStep(step);
  7771. quest->AddFailedAction(step, action);
  7772. quest->SetStepTimer(duration);
  7773. client->AddQuestTimer(quest->GetQuestID());
  7774. return 0;
  7775. }
  7776. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7777. if (!lua_interface)
  7778. return 0;
  7779. Quest* quest = lua_interface->GetQuest(state);
  7780. Spawn* player = lua_interface->GetSpawn(state, 2);
  7781. if (!quest) {
  7782. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7783. return 0;
  7784. }
  7785. if (!player) {
  7786. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7787. return 0;
  7788. }
  7789. if (!player->IsPlayer()) {
  7790. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7791. return 0;
  7792. }
  7793. Client* client = player->GetZone()->GetClientBySpawn(player);
  7794. if (!client) {
  7795. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7796. return 0;
  7797. }
  7798. quest->SetTimerStep(0);
  7799. quest->SetStepTimer(0);
  7800. client->RemoveQuestTimer(quest->GetQuestID());
  7801. return 0;
  7802. }
  7803. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* player = lua_interface->GetSpawn(state);
  7807. Quest* quest = lua_interface->GetQuest(state, 2);
  7808. int32 step = lua_interface->GetInt32Value(state, 3);
  7809. if (!player) {
  7810. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7811. return 0;
  7812. }
  7813. if (!player->IsPlayer()) {
  7814. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7815. return 0;
  7816. }
  7817. if (!quest) {
  7818. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7819. return 0;
  7820. }
  7821. if (step == 0) {
  7822. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. Client* client = player->GetZone()->GetClientBySpawn(player);
  7826. if (!client) {
  7827. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7828. return 0;
  7829. }
  7830. if (quest->RemoveQuestStep(step, client)) {
  7831. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7832. client->GetCurrentZone()->SendQuestUpdates(client);
  7833. }
  7834. else
  7835. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7836. return 0;
  7837. }
  7838. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7839. if (!lua_interface)
  7840. return 0;
  7841. Quest* quest = lua_interface->GetQuest(state, 1);
  7842. int32 step = lua_interface->GetInt32Value(state, 2);
  7843. string desc = lua_interface->GetStringValue(state, 3);
  7844. string task_group = lua_interface->GetStringValue(state, 4);
  7845. if (!quest) {
  7846. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7847. return 0;
  7848. }
  7849. if (step == 0) {
  7850. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7851. return 0;
  7852. }
  7853. QuestStep* quest_step = quest->GetQuestStep(step);
  7854. if (!quest_step) {
  7855. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7856. return 0;
  7857. }
  7858. quest_step->SetStepProgress(0);
  7859. quest_step->SetTaskGroup(task_group);
  7860. quest_step->SetDescription(desc);
  7861. return 0;
  7862. }
  7863. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7864. if (!lua_interface)
  7865. return 0;
  7866. Quest* quest = lua_interface->GetQuest(state);
  7867. int32 step = lua_interface->GetInt32Value(state, 2);
  7868. string action = lua_interface->GetStringValue(state, 3);
  7869. if (!quest) {
  7870. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7871. return 0;
  7872. }
  7873. if (step == 0) {
  7874. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7875. return 0;
  7876. }
  7877. if (action.length() == 0) {
  7878. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7879. return 0;
  7880. }
  7881. quest->AddFailedAction(step, action);
  7882. return 0;
  7883. }
  7884. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7885. if (!lua_interface)
  7886. return 0;
  7887. Spawn* player = lua_interface->GetSpawn(state);
  7888. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7889. int32 step = lua_interface->GetInt32Value(state, 3);
  7890. if (!player) {
  7891. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7892. return 0;
  7893. }
  7894. if (!player->IsPlayer()) {
  7895. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7896. return 0;
  7897. }
  7898. if (quest_id == 0) {
  7899. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7900. return 0;
  7901. }
  7902. if (step == 0) {
  7903. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7904. return 0;
  7905. }
  7906. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7907. if (!quest) {
  7908. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7909. return 0;
  7910. }
  7911. quest->StepFailed(step);
  7912. return 0;
  7913. }
  7914. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7915. if (!lua_interface)
  7916. return 0;
  7917. Spawn* player = lua_interface->GetSpawn(state);
  7918. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7919. if (!player) {
  7920. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7921. return 0;
  7922. }
  7923. if (!player->IsPlayer()) {
  7924. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7925. return 0;
  7926. }
  7927. if (quest_id == 0) {
  7928. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7929. return 0;
  7930. }
  7931. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7932. if (!quest) {
  7933. lua_interface->SetInt32Value(state, 0);
  7934. return 1;
  7935. }
  7936. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7937. return 1;
  7938. }
  7939. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7940. if (!lua_interface)
  7941. return 0;
  7942. string name = lua_interface->GetStringValue(state);
  7943. string value = lua_interface->GetStringValue(state, 2);
  7944. string comment = lua_interface->GetStringValue(state, 3);
  7945. if (name.length() == 0) {
  7946. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7947. return 0;
  7948. }
  7949. if (value.length() == 0) {
  7950. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7951. return 0;
  7952. }
  7953. string varname = string("lua_").append(name);
  7954. Variable* var = variables.FindVariable(varname);
  7955. if (var)
  7956. var->SetValue(value.c_str());
  7957. else {
  7958. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7959. variables.AddVariable(var);
  7960. }
  7961. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7962. return 0;
  7963. }
  7964. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7965. if (!lua_interface)
  7966. return 0;
  7967. string name = lua_interface->GetStringValue(state);
  7968. if (name.length() == 0) {
  7969. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7970. return 0;
  7971. }
  7972. string varname = string("lua_").append(name);
  7973. Variable* var = variables.FindVariable(varname);
  7974. if (var)
  7975. lua_interface->SetStringValue(state, var->GetValue());
  7976. else
  7977. lua_interface->SetStringValue(state, "NULL");
  7978. return 1;
  7979. }
  7980. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7981. if (!lua_interface)
  7982. return 0;
  7983. Spawn* player = lua_interface->GetSpawn(state);
  7984. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7985. if (!player) {
  7986. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7987. return 0;
  7988. }
  7989. if (!player->IsPlayer()) {
  7990. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7991. return 0;
  7992. }
  7993. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7994. return 1;
  7995. }
  7996. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7997. if (!lua_interface)
  7998. return 0;
  7999. Spawn* player = lua_interface->GetSpawn(state);
  8000. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8001. if (!player) {
  8002. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8003. return 0;
  8004. }
  8005. if (!player->IsPlayer()) {
  8006. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. Language* language = master_languages_list.GetLanguage(language_id);
  8010. if (language)
  8011. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8012. return 0;
  8013. }
  8014. int EQ2Emu_lua_IsNight(lua_State* state) {
  8015. if (!lua_interface)
  8016. return 0;
  8017. ZoneServer* zone = lua_interface->GetZone(state);
  8018. if (!zone) {
  8019. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8020. return 0;
  8021. }
  8022. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8023. return 1;
  8024. }
  8025. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8026. if (!lua_interface)
  8027. return 0;
  8028. Spawn* spawn = lua_interface->GetSpawn(state);
  8029. if (!spawn) {
  8030. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. if (!spawn->IsWidget()) {
  8034. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. ((Widget*)spawn)->SetMultiFloorLift(true);
  8038. if (spawn->GetZone())
  8039. spawn->GetZone()->AddTransportSpawn(spawn);
  8040. return 0;
  8041. }
  8042. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8043. if (!lua_interface)
  8044. return 0;
  8045. Spawn* player = lua_interface->GetSpawn(state);
  8046. int32 path = lua_interface->GetInt32Value(state, 2);
  8047. if (!player) {
  8048. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8049. return 0;
  8050. }
  8051. if (!player->IsPlayer()) {
  8052. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8053. return 0;
  8054. }
  8055. if (path == 0) {
  8056. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8057. return 0;
  8058. }
  8059. Client* client = player->GetZone()->GetClientBySpawn(player);
  8060. if (!client) {
  8061. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. client->SendFlightAutoMount(path);
  8065. return 0;
  8066. }
  8067. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8068. if (!lua_interface)
  8069. return 0;
  8070. Spawn* player = lua_interface->GetSpawn(state);
  8071. if (!player) {
  8072. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8073. return 0;
  8074. }
  8075. if (!player->IsPlayer()) {
  8076. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8077. return 0;
  8078. }
  8079. Client* client = player->GetZone()->GetClientBySpawn(player);
  8080. if (!client) {
  8081. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8082. return 0;
  8083. }
  8084. client->EndAutoMount();
  8085. return 0;
  8086. }
  8087. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8088. if (!lua_interface)
  8089. return 0;
  8090. Spawn* player = lua_interface->GetSpawn(state);
  8091. if (!player) {
  8092. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8093. return 0;
  8094. }
  8095. if (!player->IsPlayer()) {
  8096. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. Client* client = player->GetZone()->GetClientBySpawn(player);
  8100. if (!client) {
  8101. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8105. return 1;
  8106. }
  8107. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8108. if (!lua_interface)
  8109. return 0;
  8110. Spawn* player = lua_interface->GetSpawn(state);
  8111. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8112. int32 value = lua_interface->GetInt32Value(state, 3);
  8113. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8114. if (!player) {
  8115. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. if (!player->IsPlayer()) {
  8119. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8120. return 0;
  8121. }
  8122. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8123. return 0;
  8124. }
  8125. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8126. if (!lua_interface)
  8127. return 0;
  8128. Spawn* player = lua_interface->GetSpawn(state);
  8129. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8130. if (!player) {
  8131. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. if (!player->IsPlayer()) {
  8135. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8136. return 0;
  8137. }
  8138. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8139. if (!hd)
  8140. return 0;
  8141. lua_interface->SetInt32Value(state, hd->Value);
  8142. lua_interface->SetInt32Value(state, hd->Value2);
  8143. return 2;
  8144. }
  8145. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8146. if (!lua_interface)
  8147. return 0;
  8148. Spawn* spawn = lua_interface->GetSpawn(state);
  8149. int32 grid = lua_interface->GetInt32Value(state, 2);
  8150. if (!spawn) {
  8151. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8152. return 0;
  8153. }
  8154. if (grid == 0) {
  8155. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8159. return 0;
  8160. }
  8161. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8162. if (!lua_interface)
  8163. return 0;
  8164. Spawn* spawn = lua_interface->GetSpawn(state);
  8165. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8166. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8167. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8168. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8169. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8170. if (!spawn) {
  8171. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8172. return 0;
  8173. }
  8174. //Add this quest to the list of required quests for this spawn
  8175. spawn->SetRequiredHistory(event_id, value1, value2);
  8176. //If private spawn value set
  8177. if (private_spawn) {
  8178. //Set the spawn to be private when not granted access via history
  8179. spawn->AddAllowAccessSpawn(spawn);
  8180. spawn->SetPrivateQuestSpawn(true);
  8181. }
  8182. //This value will override vis_flags in the vis packet
  8183. if (flag_override > 0)
  8184. spawn->SetQuestsRequiredOverride(flag_override);
  8185. return 0;
  8186. }
  8187. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8188. if (!lua_interface)
  8189. return 0;
  8190. Spawn* player = lua_interface->GetSpawn(state);
  8191. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8192. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8193. if (!player) {
  8194. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8195. return 0;
  8196. }
  8197. if (!player->IsPlayer()) {
  8198. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8199. return 0;
  8200. }
  8201. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8202. return 1;
  8203. }
  8204. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8205. if (!lua_interface)
  8206. return 0;
  8207. Spawn* player = lua_interface->GetSpawn(state);
  8208. int8 level = lua_interface->GetInt8Value(state, 2);
  8209. if (!player) {
  8210. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8211. return 0;
  8212. }
  8213. if (!player->IsPlayer()) {
  8214. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8215. return 0;
  8216. }
  8217. if (level == 0) {
  8218. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8219. return 0;
  8220. }
  8221. Client* client = player->GetZone()->GetClientBySpawn(player);
  8222. if (!client) {
  8223. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8224. return 0;
  8225. }
  8226. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8227. client->GetPlayer()->SetXP(1);
  8228. client->GetPlayer()->SetNeededXP();
  8229. return 0;
  8230. }
  8231. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8232. if (!lua_interface)
  8233. return 0;
  8234. Spawn* player = lua_interface->GetSpawn(state);
  8235. int32 amount = lua_interface->GetInt32Value(state, 2);
  8236. if (!player) {
  8237. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8238. return 0;
  8239. }
  8240. if (!player->IsPlayer()) {
  8241. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8242. return 0;
  8243. }
  8244. if (amount == 0) {
  8245. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8246. return 0;
  8247. }
  8248. ((Player*)player)->AddCoins(amount);
  8249. return 0;
  8250. }
  8251. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8252. if (!lua_interface)
  8253. return 0;
  8254. Spawn* player = lua_interface->GetSpawn(state);
  8255. int32 amount = lua_interface->GetInt32Value(state, 2);
  8256. if (!player) {
  8257. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8258. return 0;
  8259. }
  8260. if (!player->IsPlayer()) {
  8261. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8262. return 0;
  8263. }
  8264. if (amount == 0) {
  8265. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8266. return 0;
  8267. }
  8268. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8269. return 1;
  8270. }
  8271. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8272. if (!lua_interface)
  8273. return 0;
  8274. ZoneServer* zone = lua_interface->GetZone(state);
  8275. if (!zone) {
  8276. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8277. return 0;
  8278. }
  8279. vector<Entity*> players = zone->GetPlayers();
  8280. if (players.size() == 0)
  8281. return 0;
  8282. lua_createtable(state, players.size(), 0);
  8283. int newTable = lua_gettop(state);
  8284. for (int32 i = 0; i < players.size(); i++) {
  8285. lua_interface->SetSpawnValue(state, players.at(i));
  8286. lua_rawseti(state, newTable, i + 1);
  8287. }
  8288. return 1;
  8289. }
  8290. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8291. if (!lua_interface)
  8292. return 0;
  8293. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8294. if (!zone) {
  8295. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8296. return 0;
  8297. }
  8298. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8299. //Map of <placement_id, location_id>
  8300. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8301. map<int32, int32>::iterator itr;
  8302. vector<Spawn*> group;
  8303. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8304. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8305. if (!location) {
  8306. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8307. return 0;
  8308. }
  8309. Spawn* spawn = 0;
  8310. if (location->entities[0]) {
  8311. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8312. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8313. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8314. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8315. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8316. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8317. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8318. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8319. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8320. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8321. if (spawn) {
  8322. const char* script = 0;
  8323. for (int x = 0; x < 3; x++) {
  8324. switch (x) {
  8325. case 0:
  8326. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8327. break;
  8328. case 1:
  8329. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8330. break;
  8331. case 2:
  8332. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8333. break;
  8334. }
  8335. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8336. spawn->SetSpawnScript(string(script));
  8337. break;
  8338. }
  8339. }
  8340. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8341. lua_interface->SetSpawnValue(state, spawn);
  8342. group.push_back(spawn);
  8343. }
  8344. else {
  8345. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8346. safe_delete(spawn);
  8347. }
  8348. }
  8349. }
  8350. if (!group.empty()) {
  8351. lua_createtable(state, group.size(), 0);
  8352. int newTable = lua_gettop(state);
  8353. for (int32 i = 0; i < group.size(); i++) {
  8354. lua_interface->SetSpawnValue(state, group[i]);
  8355. lua_rawseti(state, newTable, i + 1);
  8356. }
  8357. }
  8358. else
  8359. lua_pushnil(state);
  8360. return 1;
  8361. }
  8362. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8363. if (!lua_interface)
  8364. return 0;
  8365. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8366. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8367. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8368. if (!spawn) {
  8369. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. if (anim_id == 0) {
  8373. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. if (leeway == 0)
  8377. leeway = 5000;
  8378. spawn->SetSpawnAnim(anim_id);
  8379. spawn->SetSpawnAnimLeeway(leeway);
  8380. return 0;
  8381. }
  8382. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8383. if (!lua_interface)
  8384. return 0;
  8385. Spawn* player = lua_interface->GetSpawn(state);
  8386. if (!player) {
  8387. return 0;
  8388. }
  8389. Client* client = player->GetZone()->GetClientBySpawn(player);
  8390. if (!client) {
  8391. return 0;
  8392. }
  8393. lua_interface->SetInt32Value(state, client->GetVersion());
  8394. return 1;
  8395. }
  8396. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8397. if (!lua_interface)
  8398. return 0;
  8399. Item* item = lua_interface->GetItem(state);
  8400. if (!item) {
  8401. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8402. return 0;
  8403. }
  8404. lua_interface->SetInt32Value(state, item->details.item_id);
  8405. return 1;
  8406. }
  8407. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8408. if (!lua_interface)
  8409. return 0;
  8410. Spawn* spawn = lua_interface->GetSpawn(state);
  8411. if (!spawn) {
  8412. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8413. return 0;
  8414. }
  8415. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8416. return 1;
  8417. }
  8418. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8419. if (!lua_interface)
  8420. return 0;
  8421. Spawn* spawn = lua_interface->GetSpawn(state);
  8422. if (!spawn) {
  8423. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8427. return 1;
  8428. }
  8429. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8430. if (!lua_interface)
  8431. return 0;
  8432. Spawn* spawn = lua_interface->GetSpawn(state);
  8433. if (!spawn) {
  8434. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8438. return 1;
  8439. }
  8440. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8441. if (!lua_interface)
  8442. return 0;
  8443. Spawn* spawn = lua_interface->GetSpawn(state);
  8444. if (!spawn) {
  8445. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8449. return 1;
  8450. }
  8451. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8452. if (!lua_interface)
  8453. return 0;
  8454. Spawn* spawn = lua_interface->GetSpawn(state);
  8455. float pct = lua_interface->GetFloatValue(state, 2);
  8456. if (!spawn) {
  8457. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8458. return 0;
  8459. }
  8460. if (pct == 0) {
  8461. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8462. return 0;
  8463. }
  8464. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8465. lua_interface->SetInt32Value(state, amount);
  8466. return 1;
  8467. }
  8468. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8469. if (!lua_interface)
  8470. return 0;
  8471. Spawn* spawn = lua_interface->GetSpawn(state);
  8472. float pct = lua_interface->GetFloatValue(state, 2);
  8473. if (!spawn) {
  8474. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8475. return 0;
  8476. }
  8477. if (pct == 0) {
  8478. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8482. lua_interface->SetInt32Value(state, amount);
  8483. return 1;
  8484. }
  8485. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Spawn* spawn = lua_interface->GetSpawn(state);
  8489. if (!spawn) {
  8490. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. if (!spawn->IsPlayer()) {
  8494. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8498. return 1;
  8499. }
  8500. int EQ2Emu_lua_Evac(lua_State* state) {
  8501. if (!lua_interface)
  8502. return 0;
  8503. Spawn* target = lua_interface->GetSpawn(state);
  8504. if (target) {
  8505. float x = target->GetZone()->GetSafeX();
  8506. float y = target->GetZone()->GetSafeY();
  8507. float z = target->GetZone()->GetSafeZ();
  8508. float h = target->GetZone()->GetSafeHeading();
  8509. target->SetX(x);
  8510. target->SetY(y);
  8511. target->SetZ(z);
  8512. target->SetHeading(h);
  8513. target->SetSpawnOrigX(target->GetX());
  8514. target->SetSpawnOrigY(target->GetY());
  8515. target->SetSpawnOrigZ(target->GetZ());
  8516. target->SetSpawnOrigHeading(target->GetHeading());
  8517. if (target->IsPlayer()) {
  8518. Client* client = target->GetZone()->GetClientBySpawn(target);
  8519. if (client) {
  8520. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8521. if (packet)
  8522. {
  8523. packet->setDataByName("x", x);
  8524. packet->setDataByName("y", y);
  8525. packet->setDataByName("z", z);
  8526. client->QueuePacket(packet->serialize());
  8527. safe_delete(packet);
  8528. }
  8529. }
  8530. }
  8531. }
  8532. else {
  8533. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8534. ZoneServer* zone = spell->caster->GetZone();
  8535. float x = spell->caster->GetZone()->GetSafeX();
  8536. float y = spell->caster->GetZone()->GetSafeY();
  8537. float z = spell->caster->GetZone()->GetSafeZ();
  8538. float h = spell->caster->GetZone()->GetSafeHeading();
  8539. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8540. for (int32 i = 0; i < spell->targets.size(); i++) {
  8541. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8542. if (!target2)
  8543. continue;
  8544. target2->SetX(x);
  8545. target2->SetY(y);
  8546. target2->SetZ(z);
  8547. target2->SetHeading(h);
  8548. target2->SetSpawnOrigX(target2->GetX());
  8549. target2->SetSpawnOrigY(target2->GetY());
  8550. target2->SetSpawnOrigZ(target2->GetZ());
  8551. target2->SetSpawnOrigHeading(target2->GetHeading());
  8552. if (target2->IsPlayer()) {
  8553. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8554. if (client) {
  8555. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8556. if (packet)
  8557. {
  8558. packet->setDataByName("x", x);
  8559. packet->setDataByName("y", y);
  8560. packet->setDataByName("z", z);
  8561. client->QueuePacket(packet->serialize());
  8562. safe_delete(packet);
  8563. }
  8564. }
  8565. }
  8566. }
  8567. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8568. }
  8569. return 0;
  8570. }
  8571. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8572. if (!lua_interface)
  8573. return 0;
  8574. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8575. if (!luaspell) {
  8576. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8577. return 0;
  8578. }
  8579. int8 tier = luaspell->spell->GetSpellTier();
  8580. lua_interface->SetInt32Value(state, tier);
  8581. return 1;
  8582. }
  8583. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8584. if (!lua_interface)
  8585. return 0;
  8586. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8587. if (!luaspell) {
  8588. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8589. return 0;
  8590. }
  8591. int32 spell_id = luaspell->spell->GetSpellID();
  8592. lua_interface->SetInt32Value(state, spell_id);
  8593. return 1;
  8594. }
  8595. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8596. if (!lua_interface)
  8597. return 0;
  8598. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8599. if (!spawn) {
  8600. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8601. return 0;
  8602. }
  8603. if (!spawn->IsPlayer()) {
  8604. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. ZoneServer* zone = spawn->GetZone();
  8608. if (!zone) {
  8609. return 0;
  8610. }
  8611. Client* client = zone->GetClientBySpawn(spawn);
  8612. if (!client) {
  8613. return 0;
  8614. }
  8615. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8616. return 0;
  8617. }
  8618. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8619. if (!lua_interface)
  8620. return 0;
  8621. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8622. if (!spawn) {
  8623. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8624. return 0;
  8625. }
  8626. if (!spawn->IsPlayer()) {
  8627. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8628. return 0;
  8629. }
  8630. ZoneServer* zone = spawn->GetZone();
  8631. if (!zone) {
  8632. return 0;
  8633. }
  8634. Client* client = zone->GetClientBySpawn(spawn);
  8635. if (!client) {
  8636. return 0;
  8637. }
  8638. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8639. return 0;
  8640. }
  8641. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8642. if (!lua_interface)
  8643. return 0;
  8644. Spawn* caster = lua_interface->GetSpawn(state);
  8645. Spawn* target = lua_interface->GetSpawn(state, 2);
  8646. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8647. string spell_name = lua_interface->GetStringValue(state, 4);
  8648. if (!caster) {
  8649. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8650. return 0;
  8651. }
  8652. if (!caster->IsEntity()) {
  8653. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8654. return 0;
  8655. }
  8656. if (!target) {
  8657. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8658. return 0;
  8659. }
  8660. if (!target->IsEntity()) {
  8661. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8665. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8666. return 0;
  8667. }
  8668. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8669. if (!lua_interface)
  8670. return 0;
  8671. Spawn* object = lua_interface->GetSpawn(state);
  8672. Spawn* player = lua_interface->GetSpawn(state, 2);
  8673. if (object && player && player->IsPlayer()) {
  8674. int32 coins = lua_interface->GetInt32Value(state, 3);
  8675. vector<Item*>* items = 0;
  8676. int i = 0;
  8677. int32 item_id = 0;
  8678. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8679. if (items == 0)
  8680. items = new vector<Item*>;
  8681. if (master_item_list.GetItem(item_id))
  8682. items->push_back(master_item_list.GetItem(item_id));
  8683. i++;
  8684. }
  8685. Client* client = 0;
  8686. client = object->GetZone()->GetClientBySpawn(player);
  8687. if (client) {
  8688. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8689. }
  8690. safe_delete(items);
  8691. }
  8692. return 0;
  8693. }
  8694. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8695. if (!lua_interface)
  8696. return 0;
  8697. Spawn* player = lua_interface->GetSpawn(state);
  8698. int32 amount = lua_interface->GetInt32Value(state, 2);
  8699. if (player && player->IsPlayer() && amount > 0) {
  8700. ((Player*)player)->AddXP(amount);
  8701. ((Player*)player)->SetCharSheetChanged(true);
  8702. Client* client = player->GetZone()->GetClientBySpawn(player);
  8703. if (client) {
  8704. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8705. }
  8706. }
  8707. return 0;
  8708. }
  8709. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8710. if (!lua_interface)
  8711. return 0;
  8712. Spawn* player = lua_interface->GetSpawn(state);
  8713. int8 type = lua_interface->GetInt8Value(state, 2);
  8714. string text = lua_interface->GetStringValue(state, 3);
  8715. Client* client = 0;
  8716. if (player && player->IsPlayer())
  8717. client = player->GetZone()->GetClientBySpawn(player);
  8718. if (!client || text.length() == 0) {
  8719. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8720. return 0;
  8721. }
  8722. client->SimpleMessage(type, text.c_str());
  8723. return 0;
  8724. }
  8725. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8726. if (!lua_interface)
  8727. return 0;
  8728. Spawn* player = lua_interface->GetSpawn(state);
  8729. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8730. Client* client = 0;
  8731. if (player && player->IsPlayer())
  8732. client = player->GetZone()->GetClientBySpawn(player);
  8733. if (!client || !spawn) {
  8734. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8735. return 0;
  8736. }
  8737. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8738. if (!items) {
  8739. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. client->Loot(spawn->GetLootCoins(), items, spawn);
  8743. return 0;
  8744. }
  8745. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8746. if (!lua_interface)
  8747. return 0;
  8748. Spawn* spawnref = lua_interface->GetSpawn(state);
  8749. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8750. if (spawn_id > 0 && spawnref) {
  8751. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8752. if (spawns.size() == 0) {
  8753. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8754. return 0;
  8755. }
  8756. Spawn* spawn = 0;
  8757. int16 index = MakeRandomInt(0, spawns.size());
  8758. if (index >= spawns.size() || index < 0)
  8759. index = 0;
  8760. spawn = spawns[index];
  8761. lua_interface->SetSpawnValue(state, spawn);
  8762. return 1;
  8763. }
  8764. else {
  8765. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8766. }
  8767. return 0;
  8768. }
  8769. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8770. Spawn* player = lua_interface->GetSpawn(state);
  8771. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8772. string name = lua_interface->GetStringValue(state, 3);
  8773. float distance = lua_interface->GetFloatValue(state, 4);
  8774. string command = lua_interface->GetStringValue(state, 5);
  8775. string error_text = lua_interface->GetStringValue(state, 6);
  8776. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8777. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8778. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8779. if (distance == 0)
  8780. distance = 10.0f;
  8781. if (command.length() == 0)
  8782. command = name;
  8783. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8784. if (spawns.size() == 0) {
  8785. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8786. return 0;
  8787. }
  8788. Spawn* spawn = 0;
  8789. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8790. spawn = *itr;
  8791. if (spawn) {
  8792. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8793. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8794. }
  8795. }
  8796. }
  8797. return 0;
  8798. }
  8799. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8800. if (!lua_interface)
  8801. return 0;
  8802. Client* client = 0;
  8803. Spawn* player = lua_interface->GetSpawn(state);
  8804. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8805. if (player && player->IsPlayer() && player->GetZone())
  8806. client = player->GetZone()->GetClientBySpawn(player);
  8807. else{
  8808. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8809. return 0;
  8810. }
  8811. if (client) {
  8812. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8813. if (packet) {
  8814. packet->setDataByName("goal_num", goal_num);
  8815. client->QueuePacket(packet->serialize());
  8816. safe_delete(packet);
  8817. }
  8818. }
  8819. return 0;
  8820. }
  8821. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8822. if (!lua_interface)
  8823. return 0;
  8824. Client* client = 0;
  8825. Spawn* player = lua_interface->GetSpawn(state);
  8826. if (player && player->IsPlayer() && player->GetZone())
  8827. client = player->GetZone()->GetClientBySpawn(player);
  8828. else {
  8829. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8830. return 0;
  8831. }
  8832. if (client) {
  8833. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8834. }
  8835. return 0;
  8836. }
  8837. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8838. if (!lua_interface)
  8839. return 0;
  8840. Client* client = 0;
  8841. Spawn* player = lua_interface->GetSpawn(state);
  8842. float duration = lua_interface->GetFloatValue(state, 2);
  8843. string text = lua_interface->GetStringValue(state, 3);
  8844. string voice = lua_interface->GetStringValue(state, 4);
  8845. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8846. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8847. string signal = lua_interface->GetStringValue(state, 7);
  8848. string goal1 = lua_interface->GetStringValue(state, 8);
  8849. string task1 = lua_interface->GetStringValue(state, 9);
  8850. string goal2 = lua_interface->GetStringValue(state, 10);
  8851. string task2 = lua_interface->GetStringValue(state, 11);
  8852. string goal3 = lua_interface->GetStringValue(state, 12);
  8853. string task3 = lua_interface->GetStringValue(state, 13);
  8854. string goal4 = lua_interface->GetStringValue(state, 14);
  8855. string task4 = lua_interface->GetStringValue(state, 15);
  8856. if (!player) {
  8857. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8858. return 0;
  8859. }
  8860. if (!player->IsPlayer()) {
  8861. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8862. return 0;
  8863. }
  8864. else
  8865. client = ((Player*)player)->GetClient();
  8866. if (!client) {
  8867. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8868. return 0;
  8869. }
  8870. if (text.length() == 0 || task1.length() == 0 || signal.length() == 0) {
  8871. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8872. return 0;
  8873. }
  8874. if (duration >= 0 && duration < 2)
  8875. duration = 2;
  8876. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8877. if (packet) {
  8878. packet->setDataByName("open_seconds_max", duration);
  8879. packet->setDataByName("text", text.c_str());
  8880. packet->setDataByName("voice", voice.c_str());
  8881. int8 num_goals = 1;
  8882. if (task2.length() > 0)
  8883. num_goals++;
  8884. if (task3.length() > 0)
  8885. num_goals++;
  8886. if (task4.length() > 0)
  8887. num_goals++;
  8888. packet->setArrayLengthByName("num_goals", num_goals);
  8889. for (int8 i = 0; i < num_goals; i++) {
  8890. packet->setSubArrayLengthByName("num_tasks", 1, i);
  8891. }
  8892. if (goal1.length() > 0)
  8893. packet->setArrayDataByName("goal_text", goal1.c_str());
  8894. if (goal2.length() > 0)
  8895. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  8896. if (goal3.length() > 0)
  8897. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  8898. if (goal4.length() > 0)
  8899. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  8900. packet->setSubArrayDataByName("task_text", task1.c_str());
  8901. if (task2.length() > 0)
  8902. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  8903. if (task3.length() > 0)
  8904. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  8905. if (task4.length() > 0)
  8906. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  8907. packet->setDataByName("complete_sound", "click");
  8908. packet->setDataByName("signal", signal.c_str());
  8909. packet->setDataByName("voice_key1", voice_key1);
  8910. packet->setDataByName("voice_key2", voice_key2);
  8911. client->QueuePacket(packet->serialize());
  8912. safe_delete(packet);
  8913. }
  8914. return 0;
  8915. }
  8916. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  8917. if (!lua_interface)
  8918. return 0;
  8919. Client* client = 0;
  8920. Spawn* player = lua_interface->GetSpawn(state);
  8921. string window = lua_interface->GetStringValue(state, 2);
  8922. int8 show = lua_interface->GetInt8Value(state, 3);
  8923. if (!player) {
  8924. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  8925. return 0;
  8926. }
  8927. if (!player->IsPlayer()) {
  8928. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  8929. return 0;
  8930. }
  8931. else
  8932. client = ((Player*)player)->GetClient();
  8933. if (!client) {
  8934. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  8935. return 0;
  8936. }
  8937. if (window.length() == 0) {
  8938. lua_interface->LogError("LUA ShowWindow required parameters not given");
  8939. return 0;
  8940. }
  8941. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  8942. if (packet) {
  8943. packet->setDataByName("window", window.c_str());
  8944. packet->setDataByName("show", show);
  8945. client->QueuePacket(packet->serialize());
  8946. safe_delete(packet);
  8947. }
  8948. return 0;
  8949. }
  8950. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  8951. //See GameEvents.txt for options that can be used for this function
  8952. if (!lua_interface)
  8953. return 0;
  8954. Client* client = 0;
  8955. Spawn* player = lua_interface->GetSpawn(state);
  8956. string event_name = lua_interface->GetStringValue(state, 2);
  8957. int8 enabled = lua_interface->GetInt8Value(state, 3);
  8958. if (!player || !player->IsPlayer()) {
  8959. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  8960. return 0;
  8961. }
  8962. if (player->GetZone())
  8963. client = player->GetZone()->GetClientBySpawn(player);
  8964. if (!client) {
  8965. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  8966. return 0;
  8967. }
  8968. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  8969. if (packet) {
  8970. packet->setDataByName("event_name", event_name.c_str());
  8971. packet->setDataByName("enabled", enabled);
  8972. client->QueuePacket(packet->serialize());
  8973. safe_delete(packet);
  8974. }
  8975. return 0;
  8976. }
  8977. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  8978. if (!lua_interface)
  8979. return 0;
  8980. Spawn* player = lua_interface->GetSpawn(state);
  8981. if (player && player->IsPlayer()) {
  8982. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  8983. return 1;
  8984. }
  8985. return 0;
  8986. }
  8987. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  8988. if (!lua_interface)
  8989. return 0;
  8990. Spawn* player = lua_interface->GetSpawn(state);
  8991. int8 step = lua_interface->GetInt8Value(state, 2);
  8992. if (player && player->IsPlayer() && step > 0) {
  8993. ((Player*)player)->SetTutorialStep(step);
  8994. }
  8995. return 0;
  8996. }
  8997. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  8998. if (!lua_interface)
  8999. return 0;
  9000. Client* client = 0;
  9001. Spawn* player = lua_interface->GetSpawn(state);
  9002. string window = lua_interface->GetStringValue(state, 2);
  9003. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9004. if (!player) {
  9005. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9006. return 0;
  9007. }
  9008. if (!player->IsPlayer()) {
  9009. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9010. return 0;
  9011. }
  9012. else
  9013. client = ((Player*)player)->GetClient();
  9014. if (!client) {
  9015. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9016. return 0;
  9017. }
  9018. if (window.length() == 0) {
  9019. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9020. return 0;
  9021. }
  9022. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9023. if (packet) {
  9024. packet->setDataByName("window", window.c_str());
  9025. packet->setDataByName("flash_seconds", flash_seconds);
  9026. client->QueuePacket(packet->serialize());
  9027. safe_delete(packet);
  9028. }
  9029. return 0;
  9030. }
  9031. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9032. if (!lua_interface)
  9033. return 0;
  9034. Spawn* spawn = lua_interface->GetSpawn(state);
  9035. Spawn* target = lua_interface->GetSpawn(state, 2);
  9036. if (spawn && target)
  9037. return spawn->CheckLoS(target);
  9038. return 0;
  9039. }
  9040. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9041. if (!lua_interface)
  9042. return 0;
  9043. Spawn* spawn = lua_interface->GetSpawn(state);
  9044. float x = lua_interface->GetFloatValue(state, 2);
  9045. float y = lua_interface->GetFloatValue(state, 3);
  9046. float z = lua_interface->GetFloatValue(state, 4);
  9047. if (spawn)
  9048. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9049. return 0;
  9050. }
  9051. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9052. if (!lua_interface)
  9053. return 0;
  9054. ZoneServer* zone = lua_interface->GetZone(state);
  9055. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9056. if (zone)
  9057. zone->SetExpansionFlag(xpackFlag);
  9058. return 0;
  9059. }
  9060. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. ZoneServer* zone = lua_interface->GetZone(state);
  9064. if (zone) {
  9065. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9066. return 1;
  9067. }
  9068. return 0;
  9069. }
  9070. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9071. if (!lua_interface)
  9072. return 0;
  9073. ZoneServer* zone = lua_interface->GetZone(state);
  9074. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9075. if (zone)
  9076. zone->SetHolidayFlag(holidayFlag);
  9077. return 0;
  9078. }
  9079. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9080. if (!lua_interface)
  9081. return 0;
  9082. ZoneServer* zone = lua_interface->GetZone(state);
  9083. if (zone) {
  9084. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9085. return 1;
  9086. }
  9087. return 0;
  9088. }
  9089. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9090. if (!lua_interface)
  9091. return 0;
  9092. Spawn* spawn = lua_interface->GetSpawn(state);
  9093. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9094. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9095. float distance = lua_interface->GetFloatValue(state, 4);
  9096. string in_range_function = lua_interface->GetStringValue(state, 5);
  9097. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9098. if (spawn && distance > 0 && in_range_function.length() > 0)
  9099. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9100. return 0;
  9101. }
  9102. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9103. if (!lua_interface)
  9104. return 0;
  9105. Spawn* spawn = lua_interface->GetSpawn(state);
  9106. Spawn* target = lua_interface->GetSpawn(state, 2);
  9107. if (spawn && target)
  9108. {
  9109. if (spawn->IsPlayer() && target->IsEntity())
  9110. {
  9111. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9112. return 1;
  9113. }
  9114. else if (spawn->IsEntity() && target->IsEntity())
  9115. {
  9116. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9117. return 1;
  9118. }
  9119. }
  9120. return 0;
  9121. }
  9122. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9123. if (!lua_interface)
  9124. return 0;
  9125. Spawn* spawn = lua_interface->GetSpawn(state);
  9126. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9127. if (spawn && spawn->IsEntity())
  9128. {
  9129. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9130. if (spawn->IsPlayer())
  9131. {
  9132. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9133. if (client)
  9134. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9135. }
  9136. }
  9137. return 0;
  9138. }
  9139. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9140. if (!lua_interface)
  9141. return 0;
  9142. Spawn* spawn = lua_interface->GetSpawn(state);
  9143. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9144. if (spawn && spawn->IsEntity())
  9145. {
  9146. ((Entity*)spawn)->SetSeeHideSpell(val);
  9147. if (spawn->IsPlayer())
  9148. {
  9149. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9150. if (client)
  9151. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9152. }
  9153. }
  9154. return 0;
  9155. }
  9156. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9157. {
  9158. if (!lua_interface)
  9159. return 0;
  9160. Spawn* player = lua_interface->GetSpawn(state);
  9161. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9162. string command = lua_interface->GetStringValue(state, 3);
  9163. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9164. if (spawn && player && player->IsPlayer())
  9165. {
  9166. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9167. bool res = false;
  9168. if (cmd)
  9169. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9170. lua_interface->SetBooleanValue(state, res);
  9171. return 1;
  9172. }
  9173. return 0;
  9174. }
  9175. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9176. {
  9177. if (!lua_interface)
  9178. return 0;
  9179. Spawn* spawn = lua_interface->GetSpawn(state);
  9180. string command = lua_interface->GetStringValue(state, 2);
  9181. if (spawn && command.length() > 0)
  9182. spawn->RemovePrimaryEntityCommand(command.c_str());
  9183. return 0;
  9184. }
  9185. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9186. if (!lua_interface)
  9187. return 0;
  9188. Spawn* spawn = lua_interface->GetSpawn(state);
  9189. float distance = lua_interface->GetFloatValue(state, 2);
  9190. string command = lua_interface->GetStringValue(state, 3);
  9191. Spawn* player = lua_interface->GetSpawn(state, 4);
  9192. if (spawn) {
  9193. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9194. }
  9195. return 0;
  9196. }
  9197. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9198. if (!lua_interface)
  9199. return 0;
  9200. Spawn* spawn = lua_interface->GetSpawn(state);
  9201. Spawn* player = lua_interface->GetSpawn(state, 2);
  9202. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9203. if (spawn && player && transport_id && player->IsPlayer()) {
  9204. Client* client = 0;
  9205. if (player && player->IsPlayer())
  9206. client = player->GetZone()->GetClientBySpawn(player);
  9207. if (!client)
  9208. return 0;
  9209. vector<TransportDestination*> destinations;
  9210. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9211. if (destinations.size())
  9212. {
  9213. client->SetTemporaryTransportID(transport_id);
  9214. client->ProcessTeleport(spawn, &destinations, transport_id);
  9215. }
  9216. else
  9217. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9218. }
  9219. return 0;
  9220. }
  9221. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9222. if (!lua_interface)
  9223. return 0;
  9224. Spawn* player = lua_interface->GetSpawn(state);
  9225. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9226. if (player && player->IsPlayer()) {
  9227. Client* client = 0;
  9228. if (player && player->IsPlayer())
  9229. client = player->GetZone()->GetClientBySpawn(player);
  9230. if (!client)
  9231. return 0;
  9232. client->SetTemporaryTransportID(transport_id);
  9233. }
  9234. return 0;
  9235. }
  9236. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9237. if (!lua_interface)
  9238. return 0;
  9239. Spawn* player = lua_interface->GetSpawn(state);
  9240. if (player && player->IsPlayer()) {
  9241. Client* client = 0;
  9242. if (player && player->IsPlayer())
  9243. client = player->GetZone()->GetClientBySpawn(player);
  9244. if (!client)
  9245. return 0;
  9246. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9247. return 1;
  9248. }
  9249. return 0;
  9250. }
  9251. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9252. if (!lua_interface)
  9253. return 0;
  9254. Spawn* spawn = lua_interface->GetSpawn(state);
  9255. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9256. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9257. if (!spawn) {
  9258. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9259. return 0;
  9260. }
  9261. if (!spawn->IsEntity()) {
  9262. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9263. return 0;
  9264. }
  9265. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9266. {
  9267. 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);
  9268. return 0;
  9269. }
  9270. if (spell && spell->targets.size() > 0) {
  9271. ZoneServer* zone = spell->caster->GetZone();
  9272. for (int8 i = 0; i < spell->targets.size(); i++) {
  9273. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9274. if (target->IsEntity()) {
  9275. ((Entity*)target)->GetInfoStruct()->alignment = (sint8)alignment;
  9276. if (target->IsPlayer())
  9277. ((Player*)target)->SetCharSheetChanged(true);
  9278. }
  9279. }
  9280. }
  9281. else {
  9282. ((Entity*)spawn)->GetInfoStruct()->alignment = (sint8)alignment;
  9283. if (spawn->IsPlayer())
  9284. ((Player*)spawn)->SetCharSheetChanged(true);
  9285. }
  9286. return 0;
  9287. }
  9288. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9289. if (!lua_interface)
  9290. return 0;
  9291. Spawn* spawn = lua_interface->GetSpawn(state);
  9292. if (!spawn) {
  9293. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9294. return 0;
  9295. }
  9296. if (!spawn->IsEntity()) {
  9297. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9298. return 0;
  9299. }
  9300. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9301. return 1;
  9302. }
  9303. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9304. if (!lua_interface)
  9305. return 0;
  9306. int32 spell_id = lua_interface->GetInt32Value(state);
  9307. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9308. if (spell_id > 0) {
  9309. if (spell_tier == 0)
  9310. spell_tier = 1;
  9311. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9312. LuaSpell* lua_spell = 0;
  9313. if (lua_interface)
  9314. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9315. if (!lua_spell)
  9316. return 0;
  9317. lua_spell->spell = new Spell(spell);
  9318. lua_interface->AddCustomSpell(lua_spell);
  9319. lua_interface->SetSpellValue(state, lua_spell);
  9320. return 1;
  9321. }
  9322. return 0;
  9323. }
  9324. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9325. if (!lua_interface)
  9326. return 0;
  9327. LuaSpell* spell = lua_interface->GetSpell(state);
  9328. string field = lua_interface->GetStringValue(state, 2);
  9329. if (!spell) {
  9330. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9331. return 0;
  9332. }
  9333. if (!spell->spell || !spell->spell->GetSpellData()) {
  9334. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9335. return 0;
  9336. }
  9337. boost::to_lower(field);
  9338. return spell->spell->GetSpellData(state, field);
  9339. }
  9340. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9341. if (!lua_interface)
  9342. return 0;
  9343. LuaSpell* spell = lua_interface->GetSpell(state);
  9344. string field = lua_interface->GetStringValue(state, 2);
  9345. int8 fieldArg = 3; // field value after the initial set
  9346. if (!spell) {
  9347. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9348. return 0;
  9349. }
  9350. if (!spell->spell || !spell->spell->GetSpellData()) {
  9351. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9352. return 0;
  9353. }
  9354. boost::to_lower(field);
  9355. bool valSet = false;
  9356. spell->spell->SetSpellData(state, field, fieldArg);
  9357. return valSet;
  9358. }
  9359. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9360. if (!lua_interface)
  9361. return 0;
  9362. LuaSpell* spell = lua_interface->GetSpell(state);
  9363. int8 idx = lua_interface->GetInt32Value(state, 2);
  9364. if (!spell) {
  9365. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9366. return 0;
  9367. }
  9368. if (!spell->spell || !spell->spell->GetSpellData()) {
  9369. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9370. return 0;
  9371. }
  9372. if (spell->spell->lua_data.size() <= idx)
  9373. {
  9374. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9375. return 0;
  9376. }
  9377. bool setVal = true;
  9378. LUAData* data = spell->spell->lua_data[idx];
  9379. switch (data->type)
  9380. {
  9381. case 0:
  9382. {
  9383. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9384. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9385. data->int_value = value;
  9386. data->int_value2 = value2;
  9387. break;
  9388. }
  9389. case 1:
  9390. {
  9391. float value = lua_interface->GetFloatValue(state, 3);
  9392. float value2 = lua_interface->GetFloatValue(state, 4);
  9393. data->float_value = value;
  9394. data->float_value2 = value2;
  9395. break;
  9396. }
  9397. case 2:
  9398. {
  9399. bool value = lua_interface->GetBooleanValue(state, 3);
  9400. data->bool_value = value;
  9401. break;
  9402. }
  9403. case 3:
  9404. {
  9405. string value = lua_interface->GetStringValue(state, 3);
  9406. string value2 = lua_interface->GetStringValue(state, 4);
  9407. data->string_value = value;
  9408. data->string_value2 = value2;
  9409. break;
  9410. }
  9411. default:
  9412. setVal = false;
  9413. }
  9414. return setVal;
  9415. }
  9416. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9417. if (!lua_interface)
  9418. return 0;
  9419. LuaSpell* spell = lua_interface->GetSpell(state);
  9420. int8 idx = lua_interface->GetInt32Value(state, 2);
  9421. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9422. if (!spell) {
  9423. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9424. return 0;
  9425. }
  9426. if (!spell->spell || !spell->spell->GetSpellData()) {
  9427. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9428. return 0;
  9429. }
  9430. if (spell->spell->lua_data.size() <= idx)
  9431. {
  9432. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9433. return 0;
  9434. }
  9435. bool setVal = true;
  9436. LUAData* data = spell->spell->lua_data[idx];
  9437. switch (data->type)
  9438. {
  9439. case 0:
  9440. {
  9441. if(!secondfield)
  9442. lua_interface->SetSInt32Value(state, data->int_value);
  9443. else
  9444. lua_interface->SetSInt32Value(state, data->int_value2);
  9445. break;
  9446. }
  9447. case 1:
  9448. {
  9449. if (!secondfield)
  9450. lua_interface->SetFloatValue(state, data->float_value);
  9451. else
  9452. lua_interface->SetFloatValue(state, data->float_value2);
  9453. break;
  9454. }
  9455. case 2:
  9456. {
  9457. lua_interface->SetBooleanValue(state, data->bool_value);
  9458. break;
  9459. }
  9460. case 3:
  9461. {
  9462. if (!secondfield)
  9463. lua_interface->SetStringValue(state, data->string_value.c_str());
  9464. else
  9465. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9466. break;
  9467. }
  9468. default:
  9469. setVal = false;
  9470. }
  9471. return setVal;
  9472. }
  9473. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. LuaSpell* spell = lua_interface->GetSpell(state);
  9477. int8 idx = lua_interface->GetInt32Value(state, 2);
  9478. string field = lua_interface->GetStringValue(state, 3);
  9479. boost::to_lower(field);
  9480. if (!spell) {
  9481. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9482. return 0;
  9483. }
  9484. if (!spell->spell || !spell->spell->GetSpellData()) {
  9485. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9486. return 0;
  9487. }
  9488. if (spell->spell->effects.size() <= idx)
  9489. {
  9490. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9491. return 0;
  9492. }
  9493. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9494. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9495. if (field == "description")
  9496. effect->description = string(lua_interface->GetStringValue(state, 4));
  9497. else if (field == "bullet")
  9498. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9499. else if (field == "percentage")
  9500. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9501. else // no match
  9502. return 0;
  9503. return 1;
  9504. }
  9505. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9506. if (!lua_interface)
  9507. return 0;
  9508. LuaSpell* spell = lua_interface->GetSpell(state);
  9509. int8 idx = lua_interface->GetInt32Value(state, 2);
  9510. string field = lua_interface->GetStringValue(state, 3);
  9511. boost::to_lower(field);
  9512. if (!spell) {
  9513. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9514. return 0;
  9515. }
  9516. if (!spell->spell || !spell->spell->GetSpellData()) {
  9517. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9518. return 0;
  9519. }
  9520. if (spell->spell->effects.size() <= idx)
  9521. {
  9522. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9523. return 0;
  9524. }
  9525. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9526. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9527. if (field == "description")
  9528. lua_interface->SetStringValue(state, effect->description.c_str());
  9529. else if (field == "bullet")
  9530. lua_interface->SetInt32Value(state, effect->subbullet);
  9531. else if (field == "percentage")
  9532. lua_interface->SetInt32Value(state, effect->percentage);
  9533. else // no match
  9534. return 0;
  9535. return 1;
  9536. }
  9537. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9538. if (!lua_interface)
  9539. return 0;
  9540. LuaSpell* spell = lua_interface->GetSpell(state);
  9541. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9542. Spawn* target = lua_interface->GetSpawn(state, 3);
  9543. if (!target) {
  9544. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9545. return 0;
  9546. }
  9547. if (!target->IsEntity()) {
  9548. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9549. return 0;
  9550. }
  9551. if (!spell) {
  9552. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9553. return 0;
  9554. }
  9555. if (caster && !caster->IsEntity()) {
  9556. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9557. return 0;
  9558. }
  9559. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9560. return 0;
  9561. }
  9562. int EQ2Emu_lua_InWater(lua_State* state) {
  9563. if (!lua_interface)
  9564. return 0;
  9565. Spawn* spawn = lua_interface->GetSpawn(state);
  9566. if (spawn) {
  9567. lua_interface->SetBooleanValue(state, spawn->InWater());
  9568. return 1;
  9569. }
  9570. return 0;
  9571. }