LuaFunctions.cpp 416 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. return 0;
  1247. }
  1248. Spawn* caster = luaspell->caster;
  1249. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1250. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1251. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1252. Spawn* target = lua_interface->GetSpawn(state, 4);
  1253. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1254. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1255. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1256. lua_interface->ResetFunctionStack(state);
  1257. boost::to_lower(heal_type);
  1258. if (caster && caster->IsEntity()) {
  1259. bool success = false;
  1260. luaspell->resisted = false;
  1261. if (target) {
  1262. float distance = caster->GetDistance(target, true);
  1263. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1264. success = true;
  1265. }
  1266. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1267. Spawn* target = 0;
  1268. ZoneServer* zone = luaspell->caster->GetZone();
  1269. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1270. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1271. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1272. float distance = caster->GetDistance(target, true);
  1273. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1274. }
  1275. }
  1276. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1277. success = true;
  1278. }
  1279. if (success) {
  1280. if (caster->GetZone())
  1281. caster->GetZone()->TriggerCharSheetTimer();
  1282. }
  1283. }
  1284. return 0;
  1285. }
  1286. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1287. if (!lua_interface)
  1288. return 0;
  1289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1290. if(!luaspell || luaspell->resisted) {
  1291. return 0;
  1292. }
  1293. Spawn* caster = luaspell->caster;
  1294. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1295. float percentage = lua_interface->GetFloatValue(state, 2);
  1296. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1297. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1298. Spawn* target = lua_interface->GetSpawn(state, 5);
  1299. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1300. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1301. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1302. lua_interface->ResetFunctionStack(state);
  1303. boost::to_lower(heal_type);
  1304. int32 min_heal = 0, max_heal = 0;
  1305. if (caster && caster->IsEntity() && target) {
  1306. if(percentage <= 0.0f)
  1307. {
  1308. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1309. return 0;
  1310. }
  1311. if(heal_type == "power")
  1312. {
  1313. if(current_value)
  1314. {
  1315. if(caster_value)
  1316. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1317. else
  1318. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1319. }
  1320. else
  1321. {
  1322. if(caster_value)
  1323. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1324. else
  1325. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1326. }
  1327. }
  1328. else
  1329. {
  1330. if(current_value)
  1331. {
  1332. if(caster_value)
  1333. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1334. else
  1335. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1336. }
  1337. else
  1338. {
  1339. if(caster_value)
  1340. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1341. else
  1342. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1343. }
  1344. }
  1345. bool success = false;
  1346. luaspell->resisted = false;
  1347. if (target) {
  1348. float distance = caster->GetDistance(target, true);
  1349. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1350. success = true;
  1351. }
  1352. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1353. Spawn* target = 0;
  1354. ZoneServer* zone = luaspell->caster->GetZone();
  1355. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1356. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1357. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1358. float distance = caster->GetDistance(target, true);
  1359. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1360. }
  1361. }
  1362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1363. success = true;
  1364. }
  1365. if (success) {
  1366. if (caster->GetZone())
  1367. caster->GetZone()->TriggerCharSheetTimer();
  1368. }
  1369. }
  1370. return 0;
  1371. }
  1372. int EQ2Emu_lua_AddItem(lua_State* state) {
  1373. if (!lua_interface)
  1374. return 0;
  1375. Spawn* spawn = lua_interface->GetSpawn(state);
  1376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1377. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1378. lua_interface->ResetFunctionStack(state);
  1379. // default of 1 quantity to add
  1380. if (quantity == 0)
  1381. quantity = 1;
  1382. if (spawn && spawn->IsPlayer()) {
  1383. Client* client = ((Player*)spawn)->GetClient();
  1384. if (client && item_id > 0) {
  1385. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1386. return 1;
  1387. }
  1388. }
  1389. lua_interface->SetBooleanValue(state, false);
  1390. return 1;
  1391. }
  1392. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1393. if (!lua_interface)
  1394. return 0;
  1395. Spawn* spawn = lua_interface->GetSpawn(state);
  1396. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1397. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1398. string location = lua_interface->GetStringValue(state, 4);
  1399. int16 item_count = lua_interface->GetInt16Value(state,5);
  1400. //devn00b: if we dont have a count, assume 1 item.
  1401. if(!item_count) {
  1402. item_count = 1;
  1403. }
  1404. lua_interface->ResetFunctionStack(state);
  1405. if (spawn && spawn->IsPlayer()) {
  1406. Client* client = ((Player*)spawn)->GetClient();
  1407. if (client && item_id > 0) {
  1408. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1409. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1410. else
  1411. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1412. if (send_messages) {
  1413. Item* item = master_item_list.GetItem(item_id);
  1414. if (item) {
  1415. if(item_count > 1) {
  1416. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1417. string popup_text1 = "You receive "+ item_count;
  1418. string popup_text2 = " " + item->name;
  1419. string popup_text = popup_text1 + popup_text2;
  1420. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1421. // return 1;
  1422. } else {
  1423. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1424. string popup_text = "You receive " + item->name;
  1425. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1426. }
  1427. }
  1428. }
  1429. return 1;
  1430. }
  1431. }
  1432. lua_interface->SetBooleanValue(state, false);
  1433. return 1;
  1434. }
  1435. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1436. Spawn* spawn = lua_interface->GetSpawn(state);
  1437. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1438. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1439. lua_interface->ResetFunctionStack(state);
  1440. // default of 1 to remove
  1441. if (quantity == 0)
  1442. quantity = 1;
  1443. Client* client;
  1444. Item* item;
  1445. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1446. if ((client = ((Player*)spawn)->GetClient())) {
  1447. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1448. if (client->RemoveItem(item, quantity)) {
  1449. lua_interface->SetBooleanValue(state, true);
  1450. return 1;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. lua_interface->SetBooleanValue(state, false);
  1456. return 1;
  1457. }
  1458. int EQ2Emu_lua_HasItem(lua_State* state) {
  1459. Spawn* player = lua_interface->GetSpawn(state);
  1460. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1461. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1462. lua_interface->ResetFunctionStack(state);
  1463. if (player && player->IsPlayer()) {
  1464. bool hasItem = false;
  1465. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1466. if (!hasItem)
  1467. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1468. lua_interface->SetBooleanValue(state, hasItem);
  1469. return 1;
  1470. }
  1471. lua_interface->SetBooleanValue(state, false);
  1472. return 1;
  1473. }
  1474. int EQ2Emu_lua_Spawn(lua_State* state) {
  1475. if (!lua_interface)
  1476. return 0;
  1477. ZoneServer* zone = lua_interface->GetZone(state);
  1478. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1479. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1480. float x = lua_interface->GetFloatValue(state, 4);
  1481. float y = lua_interface->GetFloatValue(state, 5);
  1482. float z = lua_interface->GetFloatValue(state, 6);
  1483. float heading = lua_interface->GetFloatValue(state, 7);
  1484. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1485. Spawn* spawn = zone->GetSpawn(spawn_id);
  1486. if (!spawn)
  1487. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1488. else {
  1489. spawn->SetX(x);
  1490. spawn->SetZ(z);
  1491. spawn->SetY(y,true,true);
  1492. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1493. spawn->SetHeading(heading);
  1494. if (restricted_npc)
  1495. spawn->AddAllowAccessSpawn(spawn);
  1496. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1497. bool scriptActive = false;
  1498. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1499. scriptActive = true;
  1500. spawn->SetSpawnScript(string(spawn_script));
  1501. }
  1502. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1503. zone->AddSpawn(spawn);
  1504. if (scriptActive) {
  1505. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1506. }
  1507. lua_interface->ResetFunctionStack(state);
  1508. lua_interface->SetSpawnValue(state, spawn);
  1509. return 1;
  1510. }
  1511. }
  1512. else {
  1513. string output = "Invalid paramaters to LUA Spawn command: \n";
  1514. if (!zone)
  1515. output = output.append("\t").append("Missing zone reference. \n");
  1516. if (spawn_id == 0)
  1517. output = output.append("\t").append("Missing spawn_id.");
  1518. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1519. }
  1520. lua_interface->ResetFunctionStack(state);
  1521. return 0;
  1522. }
  1523. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1524. if (!lua_interface)
  1525. return 0;
  1526. ZoneServer* zone = lua_interface->GetZone(state);
  1527. lua_interface->ResetFunctionStack(state);
  1528. if (zone) {
  1529. lua_interface->SetStringValue(state, zone->GetZoneName());
  1530. return 1;
  1531. }
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. ZoneServer* zone = lua_interface->GetZone(state);
  1538. lua_interface->ResetFunctionStack(state);
  1539. if (zone) {
  1540. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1541. return 1;
  1542. }
  1543. return 0;
  1544. }
  1545. int EQ2Emu_lua_GetZone(lua_State* state) {
  1546. if (!lua_interface)
  1547. return 0;
  1548. int32 zone_id = lua_interface->GetInt32Value(state);
  1549. ZoneServer* zone = 0;
  1550. if (zone_id > 0)
  1551. zone = zone_list.Get(zone_id);
  1552. else {
  1553. string zone_name = lua_interface->GetStringValue(state);
  1554. if (zone_name.length() > 0) {
  1555. zone = zone_list.Get(zone_name.c_str());
  1556. }
  1557. else {
  1558. Spawn* spawn = lua_interface->GetSpawn(state);
  1559. if (spawn)
  1560. zone = spawn->GetZone();
  1561. }
  1562. }
  1563. lua_interface->ResetFunctionStack(state);
  1564. if (zone) {
  1565. lua_interface->SetZoneValue(state, zone);
  1566. return 1;
  1567. }
  1568. return 0;
  1569. }
  1570. int EQ2Emu_lua_AddHate(lua_State* state) {
  1571. Spawn* entity = lua_interface->GetSpawn(state);
  1572. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1573. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1574. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1575. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1576. if(!luaspell || luaspell->resisted) {
  1577. return 0;
  1578. }
  1579. if (entity && entity->IsEntity() && amount != 0) {
  1580. if (luaspell) {
  1581. ZoneServer* zone = luaspell->caster->GetZone();
  1582. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1583. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1584. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1585. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1586. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1587. if (send_packet)
  1588. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1589. }
  1590. }
  1591. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1592. }
  1593. else if (npc && npc->IsNPC() && npc->GetZone())
  1594. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1595. }
  1596. lua_interface->ResetFunctionStack(state);
  1597. return 0;
  1598. }
  1599. int EQ2Emu_lua_Zone(lua_State* state) {
  1600. if (!lua_interface)
  1601. return 0;
  1602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1603. ZoneServer* zone = lua_interface->GetZone(state);
  1604. Spawn* player = lua_interface->GetSpawn(state, 2);
  1605. Client* client = 0;
  1606. if (player && player->IsPlayer())
  1607. client = ((Player*)player)->GetClient();
  1608. float x = lua_interface->GetFloatValue(state, 3);
  1609. float y = lua_interface->GetFloatValue(state, 4);
  1610. float z = lua_interface->GetFloatValue(state, 5);
  1611. float heading = lua_interface->GetFloatValue(state, 6);
  1612. if (zone && client) {
  1613. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1614. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1615. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1616. {
  1617. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1618. return 0;
  1619. }
  1620. if (x != 0 || y != 0 || z != 0) {
  1621. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1622. player->SetX(x);
  1623. player->SetY(y);
  1624. player->SetZ(z);
  1625. player->SetHeading(heading);
  1626. client->Zone(zone->GetZoneName(), false);
  1627. }
  1628. else
  1629. client->Zone(zone->GetZoneName());
  1630. }
  1631. else
  1632. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1633. lua_interface->ResetFunctionStack(state);
  1634. return 0;
  1635. }
  1636. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1637. if (!lua_interface)
  1638. return 0;
  1639. Spawn* spawn = lua_interface->GetSpawn(state);
  1640. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1641. if (spawn && spawn2)
  1642. spawn->AddAllowAccessSpawn(spawn2);
  1643. lua_interface->ResetFunctionStack(state);
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* target = lua_interface->GetSpawn(state);
  1650. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1651. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1652. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1653. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1654. lua_interface->ResetFunctionStack(state);
  1655. if (!target) {
  1656. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1657. return 0;
  1658. }
  1659. if (!target->IsEntity()) {
  1660. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1661. return 0;
  1662. }
  1663. if (spell_id <= 0) {
  1664. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1665. return 0;
  1666. }
  1667. if (caster && !caster->IsEntity()) {
  1668. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1669. return 0;
  1670. }
  1671. if (spell_tier == 0)
  1672. spell_tier = 1;
  1673. if (!caster)
  1674. caster = target;
  1675. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1676. return 0;
  1677. }
  1678. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1679. if (!lua_interface)
  1680. return 0;
  1681. Spawn* target = lua_interface->GetSpawn(state);
  1682. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1683. if(!luaspell || luaspell->resisted) {
  1684. return 0;
  1685. }
  1686. Spawn* caster = luaspell->caster;
  1687. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1688. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1689. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1690. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1691. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1692. //lua_interface->ResetFunctionStack(state);
  1693. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1694. vector<int16> faction_req;
  1695. vector<int16> race_req;
  1696. int32 class_req = 0;
  1697. int32 i = 0;
  1698. int8 f = 0;
  1699. int8 r = 0;
  1700. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1701. if (class_id < 100) {
  1702. class_req += pow(2.0, double(class_id - 1));
  1703. }
  1704. else if (class_id > 100 && class_id < 1000) {
  1705. race_req.push_back(class_id);
  1706. r++;
  1707. }
  1708. else {
  1709. faction_req.push_back(class_id);
  1710. f++;
  1711. }
  1712. i++;
  1713. }
  1714. lua_interface->ResetFunctionStack(state);
  1715. if (caster && caster->IsEntity()) {
  1716. bool race_match = false;
  1717. bool success = false;
  1718. luaspell->resisted = false;
  1719. if (luaspell->targets.size() > 0) {
  1720. ZoneServer* zone = luaspell->caster->GetZone();
  1721. Spawn* target = 0;
  1722. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1723. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1724. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1725. if (race_req.size() > 0) {
  1726. for (int8 i = 0; i < race_req.size(); i++) {
  1727. if(race_req[i] == target->GetRace() ||
  1728. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1729. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1730. race_match = true;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1736. if (race_match == true) {
  1737. float distance = caster->GetDistance(target, true);
  1738. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1739. }
  1740. }
  1741. }
  1742. success = true;
  1743. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1744. }
  1745. else if (target) {
  1746. //check class and race/faction here
  1747. if (race_req.size() > 0) {
  1748. for (int8 i = 0; i < race_req.size(); i++) {
  1749. if(race_req[i] == target->GetRace() ||
  1750. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1751. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1752. race_match = true;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1758. if (race_match == true) {
  1759. float distance = caster->GetDistance(target, true);
  1760. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1761. success = true;
  1762. }
  1763. }
  1764. if (success) {
  1765. Spell* spell = luaspell->spell;
  1766. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1767. ((Player*)caster)->InCombat(true);
  1768. if (caster->GetZone())
  1769. caster->GetZone()->TriggerCharSheetTimer();
  1770. }
  1771. }
  1772. }
  1773. return 0;
  1774. }
  1775. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1776. if (!lua_interface)
  1777. return 0;
  1778. Spawn* spawn = lua_interface->GetSpawn(state);
  1779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1780. lua_interface->ResetFunctionStack(state);
  1781. if (spawn && value != 0) {
  1782. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1783. spawn->SetPower(spawn->GetTotalPower());
  1784. else
  1785. spawn->SetPower(spawn->GetPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn && value != 0) {
  1796. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1797. spawn->SetHP(spawn->GetTotalHP());
  1798. else
  1799. spawn->SetHP(spawn->GetHP() + value);
  1800. }
  1801. return 0;
  1802. }
  1803. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1804. if (!lua_interface)
  1805. return 0;
  1806. Spawn* spawn = lua_interface->GetSpawn(state);
  1807. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1808. lua_interface->ResetFunctionStack(state);
  1809. if (spawn && value != 0) {
  1810. spawn->SetPower(spawn->GetPower() + value);
  1811. if (value > spawn->GetTotalHPBase())
  1812. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1821. lua_interface->ResetFunctionStack(state);
  1822. if (spawn && value != 0) {
  1823. spawn->SetHP(spawn->GetHP() + value);
  1824. if (value > spawn->GetTotalHPBase())
  1825. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1826. }
  1827. return 0;
  1828. }
  1829. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1830. if (!lua_interface)
  1831. return 0;
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1834. lua_interface->ResetFunctionStack(state);
  1835. if (spawn) {
  1836. spawn->SetHP(value);
  1837. if (value > spawn->GetTotalHPBase())
  1838. spawn->SetTotalHP(value);
  1839. }
  1840. return 0;
  1841. }
  1842. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1843. if (!lua_interface)
  1844. return 0;
  1845. Spawn* spawn = lua_interface->GetSpawn(state);
  1846. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1847. float value = lua_interface->GetFloatValue(state, 2);
  1848. lua_interface->ResetFunctionStack(state);
  1849. if (spawn && spawn->IsEntity() && value > 0)
  1850. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1851. if (spawn && spawn->IsPlayer())
  1852. ((Player*)spawn)->SetCharSheetChanged(true);
  1853. return 0;
  1854. }
  1855. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1856. if (!lua_interface)
  1857. return 0;
  1858. Spawn* spawn = lua_interface->GetSpawn(state);
  1859. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1860. lua_interface->ResetFunctionStack(state);
  1861. if (spawn && spawn->IsEntity() && value > 0)
  1862. ((Entity*)spawn)->SetTotalHPBase(value);
  1863. return 0;
  1864. }
  1865. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1866. if (!lua_interface)
  1867. return 0;
  1868. Spawn* spawn = lua_interface->GetSpawn(state);
  1869. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1870. lua_interface->ResetFunctionStack(state);
  1871. if (spawn && value > 0) {
  1872. spawn->SetPower(value);
  1873. if (value > spawn->GetTotalPowerBase())
  1874. spawn->SetTotalPower(value);
  1875. }
  1876. return 0;
  1877. }
  1878. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1879. if (!lua_interface)
  1880. return 0;
  1881. Spawn* spawn = lua_interface->GetSpawn(state);
  1882. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1883. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1884. lua_interface->ResetFunctionStack(state);
  1885. if (spawn && spawn->IsEntity() && value > 0)
  1886. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1887. return 0;
  1888. }
  1889. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1890. if (!lua_interface)
  1891. return 0;
  1892. Spawn* spawn = lua_interface->GetSpawn(state);
  1893. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1894. lua_interface->ResetFunctionStack(state);
  1895. if (spawn && spawn->IsEntity() && value > 0)
  1896. ((Entity*)spawn)->SetTotalPowerBase(value);
  1897. return 0;
  1898. }
  1899. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1900. if (!lua_interface)
  1901. return 0;
  1902. Spawn* spawn = lua_interface->GetSpawn(state);
  1903. float x = lua_interface->GetFloatValue(state, 2);
  1904. float y = lua_interface->GetFloatValue(state, 3);
  1905. float z = lua_interface->GetFloatValue(state, 4);
  1906. float heading = lua_interface->GetFloatValue(state, 5);
  1907. lua_interface->ResetFunctionStack(state);
  1908. if (spawn) {
  1909. spawn->SetX(x);
  1910. spawn->SetY(y);
  1911. spawn->SetZ(z);
  1912. if (heading != 0)
  1913. spawn->SetHeading(heading);
  1914. spawn->SetSpawnOrigX(spawn->GetX());
  1915. spawn->SetSpawnOrigY(spawn->GetY());
  1916. spawn->SetSpawnOrigZ(spawn->GetZ());
  1917. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1918. if (spawn->IsPlayer()) {
  1919. Client* client = ((Player*)spawn)->GetClient();
  1920. if (client) {
  1921. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1922. client->QueuePacket(packet);
  1923. }
  1924. }
  1925. }
  1926. return 0;
  1927. }
  1928. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1929. if (!lua_interface)
  1930. return 0;
  1931. Spawn* spawn = lua_interface->GetSpawn(state);
  1932. float value = lua_interface->GetFloatValue(state, 2);
  1933. lua_interface->ResetFunctionStack(state);
  1934. if (spawn) {
  1935. spawn->SetHeading(value);
  1936. if (spawn->IsPlayer()) {
  1937. Client* client = ((Player*)spawn)->GetClient();
  1938. if (client) {
  1939. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1940. client->QueuePacket(packet);
  1941. }
  1942. }
  1943. }
  1944. return 0;
  1945. }
  1946. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1947. if (!lua_interface)
  1948. return 0;
  1949. Spawn* spawn = lua_interface->GetSpawn(state);
  1950. int16 value = lua_interface->GetInt16Value(state, 2);
  1951. lua_interface->ResetFunctionStack(state);
  1952. if (spawn)
  1953. spawn->SetModelType(value);
  1954. return 0;
  1955. }
  1956. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1957. if (!lua_interface)
  1958. return 0;
  1959. Spawn* spawn = lua_interface->GetSpawn(state);
  1960. int8 value = lua_interface->GetInt8Value(state, 2);
  1961. lua_interface->ResetFunctionStack(state);
  1962. if (spawn) {
  1963. if (spawn->IsPlayer())
  1964. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1965. else
  1966. spawn->SetAdventureClass(value);
  1967. }
  1968. return 0;
  1969. }
  1970. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1971. if (!lua_interface)
  1972. return 0;
  1973. Spawn* spawn = lua_interface->GetSpawn(state);
  1974. int8 value = lua_interface->GetInt8Value(state, 2);
  1975. lua_interface->ResetFunctionStack(state);
  1976. if (spawn) {
  1977. spawn->SetTradeskillClass(value);
  1978. if (spawn->IsEntity()) {
  1979. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1980. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1981. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1982. }
  1983. if (spawn->IsPlayer())
  1984. ((Player*)spawn)->SetCharSheetChanged(true);
  1985. }
  1986. return 0;
  1987. }
  1988. int EQ2Emu_lua_SetMount(lua_State* state) {
  1989. if (!lua_interface)
  1990. return 0;
  1991. Spawn* spawn = lua_interface->GetSpawn(state);
  1992. int16 value = lua_interface->GetInt16Value(state, 2);
  1993. if (spawn && spawn->IsEntity()) {
  1994. ((Entity*)spawn)->SetMount(value);
  1995. EQ2_Color color;
  1996. color.red = 255;
  1997. color.green = 255;
  1998. color.blue = 255;
  1999. ((Entity*)spawn)->SetMountColor(&color);
  2000. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2001. }
  2002. return 0;
  2003. }
  2004. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2005. if (!lua_interface)
  2006. return 0;
  2007. Spawn* spawn = lua_interface->GetSpawn(state);
  2008. EQ2_Color mount_color;
  2009. EQ2_Color saddle_color;
  2010. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2011. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2012. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2013. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2014. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2015. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2016. if (spawn && spawn->IsEntity()) {
  2017. ((Entity*)spawn)->SetMountColor(&mount_color);
  2018. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2019. }
  2020. return 0;
  2021. }
  2022. int EQ2Emu_lua_GetMount(lua_State* state) {
  2023. if (!lua_interface)
  2024. return 0;
  2025. Spawn* spawn = lua_interface->GetSpawn(state);
  2026. if (spawn && spawn->IsEntity()) {
  2027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2028. return 1;
  2029. }
  2030. return 0;
  2031. }
  2032. int EQ2Emu_lua_GetRace(lua_State* state) {
  2033. if (!lua_interface)
  2034. return 0;
  2035. Spawn* spawn = lua_interface->GetSpawn(state);
  2036. if (spawn)
  2037. {
  2038. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2039. lua_interface->SetInt32Value(state, spawn->GetRace());
  2040. return 1;
  2041. }
  2042. return 0;
  2043. }
  2044. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2045. if (!lua_interface)
  2046. return 0;
  2047. Spawn* spawn = lua_interface->GetSpawn(state);
  2048. if (spawn) {
  2049. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2050. return 1;
  2051. }
  2052. return 0;
  2053. }
  2054. int EQ2Emu_lua_GetClass(lua_State* state) {
  2055. Spawn* spawn = lua_interface->GetSpawn(state);
  2056. if (spawn) {
  2057. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2058. return 1;
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2063. Spawn* spawn = lua_interface->GetSpawn(state);
  2064. if (spawn) {
  2065. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2066. return 1;
  2067. }
  2068. return 0;
  2069. }
  2070. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2071. if (!lua_interface)
  2072. return 0;
  2073. Spawn* spawn = lua_interface->GetSpawn(state);
  2074. float value = lua_interface->GetFloatValue(state, 2);
  2075. lua_interface->ResetFunctionStack(state);
  2076. if (spawn) {
  2077. spawn->SetSpeed(value);
  2078. if(spawn->IsEntity())
  2079. ((Entity*)spawn)->SetSpeed(value);
  2080. if (spawn->IsPlayer()) {
  2081. Client* client = ((Player*)spawn)->GetClient();
  2082. if (client) {
  2083. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2084. if (packet) {
  2085. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2086. packet->setDataByName("speed", value);
  2087. packet->setDataByName("size", 0.51);
  2088. EQ2Packet* app = packet->serialize();
  2089. client->QueuePacket(app);
  2090. safe_delete(packet);
  2091. }
  2092. }
  2093. }
  2094. }
  2095. return 0;
  2096. }
  2097. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2098. if (!lua_interface)
  2099. return 0;
  2100. Spawn* spawn = lua_interface->GetSpawn(state);
  2101. const int16 type = lua_interface->GetInt16Value(state, 2);
  2102. const float value = lua_interface->GetFloatValue(state, 3);
  2103. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2104. if(!luaspell || luaspell->resisted) {
  2105. return 0;
  2106. }
  2107. int64 class_req = 0;
  2108. int32 class_id = 0;
  2109. vector<int16> faction_req;
  2110. vector<int16> race_req;
  2111. int32 i = 0;
  2112. int8 f = 0;
  2113. int8 r = 0;
  2114. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2115. if (class_id < 100) {
  2116. class_req += pow(2.0, double(class_id - 1));
  2117. }
  2118. else if (class_id > 100 && class_id < 1000) {
  2119. race_req.push_back(class_id);
  2120. r++;
  2121. }
  2122. else {
  2123. faction_req.push_back(class_id);
  2124. f++;
  2125. }
  2126. i++;
  2127. }
  2128. if (value != 0 && type >= 0) {
  2129. if (luaspell && luaspell->spell && luaspell->caster) {
  2130. ZoneServer* zone = luaspell->caster->GetZone();
  2131. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2132. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2133. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2134. if (target) {
  2135. if (target->IsPlayer()) {
  2136. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2137. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2138. if (((Player*)target)->GetGroupMemberInfo())
  2139. ((Player*)target)->UpdateGroupMemberInfo();
  2140. ((Player*)target)->SetCharSheetChanged(true);
  2141. }
  2142. else if (target->IsNPC())
  2143. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2144. else
  2145. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2146. }
  2147. }
  2148. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2149. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2150. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2151. }
  2152. else if (spawn && spawn->IsEntity()) {
  2153. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2154. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2155. if (spawn->IsPlayer())
  2156. ((Player*)spawn)->SetCharSheetChanged(true);
  2157. }
  2158. else
  2159. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2160. }
  2161. else
  2162. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2163. return 0;
  2164. }
  2165. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2166. if (!lua_interface)
  2167. return 0;
  2168. Spawn* spawn = lua_interface->GetSpawn(state);
  2169. int16 type = lua_interface->GetInt16Value(state, 2);
  2170. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2171. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2172. if (!spawn) {
  2173. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2174. return 0;
  2175. }
  2176. if (!spawn->IsEntity()) {
  2177. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2178. return 0;
  2179. }
  2180. if (value == 0) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!luaspell || !luaspell->spell) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if(luaspell->resisted) {
  2189. return 0;
  2190. }
  2191. int32 class_req = 0;
  2192. vector<int16> faction_req;
  2193. vector<int16> race_req;
  2194. int32 class_id = 0;
  2195. int32 i = 0;
  2196. int8 f = 0;
  2197. int8 r = 0;
  2198. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2199. if (class_id < 100) {
  2200. class_req += pow(2.0, double(class_id - 1));
  2201. }
  2202. else if (class_id > 100 && class_id < 1000) {
  2203. race_req.push_back(class_id);
  2204. r++;
  2205. }
  2206. else {
  2207. faction_req.push_back(class_id);
  2208. f++;
  2209. }
  2210. i++;
  2211. }
  2212. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2213. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2214. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2215. if (spawn->IsPlayer())
  2216. ((Player*)spawn)->SetCharSheetChanged(true);
  2217. return 0;
  2218. }
  2219. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2220. if (!lua_interface)
  2221. return 0;
  2222. Spawn* spawn = lua_interface->GetSpawn(state);
  2223. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2224. if (!spawn) {
  2225. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2226. return 0;
  2227. }
  2228. if (!spawn->IsEntity()) {
  2229. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2230. return 0;
  2231. }
  2232. if (!luaspell || !luaspell->spell) {
  2233. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2234. return 0;
  2235. }
  2236. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2237. if (spawn->IsPlayer())
  2238. ((Player*)spawn)->SetCharSheetChanged(true);
  2239. return 0;
  2240. }
  2241. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2242. if (!lua_interface)
  2243. return 0;
  2244. Spawn* spawn = lua_interface->GetSpawn(state);
  2245. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2246. if (luaspell && luaspell->spell) {
  2247. ZoneServer* zone = luaspell->caster->GetZone();
  2248. Spawn* target = 0;
  2249. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2250. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2251. target = zone->GetSpawnByID(luaspell->targets[i]);
  2252. if (target && target->IsEntity()) {
  2253. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2254. if (target->IsPlayer())
  2255. ((Player*)target)->SetCharSheetChanged(true);
  2256. }
  2257. }
  2258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2259. }
  2260. else if (spawn && spawn->IsEntity()) {
  2261. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2262. if (spawn->IsPlayer())
  2263. ((Player*)spawn)->SetCharSheetChanged(true);
  2264. }
  2265. return 0;
  2266. }
  2267. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2268. if (!lua_interface)
  2269. return 0;
  2270. Spawn* spawn = lua_interface->GetSpawn(state);
  2271. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2272. float value = lua_interface->GetFloatValue(state, 3);
  2273. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2274. if (value != 0) {
  2275. int32 spell_id = 0;
  2276. if (luaspell && luaspell->spell && luaspell->caster) {
  2277. if(luaspell->resisted) {
  2278. return 0;
  2279. }
  2280. spell_id = luaspell->spell->GetSpellID();
  2281. ZoneServer* zone = luaspell->caster->GetZone();
  2282. Spawn* target = 0;
  2283. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2284. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2285. target = zone->GetSpawnByID(luaspell->targets[i]);
  2286. if (target && target->Alive()) {
  2287. if (target->IsPlayer()) {
  2288. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2289. Client* client = ((Player*)target)->GetClient();
  2290. if (client) {
  2291. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2292. if (packet)
  2293. client->QueuePacket(packet);
  2294. }
  2295. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2296. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2297. }
  2298. else if (target->IsNPC()) {
  2299. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2300. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2301. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2302. }
  2303. else
  2304. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2305. }
  2306. }
  2307. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2308. }
  2309. else if (spawn) {
  2310. if (spawn->IsPlayer()) {
  2311. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2312. Client* client = ((Player*)spawn)->GetClient();
  2313. if (client) {
  2314. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2315. if (packet)
  2316. client->QueuePacket(packet);
  2317. }
  2318. }
  2319. else if (spawn->IsNPC())
  2320. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2323. }
  2324. }
  2325. else
  2326. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2327. return 0;
  2328. }
  2329. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2330. if (!lua_interface)
  2331. return 0;
  2332. Spawn* spawn = lua_interface->GetSpawn(state);
  2333. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2334. if (spawn && spawn->IsPlayer()) {
  2335. int32 spell_id = 0;
  2336. if (luaspell && luaspell->spell) {
  2337. if(luaspell->resisted) {
  2338. return 0;
  2339. }
  2340. spell_id = luaspell->spell->GetSpellID();
  2341. ZoneServer* zone = luaspell->caster->GetZone();
  2342. Spawn* target = 0;
  2343. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2344. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2345. target = zone->GetSpawnByID(luaspell->targets[i]);
  2346. if (target) {
  2347. if (target->IsPlayer()) {
  2348. ((Player*)target)->RemoveSkillBonus(spell_id);
  2349. Client* client = ((Player*)target)->GetClient();
  2350. if (client) {
  2351. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2352. if (packet)
  2353. client->QueuePacket(packet);
  2354. }
  2355. }
  2356. else if (target->IsNPC())
  2357. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2358. else
  2359. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2360. }
  2361. }
  2362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2363. }
  2364. else if (spawn) {
  2365. if (spawn->IsPlayer()) {
  2366. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2367. Client* client = ((Player*)spawn)->GetClient();
  2368. if (client) {
  2369. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2370. if (packet)
  2371. client->QueuePacket(packet);
  2372. }
  2373. }
  2374. else if (spawn->IsNPC())
  2375. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2376. else
  2377. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2378. }
  2379. }
  2380. return 0;
  2381. }
  2382. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2383. if (!lua_interface)
  2384. return 0;
  2385. Spawn* spawn = lua_interface->GetSpawn(state);
  2386. int8 type = lua_interface->GetInt32Value(state, 2);
  2387. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2388. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2389. if(luaspell && luaspell->resisted) {
  2390. return 0;
  2391. }
  2392. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2393. ZoneServer* zone = luaspell->caster->GetZone();
  2394. Spawn* target = 0;
  2395. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2396. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2397. target = zone->GetSpawnByID(luaspell->targets[i]);
  2398. if (target && target->IsEntity()) {
  2399. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2400. ((Entity*)target)->AddMezSpell(luaspell);
  2401. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2402. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2403. if (target->IsNPC())
  2404. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2405. }
  2406. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2407. ((Entity*)target)->AddStifleSpell(luaspell);
  2408. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2409. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2410. if (target->IsNPC())
  2411. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2412. }
  2413. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2414. ((Entity*)target)->AddDazeSpell(luaspell);
  2415. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2416. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2417. if (target->IsNPC())
  2418. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2419. }
  2420. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2423. ((Entity*)target)->AddStunSpell(luaspell);
  2424. if (target->IsNPC())
  2425. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2426. }
  2427. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2428. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2429. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2430. ((Entity*)target)->AddRootSpell(luaspell);
  2431. if (target->IsNPC())
  2432. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2433. }
  2434. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2437. ((Entity*)target)->AddFearSpell(luaspell);
  2438. if (target->IsNPC())
  2439. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2440. }
  2441. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2442. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2443. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2444. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2445. }
  2446. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2447. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2448. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2449. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2450. }
  2451. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2452. ((Entity*)target)->AddSnareSpell(luaspell);
  2453. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2454. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2455. if (target->IsNPC())
  2456. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2459. ((Entity*)target)->AddFlightSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2464. ((Entity*)target)->AddGlideSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2467. }
  2468. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2469. ((Entity*)target)->AddSafefallSpell(luaspell);
  2470. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2471. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2472. }
  2473. else
  2474. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2475. }
  2476. else
  2477. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2478. }
  2479. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2480. }
  2481. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2482. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2483. ((Entity*)spawn)->AddMezSpell(luaspell);
  2484. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2485. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2486. }
  2487. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2488. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2489. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2490. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2491. }
  2492. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2493. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2494. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2495. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2496. }
  2497. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2498. ((Entity*)spawn)->AddStunSpell(luaspell);
  2499. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2500. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2501. }
  2502. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2503. ((Entity*)spawn)->AddRootSpell(luaspell);
  2504. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2505. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2506. }
  2507. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2508. ((Entity*)spawn)->AddFearSpell(luaspell);
  2509. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2510. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2511. }
  2512. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2513. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2514. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2515. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2516. }
  2517. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2518. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2519. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2520. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2521. }
  2522. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2523. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2524. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2525. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2526. }
  2527. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2528. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2529. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2530. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2531. }
  2532. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2533. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2536. }
  2537. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2538. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2539. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2540. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2541. }
  2542. else
  2543. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2544. }
  2545. else
  2546. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2547. return 0;
  2548. }
  2549. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2550. if (!lua_interface)
  2551. return 0;
  2552. Spawn* spawn = lua_interface->GetSpawn(state);
  2553. int8 type = lua_interface->GetInt8Value(state, 2);
  2554. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2555. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2556. if (spawn && spawn->IsEntity()) {
  2557. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2558. ZoneServer* zone = luaspell->caster->GetZone();
  2559. Spawn* target = 0;
  2560. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2561. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2562. target = zone->GetSpawnByID(luaspell->targets[i]);
  2563. if (target) {
  2564. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2565. ((Entity*)target)->RemoveMezSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2567. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2569. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2571. ((Entity*)target)->RemoveStunSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2573. ((Entity*)target)->RemoveRootSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2575. ((Entity*)target)->RemoveFearSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2577. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2579. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2581. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2583. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2585. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2587. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2588. else
  2589. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2590. }
  2591. }
  2592. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2593. }
  2594. else if (only_remove_spawn) {
  2595. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2596. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2597. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2598. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2599. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2600. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2601. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2602. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2603. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2604. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2605. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2606. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2607. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2608. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2610. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2612. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2614. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2616. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2618. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2619. else
  2620. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2621. }
  2622. }
  2623. return 0;
  2624. }
  2625. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. int8 type = lua_interface->GetInt8Value(state, 2);
  2630. bool hasEffect = false;
  2631. if (!spawn)
  2632. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2633. else if (!spawn->IsEntity())
  2634. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2635. else if (type < CONTROL_MAX_EFFECTS)
  2636. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2637. else
  2638. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2639. lua_interface->SetBooleanValue(state, hasEffect);
  2640. return 1;
  2641. }
  2642. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2643. if (!lua_interface)
  2644. return 0;
  2645. Spawn* spawn = lua_interface->GetSpawn(state);
  2646. float distance = 0.0f;
  2647. if (!spawn)
  2648. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2649. else if (!spawn->IsNPC())
  2650. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2651. else
  2652. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2653. lua_interface->SetFloatValue(state, distance);
  2654. return 1;
  2655. }
  2656. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. float distance = 0.0f;
  2661. if (!spawn)
  2662. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2663. else if (!spawn->IsNPC())
  2664. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2665. else
  2666. distance = ((NPC*)spawn)->GetAggroRadius();
  2667. lua_interface->SetFloatValue(state, distance);
  2668. return 1;
  2669. }
  2670. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. float distance = lua_interface->GetFloatValue(state, 2);
  2675. bool override = lua_interface->GetBooleanValue(state, 3);
  2676. bool result = false;
  2677. lua_interface->ResetFunctionStack(state);
  2678. if (!spawn)
  2679. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2680. else if (!spawn->IsNPC())
  2681. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2682. else
  2683. {
  2684. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2685. result = true;
  2686. }
  2687. lua_interface->SetBooleanValue(state, result);
  2688. return 1;
  2689. }
  2690. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. int16 value = lua_interface->GetInt16Value(state, 2);
  2695. if (spawn && spawn->IsEntity()) {
  2696. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2697. if (spawn->IsPlayer())
  2698. ((Player*)spawn)->SetCharSheetChanged(true);
  2699. }
  2700. return 0;
  2701. }
  2702. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2703. if (!lua_interface)
  2704. return 0;
  2705. Spawn* spawn = lua_interface->GetSpawn(state);
  2706. int16 value = lua_interface->GetInt16Value(state, 2);
  2707. if (spawn && spawn->IsEntity()) {
  2708. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2709. if (spawn->IsPlayer())
  2710. ((Player*)spawn)->SetCharSheetChanged(true);
  2711. }
  2712. return 0;
  2713. }
  2714. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2715. if (!lua_interface)
  2716. return 0;
  2717. Spawn* spawn = lua_interface->GetSpawn(state);
  2718. int16 value = lua_interface->GetInt16Value(state, 2);
  2719. if (spawn && spawn->IsEntity()) {
  2720. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2721. if (spawn->IsPlayer())
  2722. ((Player*)spawn)->SetCharSheetChanged(true);
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. int16 value = lua_interface->GetInt16Value(state, 2);
  2731. if (spawn && spawn->IsEntity()) {
  2732. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2733. if (spawn->IsPlayer())
  2734. ((Player*)spawn)->SetCharSheetChanged(true);
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. int16 value = lua_interface->GetInt16Value(state, 2);
  2743. if (spawn && spawn->IsEntity()) {
  2744. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2745. if (spawn->IsPlayer())
  2746. ((Player*)spawn)->SetCharSheetChanged(true);
  2747. }
  2748. return 0;
  2749. }
  2750. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2751. if (!lua_interface)
  2752. return 0;
  2753. Spawn* spawn = lua_interface->GetSpawn(state);
  2754. int8 value = lua_interface->GetInt8Value(state, 2);
  2755. if (spawn && spawn->IsEntity()) {
  2756. ((Entity*)spawn)->SetDeity(value);
  2757. if (spawn->IsPlayer())
  2758. ((Player*)spawn)->SetCharSheetChanged(true);
  2759. }
  2760. lua_interface->ResetFunctionStack(state);
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. if (spawn && spawn->IsEntity()) {
  2768. int8 deity = ((Entity*)spawn)->GetDeity();
  2769. lua_interface->SetInt32Value(state, deity);
  2770. return 1;
  2771. }
  2772. return 0;
  2773. }
  2774. int EQ2Emu_lua_SetInt(lua_State* state) {
  2775. if (!lua_interface)
  2776. return 0;
  2777. Spawn* spawn = lua_interface->GetSpawn(state);
  2778. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2780. if (spawn && spawn->IsEntity()) {
  2781. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2782. if (spawn->IsPlayer())
  2783. ((Player*)spawn)->SetCharSheetChanged(true);
  2784. }
  2785. return 0;
  2786. }
  2787. int EQ2Emu_lua_SetWis(lua_State* state) {
  2788. if (!lua_interface)
  2789. return 0;
  2790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2791. Spawn* spawn = lua_interface->GetSpawn(state);
  2792. float value = lua_interface->GetFloatValue(state, 2);
  2793. if (spawn && spawn->IsEntity()) {
  2794. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2795. if (spawn->IsPlayer())
  2796. ((Player*)spawn)->SetCharSheetChanged(true);
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_SetSta(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. float value = lua_interface->GetFloatValue(state, 2);
  2805. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2806. if (spawn && spawn->IsEntity()) {
  2807. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2808. if (spawn->IsPlayer())
  2809. ((Player*)spawn)->SetCharSheetChanged(true);
  2810. }
  2811. return 0;
  2812. }
  2813. int EQ2Emu_lua_SetStr(lua_State* state) {
  2814. if (!lua_interface)
  2815. return 0;
  2816. Spawn* spawn = lua_interface->GetSpawn(state);
  2817. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2818. float value = lua_interface->GetFloatValue(state, 2);
  2819. if (spawn && spawn->IsEntity()) {
  2820. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2821. if (spawn->IsPlayer())
  2822. ((Player*)spawn)->SetCharSheetChanged(true);
  2823. }
  2824. return 0;
  2825. }
  2826. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2827. if (!lua_interface)
  2828. return 0;
  2829. Spawn* spawn = lua_interface->GetSpawn(state);
  2830. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2831. float value = lua_interface->GetFloatValue(state, 2);
  2832. if (spawn && spawn->IsEntity()) {
  2833. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2834. if (spawn->IsPlayer())
  2835. ((Player*)spawn)->SetCharSheetChanged(true);
  2836. }
  2837. return 0;
  2838. }
  2839. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2840. if (!lua_interface)
  2841. return 0;
  2842. Spawn* spawn = lua_interface->GetSpawn(state);
  2843. if (spawn) {
  2844. lua_interface->SetInt32Value(state, spawn->GetHP());
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn) {
  2854. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn) {
  2864. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetName(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn) {
  2874. lua_interface->SetStringValue(state, spawn->GetName());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2880. Spawn* spawn = lua_interface->GetSpawn(state);
  2881. if (spawn) {
  2882. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2883. return 1;
  2884. }
  2885. return 0;
  2886. }
  2887. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2888. if (!lua_interface)
  2889. return 0;
  2890. Spawn* spawn = lua_interface->GetSpawn(state);
  2891. if (spawn) {
  2892. lua_interface->SetInt32Value(state, spawn->GetPower());
  2893. return 1;
  2894. }
  2895. return 0;
  2896. }
  2897. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2898. if (!lua_interface)
  2899. return 0;
  2900. Spawn* spawn = lua_interface->GetSpawn(state);
  2901. if (spawn) {
  2902. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. if (spawn) {
  2912. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2913. return 1;
  2914. }
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2922. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2923. if (spawn && spawn2) {
  2924. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2925. lua_interface->SetFloatValue(state, distance);
  2926. return 1;
  2927. }
  2928. return 0;
  2929. }
  2930. int EQ2Emu_lua_GetX(lua_State* state) {
  2931. if (!lua_interface)
  2932. return 0;
  2933. Spawn* spawn = lua_interface->GetSpawn(state);
  2934. if (spawn) {
  2935. lua_interface->SetFloatValue(state, spawn->GetX());
  2936. return 1;
  2937. }
  2938. return 0;
  2939. }
  2940. int EQ2Emu_lua_GetY(lua_State* state) {
  2941. if (!lua_interface)
  2942. return 0;
  2943. Spawn* spawn = lua_interface->GetSpawn(state);
  2944. if (spawn) {
  2945. lua_interface->SetFloatValue(state, spawn->GetY());
  2946. return 1;
  2947. }
  2948. return 0;
  2949. }
  2950. int EQ2Emu_lua_GetZ(lua_State* state) {
  2951. if (!lua_interface)
  2952. return 0;
  2953. Spawn* spawn = lua_interface->GetSpawn(state);
  2954. if (spawn) {
  2955. lua_interface->SetFloatValue(state, spawn->GetZ());
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* spawn = lua_interface->GetSpawn(state);
  2964. if (spawn) {
  2965. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2966. return 1;
  2967. }
  2968. return 0;
  2969. }
  2970. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2971. if (!lua_interface)
  2972. return 0;
  2973. Spawn* spawn = lua_interface->GetSpawn(state);
  2974. if (spawn) {
  2975. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2976. return 1;
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* spawn = lua_interface->GetSpawn(state);
  2984. if (spawn) {
  2985. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2986. return 1;
  2987. }
  2988. return 0;
  2989. }
  2990. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2991. if (!lua_interface)
  2992. return 0;
  2993. Spawn* spawn = lua_interface->GetSpawn(state);
  2994. if (spawn && spawn->IsEntity()) {
  2995. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2996. return 1;
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_GetInt(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* spawn = lua_interface->GetSpawn(state);
  3004. if (spawn && spawn->IsEntity()) {
  3005. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3006. return 1;
  3007. }
  3008. return 0;
  3009. }
  3010. int EQ2Emu_lua_GetWis(lua_State* state) {
  3011. if (!lua_interface)
  3012. return 0;
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn && spawn->IsEntity()) {
  3015. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetSta(lua_State* state) {
  3021. if (!lua_interface)
  3022. return 0;
  3023. Spawn* spawn = lua_interface->GetSpawn(state);
  3024. if (spawn && spawn->IsEntity()) {
  3025. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3026. return 1;
  3027. }
  3028. return 0;
  3029. }
  3030. int EQ2Emu_lua_GetStr(lua_State* state) {
  3031. if (!lua_interface)
  3032. return 0;
  3033. Spawn* spawn = lua_interface->GetSpawn(state);
  3034. if (spawn && spawn->IsEntity()) {
  3035. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3041. if (!lua_interface)
  3042. return 0;
  3043. Spawn* spawn = lua_interface->GetSpawn(state);
  3044. if (spawn && spawn->IsEntity()) {
  3045. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3046. return 1;
  3047. }
  3048. return 0;
  3049. }
  3050. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3051. if (!lua_interface)
  3052. return 0;
  3053. Spawn* spawn = lua_interface->GetSpawn(state);
  3054. if (spawn && spawn->IsEntity()) {
  3055. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3056. return 1;
  3057. }
  3058. return 0;
  3059. }
  3060. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3061. if (!lua_interface)
  3062. return 0;
  3063. Spawn* spawn = lua_interface->GetSpawn(state);
  3064. if (spawn && spawn->IsEntity()) {
  3065. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3066. return 1;
  3067. }
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Spawn* spawn = lua_interface->GetSpawn(state);
  3074. if (spawn && spawn->IsEntity()) {
  3075. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3076. return 1;
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Spawn* spawn = lua_interface->GetSpawn(state);
  3084. if (spawn && spawn->IsEntity()) {
  3085. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3086. return 1;
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* spawn = lua_interface->GetSpawn(state);
  3094. if (spawn && spawn->IsEntity()) {
  3095. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* player = lua_interface->GetSpawn(state);
  3104. if (!player || !player->IsPlayer()) {
  3105. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3106. return 0;
  3107. }
  3108. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3109. if (quest_id <= 0) {
  3110. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3111. return 0;
  3112. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3113. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3114. return 0;
  3115. }
  3116. int32 step = lua_interface->GetInt32Value(state, 3);
  3117. if (step > 0) {
  3118. Client* client = ((Player*)player)->GetClient();
  3119. if (client)
  3120. client->AddPendingQuestUpdate(quest_id, step);
  3121. } else {
  3122. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3123. }
  3124. return 0;
  3125. }
  3126. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3127. Spawn* player = lua_interface->GetSpawn(state);
  3128. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3129. int32 step = lua_interface->GetInt32Value(state, 3);
  3130. int32 progress = lua_interface->GetInt32Value(state, 4);
  3131. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3132. Client* client = ((Player*)player)->GetClient();
  3133. if (client)
  3134. client->AddPendingQuestUpdate(quest_id, step, progress);
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3139. if (!lua_interface)
  3140. return 0;
  3141. Spawn* player = lua_interface->GetSpawn(state);
  3142. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3143. if (player && player->IsPlayer() && quest_id > 0) {
  3144. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3145. return 1;
  3146. }
  3147. return 0;
  3148. }
  3149. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3150. if (!lua_interface)
  3151. return 0;
  3152. Spawn* player = lua_interface->GetSpawn(state);
  3153. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3154. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3155. if (player && player->IsPlayer() && quest_id > 0) {
  3156. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* player = lua_interface->GetSpawn(state);
  3165. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3166. if (player && player->IsPlayer() && quest_id > 0) {
  3167. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3168. return 1;
  3169. }
  3170. return 0;
  3171. }
  3172. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3173. if (!lua_interface)
  3174. return 0;
  3175. Quest* quest = lua_interface->GetQuest(state);
  3176. string name = lua_interface->GetStringValue(state, 2);
  3177. string type = lua_interface->GetStringValue(state, 3);
  3178. string zone = lua_interface->GetStringValue(state, 4);
  3179. int16 level = lua_interface->GetInt16Value(state, 5);
  3180. string description = lua_interface->GetStringValue(state, 6);
  3181. bool load = true;
  3182. if (!quest) {
  3183. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3184. load = false;
  3185. }
  3186. if (load && name.length() == 0) {
  3187. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3188. load = false;
  3189. }
  3190. if (load && type.length() == 0) {
  3191. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3192. load = false;
  3193. }
  3194. if (load && zone.length() == 0) {
  3195. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3196. load = false;
  3197. }
  3198. if (load && description.length() == 0) {
  3199. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3200. load = false;
  3201. }
  3202. if (load && level == 0) {
  3203. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3204. load = false;
  3205. }
  3206. if (load)
  3207. quest->RegisterQuest(name, type, zone, level, description);
  3208. return 0;
  3209. }
  3210. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3211. if (!lua_interface)
  3212. return 0;
  3213. Quest* quest = lua_interface->GetQuest(state);
  3214. if (quest) {
  3215. int8 level = lua_interface->GetInt16Value(state, 2);
  3216. quest->SetPrereqLevel(level);
  3217. }
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Quest* quest = lua_interface->GetQuest(state);
  3224. if (quest) {
  3225. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3226. quest->AddPrereqQuest(quest_id);
  3227. }
  3228. return 0;
  3229. }
  3230. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3231. if (!lua_interface)
  3232. return 0;
  3233. Quest* quest = lua_interface->GetQuest(state);
  3234. if (quest) {
  3235. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3236. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3237. if (quantity == 0)
  3238. quantity = 1;
  3239. Item* master_item = master_item_list.GetItem(item_id);
  3240. if (master_item) {
  3241. Item* item = new Item(master_item);
  3242. item->details.count = quantity;
  3243. quest->AddPrereqItem(item);
  3244. }
  3245. }
  3246. return 0;
  3247. }
  3248. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3249. if (!lua_interface)
  3250. return 0;
  3251. Spawn* player = lua_interface->GetSpawn(state);
  3252. if(!player || !player->IsPlayer()) {
  3253. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3254. return 0;
  3255. }
  3256. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3257. if (quest_id > 0) {
  3258. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3259. return 1;
  3260. } else {
  3261. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3262. }
  3263. return 0;
  3264. }
  3265. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3266. if (!lua_interface)
  3267. return 0;
  3268. Quest* quest = lua_interface->GetQuest(state);
  3269. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3270. lua_interface->ResetFunctionStack(state);
  3271. if (quest && spawn_id > 0)
  3272. quest->SetQuestReturnNPC(spawn_id);
  3273. return 0;
  3274. }
  3275. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3276. if (!lua_interface)
  3277. return 0;
  3278. Spawn* spawn = lua_interface->GetSpawn(state);
  3279. int32 time = lua_interface->GetInt32Value(state, 2);
  3280. string function = lua_interface->GetStringValue(state, 3);
  3281. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3282. Spawn* player = lua_interface->GetSpawn(state, 5);
  3283. lua_interface->ResetFunctionStack(state);
  3284. if (!spawn) {
  3285. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3286. return 0;
  3287. }
  3288. if (time <= 0) {
  3289. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3290. return 0;
  3291. }
  3292. if (function.length() == 0) {
  3293. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3294. return 0;
  3295. }
  3296. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3297. if ( time < 10)
  3298. time = 10;
  3299. timer->timer = Timer::GetCurrentTime2() + time;
  3300. timer->function = function;
  3301. timer->spawn = spawn->GetID();
  3302. timer->player = player ? player->GetID() : 0;
  3303. if (max_count == 0)
  3304. max_count = 1;
  3305. timer->max_count = max_count;
  3306. timer->current_count = 0;
  3307. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3308. return 0;
  3309. }
  3310. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3311. if (!lua_interface)
  3312. return 0;
  3313. Spawn* spawn = lua_interface->GetSpawn(state);
  3314. string function = lua_interface->GetStringValue(state, 2);
  3315. lua_interface->ResetFunctionStack(state);
  3316. if (!spawn) {
  3317. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3318. return 0;
  3319. }
  3320. if(!spawn->GetZone()) {
  3321. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3322. return 0;
  3323. }
  3324. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3325. return 0;
  3326. }
  3327. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3328. if (!lua_interface)
  3329. return 0;
  3330. Spawn* player = lua_interface->GetSpawn(state);
  3331. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3332. lua_interface->ResetFunctionStack(state);
  3333. if (player && player->IsPlayer() && quest_id > 0) {
  3334. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3335. return 1;
  3336. }
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Spawn* player = lua_interface->GetSpawn(state);
  3343. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3344. lua_interface->ResetFunctionStack(state);
  3345. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3346. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3347. if (quest)
  3348. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3349. return 1;
  3350. }
  3351. return 0;
  3352. }
  3353. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3354. if (!lua_interface)
  3355. return 0;
  3356. Spawn* player = lua_interface->GetSpawn(state);
  3357. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3358. lua_interface->ResetFunctionStack(state);
  3359. if (player && player->IsPlayer() && quest_id > 0) {
  3360. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3361. return 1;
  3362. }
  3363. return 0;
  3364. }
  3365. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3366. if (!lua_interface)
  3367. return 0;
  3368. Spawn* npc = lua_interface->GetSpawn(state);
  3369. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3370. lua_interface->ResetFunctionStack(state);
  3371. if (npc && !npc->IsPlayer() && quest_id > 0)
  3372. npc->AddProvidedQuest(quest_id);
  3373. return 0;
  3374. }
  3375. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3376. if (!lua_interface)
  3377. return 0;
  3378. Spawn* npc = lua_interface->GetSpawn(state);
  3379. Spawn* player = lua_interface->GetSpawn(state, 2);
  3380. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3381. bool forced = lua_interface->GetBooleanValue(state, 4);
  3382. lua_interface->ResetFunctionStack(state);
  3383. /* NPC is allowed to be null */
  3384. if (player && player->IsPlayer() && quest_id > 0) {
  3385. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3386. if (master_quest) {
  3387. Client* client = ((Player*)player)->GetClient();
  3388. if (!client) {
  3389. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3390. }
  3391. Quest* quest = new Quest(master_quest);
  3392. if (!quest) {
  3393. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3394. }
  3395. if (client && quest) {
  3396. if (npc)
  3397. quest->SetQuestGiver(npc->GetDatabaseID());
  3398. else
  3399. quest->SetQuestGiver(0);
  3400. client->AddPendingQuest(quest, forced);
  3401. }
  3402. }
  3403. else {
  3404. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3405. }
  3406. }
  3407. else {
  3408. 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);
  3409. }
  3410. return 0;
  3411. }
  3412. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3413. if (!lua_interface)
  3414. return 0;
  3415. Quest* quest = lua_interface->GetQuest(state);
  3416. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3417. lua_interface->ResetFunctionStack(state);
  3418. if (quest) {
  3419. quest->AddPrereqClass(class_id);
  3420. }
  3421. return 0;
  3422. }
  3423. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3424. if (!lua_interface)
  3425. return 0;
  3426. Quest* quest = lua_interface->GetQuest(state);
  3427. int8 race = lua_interface->GetInt8Value(state, 2);
  3428. lua_interface->ResetFunctionStack(state);
  3429. if (quest) {
  3430. quest->AddPrereqRace(race);
  3431. }
  3432. return 0;
  3433. }
  3434. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3435. if (!lua_interface)
  3436. return 0;
  3437. Quest* quest = lua_interface->GetQuest(state);
  3438. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3439. lua_interface->ResetFunctionStack(state);
  3440. if (quest) {
  3441. quest->AddPrereqModelType(model_type);
  3442. }
  3443. return 0;
  3444. }
  3445. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3446. if (!lua_interface)
  3447. return 0;
  3448. Quest* quest = lua_interface->GetQuest(state);
  3449. int8 level = lua_interface->GetInt8Value(state, 2);
  3450. lua_interface->ResetFunctionStack(state);
  3451. if (!quest) {
  3452. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3453. return 0;
  3454. }
  3455. quest->SetPrereqTSLevel(level);
  3456. return 0;
  3457. }
  3458. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3459. if (!lua_interface)
  3460. return 0;
  3461. Quest* quest = lua_interface->GetQuest(state);
  3462. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3463. lua_interface->ResetFunctionStack(state);
  3464. if (!quest) {
  3465. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3466. return 0;
  3467. }
  3468. quest->AddPrereqTradeskillClass(class_id);
  3469. return 0;
  3470. }
  3471. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3472. if (!lua_interface)
  3473. return 0;
  3474. Quest* quest = lua_interface->GetQuest(state);
  3475. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3476. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3477. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3478. lua_interface->ResetFunctionStack(state);
  3479. if (quest) {
  3480. quest->AddPrereqFaction(faction_id, min, max);
  3481. }
  3482. return 0;
  3483. }
  3484. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3485. if (!lua_interface)
  3486. return 0;
  3487. Quest* quest = lua_interface->GetQuest(state);
  3488. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3489. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3490. lua_interface->ResetFunctionStack(state);
  3491. if (quest) {
  3492. if (quantity == 0)
  3493. quantity = 1;
  3494. Item* master_item = master_item_list.GetItem(item_id);
  3495. if (master_item) {
  3496. Item* item = new Item(master_item);
  3497. item->details.count = quantity;
  3498. quest->AddSelectableRewardItem(item);
  3499. }
  3500. }
  3501. return 0;
  3502. }
  3503. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3504. if (!lua_interface)
  3505. return 0;
  3506. Quest* quest = lua_interface->GetQuest(state);
  3507. if (quest) {
  3508. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3509. vector<Item*>* items = quest->GetRewardItems();
  3510. if (items) {
  3511. vector<Item*>::iterator itr;
  3512. for (itr = items->begin(); itr != items->end(); itr++) {
  3513. if (*itr && (*itr)->details.item_id == item_id) {
  3514. lua_interface->SetBooleanValue(state, true);
  3515. return 1;
  3516. }
  3517. }
  3518. }
  3519. }
  3520. lua_interface->SetBooleanValue(state, false);
  3521. return 1;
  3522. }
  3523. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3524. if (!lua_interface)
  3525. return 0;
  3526. Quest* quest = lua_interface->GetQuest(state);
  3527. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3528. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3529. lua_interface->ResetFunctionStack(state);
  3530. if (quest) {
  3531. if (quantity == 0)
  3532. quantity = 1;
  3533. Item* master_item = master_item_list.GetItem(item_id);
  3534. if (master_item) {
  3535. Item* item = new Item(master_item);
  3536. item->details.count = quantity;
  3537. quest->AddRewardItem(item);
  3538. }
  3539. }
  3540. return 0;
  3541. }
  3542. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3543. if (!lua_interface)
  3544. return 0;
  3545. Quest* quest = lua_interface->GetQuest(state);
  3546. int32 copper = lua_interface->GetInt32Value(state, 2);
  3547. int32 silver = lua_interface->GetInt32Value(state, 3);
  3548. int32 gold = lua_interface->GetInt32Value(state, 4);
  3549. int32 plat = lua_interface->GetInt32Value(state, 5);
  3550. lua_interface->ResetFunctionStack(state);
  3551. if (quest) {
  3552. quest->AddRewardCoins(copper, silver, gold, plat);
  3553. }
  3554. return 0;
  3555. }
  3556. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3557. if (!lua_interface)
  3558. return 0;
  3559. Quest* quest = lua_interface->GetQuest(state);
  3560. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3561. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3562. lua_interface->ResetFunctionStack(state);
  3563. if (quest && faction_id > 0 && amount != 0)
  3564. quest->AddRewardFaction(faction_id, amount);
  3565. return 0;
  3566. }
  3567. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3568. if (!lua_interface)
  3569. return 0;
  3570. Quest* quest = lua_interface->GetQuest(state);
  3571. int32 status = lua_interface->GetInt32Value(state, 2);
  3572. lua_interface->ResetFunctionStack(state);
  3573. if (quest) {
  3574. quest->SetRewardStatus(status);
  3575. }
  3576. return 0;
  3577. }
  3578. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3579. if (!lua_interface)
  3580. return 0;
  3581. Quest* quest = lua_interface->GetQuest(state);
  3582. int32 status = lua_interface->GetInt32Value(state, 2);
  3583. lua_interface->ResetFunctionStack(state);
  3584. if (quest) {
  3585. quest->SetStatusTmpReward(status);
  3586. }
  3587. return 0;
  3588. }
  3589. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3590. if (!lua_interface)
  3591. return 0;
  3592. Quest* quest = lua_interface->GetQuest(state);
  3593. int64 coins = lua_interface->GetInt64Value(state, 2);
  3594. lua_interface->ResetFunctionStack(state);
  3595. if (quest) {
  3596. quest->SetCoinTmpReward(coins);
  3597. }
  3598. return 0;
  3599. }
  3600. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3601. if (!lua_interface)
  3602. return 0;
  3603. Quest* quest = lua_interface->GetQuest(state);
  3604. string comment = lua_interface->GetStringValue(state, 2);
  3605. lua_interface->ResetFunctionStack(state);
  3606. if (quest) {
  3607. quest->SetRewardComment(comment);
  3608. }
  3609. return 0;
  3610. }
  3611. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3612. if (!lua_interface)
  3613. return 0;
  3614. Quest* quest = lua_interface->GetQuest(state);
  3615. int32 exp = lua_interface->GetInt32Value(state, 2);
  3616. lua_interface->ResetFunctionStack(state);
  3617. if (quest) {
  3618. quest->SetRewardXP(exp);
  3619. }
  3620. return 0;
  3621. }
  3622. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3623. Quest* quest = lua_interface->GetQuest(state);
  3624. int32 step = lua_interface->GetInt32Value(state, 2);
  3625. string description = lua_interface->GetStringValue(state, 3);
  3626. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3627. float percentage = lua_interface->GetFloatValue(state, 5);
  3628. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3629. int16 icon = lua_interface->GetInt16Value(state, 7);
  3630. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3631. if (quest) {
  3632. const char* taskgroup = 0;
  3633. if (str_taskgroup.length() > 0)
  3634. taskgroup = str_taskgroup.c_str();
  3635. int32 id = 0;
  3636. vector<int32>* ids = 0;
  3637. int i = 0;
  3638. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3639. if (ids == 0)
  3640. ids = new vector<int32>;
  3641. ids->push_back(id);
  3642. i++;
  3643. }
  3644. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3645. if (quest_step && icon && quantity > 0)
  3646. quest_step->SetIcon(icon);
  3647. if (quest->GetPlayer()) {
  3648. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3649. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3650. }
  3651. }
  3652. lua_interface->ResetFunctionStack(state);
  3653. return 0;
  3654. }
  3655. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3656. {
  3657. if (!lua_interface)
  3658. return 0;
  3659. Quest* quest = lua_interface->GetQuest(state);
  3660. int32 step = lua_interface->GetInt32Value(state, 2);
  3661. string description = lua_interface->GetStringValue(state, 3);
  3662. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3663. float percentage = lua_interface->GetFloatValue(state, 5);
  3664. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3665. int16 icon = lua_interface->GetInt16Value(state, 7);
  3666. if (quest) {
  3667. const char* taskgroup = 0;
  3668. if (str_taskgroup.length() > 0)
  3669. taskgroup = str_taskgroup.c_str();
  3670. int32 id = 0;
  3671. vector<int32>* ids = 0;
  3672. int i = 0;
  3673. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3674. if (ids == 0)
  3675. ids = new vector<int32>;
  3676. ids->push_back(id);
  3677. i++;
  3678. }
  3679. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3680. if (quest_step && icon > 0 && quantity > 0)
  3681. quest_step->SetIcon(icon);
  3682. if (quest->GetPlayer()) {
  3683. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3684. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3685. }
  3686. safe_delete(ids);
  3687. }
  3688. lua_interface->ResetFunctionStack(state);
  3689. return 0;
  3690. }
  3691. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3692. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3693. }
  3694. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3695. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3696. }
  3697. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. int32 step = lua_interface->GetInt32Value(state, 2);
  3702. string description = lua_interface->GetStringValue(state, 3);
  3703. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3704. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3705. int16 icon = lua_interface->GetInt16Value(state, 6);
  3706. if (quest) {
  3707. const char* taskgroup = 0;
  3708. if (str_taskgroup.length() > 0)
  3709. taskgroup = str_taskgroup.c_str();
  3710. int32 npc_id = 0;
  3711. vector<int32>* ids = 0;
  3712. int i = 0;
  3713. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3714. if (ids == 0)
  3715. ids = new vector<int32>;
  3716. ids->push_back(npc_id);
  3717. i++;
  3718. }
  3719. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3720. if (quest_step && icon > 0)
  3721. quest_step->SetIcon(icon);
  3722. if (quest->GetPlayer()) {
  3723. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3724. if(client)
  3725. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3726. }
  3727. safe_delete(ids);
  3728. }
  3729. lua_interface->ResetFunctionStack(state);
  3730. return 0;
  3731. }
  3732. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3733. if (!lua_interface)
  3734. return 0;
  3735. Quest* quest = lua_interface->GetQuest(state);
  3736. int32 step = lua_interface->GetInt32Value(state, 2);
  3737. string description = lua_interface->GetStringValue(state, 3);
  3738. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3739. float percentage = lua_interface->GetFloatValue(state, 5);
  3740. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3741. int16 icon = lua_interface->GetInt16Value(state, 7);
  3742. if (quest) {
  3743. const char* taskgroup = 0;
  3744. if (str_taskgroup.length() > 0)
  3745. taskgroup = str_taskgroup.c_str();
  3746. int32 item_id = 0;
  3747. vector<int32>* ids = 0;
  3748. int i = 0;
  3749. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3750. if (ids == 0)
  3751. ids = new vector<int32>;
  3752. ids->push_back(item_id);
  3753. i++;
  3754. }
  3755. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3756. if (quest_step && icon > 0 && quantity > 0)
  3757. quest_step->SetIcon(icon);
  3758. if (quest->GetPlayer()) {
  3759. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3760. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3761. }
  3762. safe_delete(ids);
  3763. }
  3764. lua_interface->ResetFunctionStack(state);
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Quest* quest = lua_interface->GetQuest(state);
  3771. int32 step = lua_interface->GetInt32Value(state, 2);
  3772. string description = lua_interface->GetStringValue(state, 3);
  3773. float max_variation = lua_interface->GetFloatValue(state, 4);
  3774. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3775. int16 icon = lua_interface->GetInt16Value(state, 6);
  3776. if (quest) {
  3777. const char* taskgroup = 0;
  3778. if (str_taskgroup.length() > 0)
  3779. taskgroup = str_taskgroup.c_str();
  3780. vector<Location>* locations = 0;
  3781. int8 i = 7;
  3782. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3783. while (true) {
  3784. Location loc;
  3785. loc.x = lua_interface->GetFloatValue(state, i);
  3786. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3787. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3788. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3789. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3790. break;
  3791. if (locations == 0)
  3792. locations = new vector<Location>;
  3793. locations->push_back(loc);
  3794. i += 4;
  3795. }
  3796. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3797. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3798. if (quest_step && icon > 0)
  3799. quest_step->SetIcon(icon);
  3800. if (quest->GetPlayer()) {
  3801. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3802. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3803. }
  3804. }
  3805. lua_interface->ResetFunctionStack(state);
  3806. return 0;
  3807. }
  3808. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3809. if (!lua_interface)
  3810. return 0;
  3811. Quest* quest = lua_interface->GetQuest(state);
  3812. int32 step = lua_interface->GetInt32Value(state, 2);
  3813. string description = lua_interface->GetStringValue(state, 3);
  3814. float max_variation = lua_interface->GetFloatValue(state, 4);
  3815. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3816. int16 icon = lua_interface->GetInt16Value(state, 6);
  3817. if (quest) {
  3818. const char* taskgroup = 0;
  3819. if (str_taskgroup.length() > 0)
  3820. taskgroup = str_taskgroup.c_str();
  3821. vector<Location>* locations = 0;
  3822. int8 i = 7;
  3823. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3824. while (true) {
  3825. Location loc;
  3826. loc.x = lua_interface->GetFloatValue(state, i);
  3827. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3828. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3829. loc.zone_id = 0;
  3830. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3831. break;
  3832. if (locations == 0)
  3833. locations = new vector<Location>;
  3834. locations->push_back(loc);
  3835. i += 3;
  3836. }
  3837. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3838. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3839. if (quest_step && icon > 0)
  3840. quest_step->SetIcon(icon);
  3841. if (quest->GetPlayer()) {
  3842. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3843. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3844. }
  3845. }
  3846. lua_interface->ResetFunctionStack(state);
  3847. return 0;
  3848. }
  3849. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3850. if (!lua_interface)
  3851. return 0;
  3852. Quest* quest = lua_interface->GetQuest(state);
  3853. int32 step = lua_interface->GetInt32Value(state, 2);
  3854. string description = lua_interface->GetStringValue(state, 3);
  3855. float max_variation = lua_interface->GetFloatValue(state, 4);
  3856. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3857. int16 icon = lua_interface->GetInt16Value(state, 6);
  3858. if (quest) {
  3859. const char* taskgroup = 0;
  3860. if (str_taskgroup.length() > 0)
  3861. taskgroup = str_taskgroup.c_str();
  3862. vector<Location>* locations = 0;
  3863. int i = 7;
  3864. while (true) {
  3865. Location loc;
  3866. loc.x = lua_interface->GetFloatValue(state, i);
  3867. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3868. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3869. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3870. break;
  3871. if (locations == 0)
  3872. locations = new vector<Location>;
  3873. locations->push_back(loc);
  3874. i += 3;
  3875. }
  3876. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3877. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3878. if (quest_step && icon > 0)
  3879. quest_step->SetIcon(icon);
  3880. if (quest->GetPlayer()) {
  3881. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3882. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3883. }
  3884. }
  3885. lua_interface->ResetFunctionStack(state);
  3886. return 0;
  3887. }
  3888. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3889. Quest* quest = lua_interface->GetQuest(state);
  3890. int32 step = lua_interface->GetInt32Value(state, 2);
  3891. string description = lua_interface->GetStringValue(state, 3);
  3892. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3893. float percentage = lua_interface->GetFloatValue(state, 5);
  3894. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3895. int16 icon = lua_interface->GetInt16Value(state, 7);
  3896. if (quest) {
  3897. const char* taskgroup = 0;
  3898. if (str_taskgroup.length() > 0)
  3899. taskgroup = str_taskgroup.c_str();
  3900. int32 spell_id = 0;
  3901. vector<int32>* ids = 0;
  3902. int i = 0;
  3903. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3904. if (ids == 0)
  3905. ids = new vector<int32>;
  3906. ids->push_back(spell_id);
  3907. i++;
  3908. }
  3909. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3910. if (quest_step && icon > 0 && quantity > 0)
  3911. quest_step->SetIcon(icon);
  3912. if (quest->GetPlayer()) {
  3913. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3914. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3915. }
  3916. safe_delete(ids);
  3917. }
  3918. lua_interface->ResetFunctionStack(state);
  3919. return 0;
  3920. }
  3921. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3922. if (!lua_interface)
  3923. return 0;
  3924. Quest* quest = lua_interface->GetQuest(state);
  3925. int32 step = lua_interface->GetInt32Value(state, 2);
  3926. string description = lua_interface->GetStringValue(state, 3);
  3927. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3928. float percentage = lua_interface->GetFloatValue(state, 5);
  3929. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3930. int16 icon = lua_interface->GetInt16Value(state, 7);
  3931. if (quest) {
  3932. const char* taskgroup = 0;
  3933. if (str_taskgroup.length() > 0)
  3934. taskgroup = str_taskgroup.c_str();
  3935. int32 item_id = 0;
  3936. vector<int32>* ids = 0;
  3937. int i = 0;
  3938. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3939. if (ids == 0)
  3940. ids = new vector<int32>;
  3941. ids->push_back(item_id);
  3942. i++;
  3943. }
  3944. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3945. if (quest_step && icon > 0 && quantity > 0)
  3946. quest_step->SetIcon(icon);
  3947. if (quest->GetPlayer()) {
  3948. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3949. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3950. }
  3951. safe_delete(ids);
  3952. }
  3953. lua_interface->ResetFunctionStack(state);
  3954. return 0;
  3955. }
  3956. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3957. if (!lua_interface)
  3958. return 0;
  3959. Quest* quest = lua_interface->GetQuest(state);
  3960. int32 step = lua_interface->GetInt32Value(state, 2);
  3961. string description = lua_interface->GetStringValue(state, 3);
  3962. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3963. float percentage = lua_interface->GetFloatValue(state, 5);
  3964. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3965. int16 icon = lua_interface->GetInt16Value(state, 7);
  3966. if (quest) {
  3967. const char* taskgroup = 0;
  3968. if (str_taskgroup.length() > 0)
  3969. taskgroup = str_taskgroup.c_str();
  3970. int32 item_id = 0;
  3971. vector<int32>* ids = 0;
  3972. int i = 0;
  3973. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3974. if (ids == 0)
  3975. ids = new vector<int32>;
  3976. ids->push_back(item_id);
  3977. i++;
  3978. }
  3979. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3980. if (quest_step && icon > 0 && quantity > 0)
  3981. quest_step->SetIcon(icon);
  3982. if (quest->GetPlayer()) {
  3983. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3984. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3985. }
  3986. safe_delete(ids);
  3987. }
  3988. lua_interface->ResetFunctionStack(state);
  3989. return 0;
  3990. }
  3991. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3992. if (!lua_interface)
  3993. return 0;
  3994. Quest* quest = lua_interface->GetQuest(state);
  3995. string action = lua_interface->GetStringValue(state, 2);
  3996. lua_interface->ResetFunctionStack(state);
  3997. if (quest) {
  3998. if (action.length() > 0)
  3999. quest->SetCompleteAction(action);
  4000. }
  4001. return 0;
  4002. }
  4003. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4004. if (!lua_interface)
  4005. return 0;
  4006. Quest* quest = lua_interface->GetQuest(state);
  4007. int32 step = lua_interface->GetInt32Value(state, 2);
  4008. string action = lua_interface->GetStringValue(state, 3);
  4009. lua_interface->ResetFunctionStack(state);
  4010. if (quest) {
  4011. if (step > 0 && action.length() > 0)
  4012. quest->AddCompleteAction(step, action);
  4013. }
  4014. return 0;
  4015. }
  4016. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4017. if (!lua_interface)
  4018. return 0;
  4019. Quest* quest = lua_interface->GetQuest(state);
  4020. int32 step = lua_interface->GetInt32Value(state, 2);
  4021. string action = lua_interface->GetStringValue(state, 3);
  4022. lua_interface->ResetFunctionStack(state);
  4023. if (quest) {
  4024. if (step > 0 && action.length() > 0)
  4025. quest->AddProgressAction(step, action);
  4026. }
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4030. if (!lua_interface)
  4031. return 0;
  4032. Quest* quest = lua_interface->GetQuest(state);
  4033. string description = lua_interface->GetStringValue(state, 2);
  4034. lua_interface->ResetFunctionStack(state);
  4035. if (quest && description.length() > 0)
  4036. quest->SetDescription(description);
  4037. return 0;
  4038. }
  4039. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4040. if (!lua_interface)
  4041. return 0;
  4042. Quest* quest = lua_interface->GetQuest(state);
  4043. string description = lua_interface->GetStringValue(state, 2);
  4044. lua_interface->ResetFunctionStack(state);
  4045. if (quest && description.length() > 0)
  4046. quest->SetCompletedDescription(description);
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Quest* quest = lua_interface->GetQuest(state);
  4053. int32 step = lua_interface->GetInt32Value(state, 2);
  4054. string description = lua_interface->GetStringValue(state, 3);
  4055. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4056. lua_interface->ResetFunctionStack(state);
  4057. if (quest && step > 0 && description.length() > 0) {
  4058. quest->SetTaskGroupDescription(step, description, display_bullets);
  4059. /* if (quest->GetPlayer()) {
  4060. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4061. if (client)
  4062. client->SendQuestUpdateStep(quest, step, false);
  4063. }*/
  4064. }
  4065. return 0;
  4066. }
  4067. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4068. if (!lua_interface)
  4069. return 0;
  4070. Quest* quest = lua_interface->GetQuest(state);
  4071. int32 step = lua_interface->GetInt32Value(state, 2);
  4072. string description = lua_interface->GetStringValue(state, 3);
  4073. lua_interface->ResetFunctionStack(state);
  4074. if (quest && step > 0 && description.length() > 0) {
  4075. quest->SetStepDescription(step, description);
  4076. /*if (quest->GetPlayer()) {
  4077. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4078. if (client)
  4079. client->SendQuestUpdateStepImmediately(quest, step);
  4080. }*/
  4081. }
  4082. return 0;
  4083. }
  4084. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4085. Quest* quest = lua_interface->GetQuest(state);
  4086. string zone = lua_interface->GetStringValue(state, 2);
  4087. lua_interface->ResetFunctionStack(state);
  4088. if (quest && zone.length() > 0)
  4089. quest->SetZone(zone);
  4090. return 0;
  4091. }
  4092. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4093. if (!lua_interface)
  4094. return 0;
  4095. Quest* quest = lua_interface->GetQuest(state);
  4096. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4097. lua_interface->ResetFunctionStack(state);
  4098. if (quest && spawn) {
  4099. if (spawn->IsPlayer()) {
  4100. Client* client = ((Player*)spawn)->GetClient();
  4101. if (client) {
  4102. client->AddPendingQuestReward(quest);
  4103. }
  4104. }
  4105. }
  4106. return 0;
  4107. }
  4108. int EQ2Emu_lua_Harvest(lua_State* state) {
  4109. if (!lua_interface)
  4110. return 0;
  4111. Spawn* player = lua_interface->GetSpawn(state);
  4112. Spawn* node = lua_interface->GetSpawn(state, 2);
  4113. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4114. Client* client = ((Player*)player)->GetClient();
  4115. if (client) {
  4116. ((GroundSpawn*)node)->ProcessHarvest(client);
  4117. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4118. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4119. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4120. }
  4121. }
  4122. }
  4123. else if (player && player->IsPlayer()) {
  4124. Client* client = ((Player*)player)->GetClient();
  4125. if (client)
  4126. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4127. }
  4128. lua_interface->ResetFunctionStack(state);
  4129. return 0;
  4130. }
  4131. int EQ2Emu_lua_Bind(lua_State* state) {
  4132. if (!lua_interface)
  4133. return 0;
  4134. Spawn* spawn = lua_interface->GetSpawn(state);
  4135. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4136. float x = lua_interface->GetFloatValue(state, 3);
  4137. float y = lua_interface->GetFloatValue(state, 4);
  4138. float z = lua_interface->GetFloatValue(state, 5);
  4139. float h = lua_interface->GetFloatValue(state, 6);
  4140. lua_interface->ResetFunctionStack(state);
  4141. if (!spawn) {
  4142. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4143. return 0;
  4144. }
  4145. if (!spawn->IsPlayer()) {
  4146. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4147. return 0;
  4148. }
  4149. if (zone_id == 0) {
  4150. Client* client = ((Player*)spawn)->GetClient();
  4151. if (!client) {
  4152. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4153. return 0;
  4154. }
  4155. if (!client->Bind())
  4156. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4157. }
  4158. else {
  4159. Player* player = (Player*)spawn;
  4160. player->GetPlayerInfo()->SetBindZone(zone_id);
  4161. player->GetPlayerInfo()->SetBindX(x);
  4162. player->GetPlayerInfo()->SetBindY(y);
  4163. player->GetPlayerInfo()->SetBindZ(z);
  4164. player->GetPlayerInfo()->SetBindHeading(h);
  4165. }
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_Gate(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4172. Spawn* spawn = lua_interface->GetSpawn(state);
  4173. lua_interface->ResetFunctionStack(state);
  4174. if (spawn) {
  4175. if (spawn->IsPlayer()) {
  4176. Client* client = ((Player*)spawn)->GetClient();
  4177. if (client) {
  4178. if (!client->Gate((spell != nullptr) ? true : false))
  4179. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4180. }
  4181. }
  4182. }
  4183. return 0;
  4184. }
  4185. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4186. if (!lua_interface)
  4187. return 0;
  4188. bool ret = false;
  4189. Spawn* spawn = lua_interface->GetSpawn(state);
  4190. lua_interface->ResetFunctionStack(state);
  4191. if (spawn) {
  4192. if (spawn->IsPlayer()) {
  4193. Client* client = ((Player*)spawn)->GetClient();
  4194. if (client)
  4195. ret = client->BindAllowed();
  4196. }
  4197. }
  4198. lua_interface->SetBooleanValue(state, ret);
  4199. return 1;
  4200. }
  4201. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4202. if (!lua_interface)
  4203. return 0;
  4204. bool ret = false;
  4205. Spawn* spawn = lua_interface->GetSpawn(state);
  4206. lua_interface->ResetFunctionStack(state);
  4207. if (spawn) {
  4208. if (spawn->IsPlayer()) {
  4209. Client* client = ((Player*)spawn)->GetClient();
  4210. ZoneServer* zone = lua_interface->GetZone(state);
  4211. if (client && zone){
  4212. ret = zone->GetCanGate();
  4213. }
  4214. }
  4215. }
  4216. lua_interface->SetBooleanValue(state, ret);
  4217. return 1;
  4218. }
  4219. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4220. Spawn* spawn = lua_interface->GetSpawn(state);
  4221. lua_interface->ResetFunctionStack(state);
  4222. if (spawn) {
  4223. lua_interface->SetBooleanValue(state, spawn->Alive());
  4224. return 1;
  4225. }
  4226. return 0;
  4227. }
  4228. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4229. if (!lua_interface)
  4230. return 0;
  4231. Spawn* spawn = lua_interface->GetSpawn(state);
  4232. lua_interface->ResetFunctionStack(state);
  4233. if (spawn && spawn->IsEntity()) {
  4234. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4235. return 1;
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4240. Spawn* spawn = lua_interface->GetSpawn(state);
  4241. string message = lua_interface->GetStringValue(state, 2);
  4242. string color_str = lua_interface->GetStringValue(state, 3);
  4243. lua_interface->ResetFunctionStack(state);
  4244. int8 color = CHANNEL_NARRATIVE;
  4245. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4246. Client* client = ((Player*)spawn)->GetClient();
  4247. if (client) {
  4248. if (color_str.length() > 0) {
  4249. // leave for backwards compat, but all future should just use the number
  4250. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4251. color = CHANNEL_COLOR_RED;
  4252. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4253. color = CHANNEL_COLOR_YELLOW;
  4254. else
  4255. {
  4256. // use a number to specify the channel as per Commands/Commands.h defines
  4257. color = (int8)atoul(color_str.c_str());
  4258. }
  4259. }
  4260. client->SimpleMessage(color, message.c_str());
  4261. }
  4262. }
  4263. return 0;
  4264. }
  4265. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4266. Spawn* spawn = lua_interface->GetSpawn(state);
  4267. string message = lua_interface->GetStringValue(state, 2);
  4268. int8 red = lua_interface->GetInt8Value(state, 3);
  4269. int8 green = lua_interface->GetInt8Value(state, 4);
  4270. int8 blue = lua_interface->GetInt8Value(state, 5);
  4271. lua_interface->ResetFunctionStack(state);
  4272. if (!spawn) {
  4273. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (!spawn->IsPlayer()) {
  4277. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4278. return 0;
  4279. }
  4280. int32 words = ::CountWordsInString(message.c_str());
  4281. if (words < 5)
  4282. words = 5;
  4283. Client* client = ((Player*)spawn)->GetClient();
  4284. if (client)
  4285. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4286. return 0;
  4287. }
  4288. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4289. Spawn* spawn = lua_interface->GetSpawn(state);
  4290. int8 param = lua_interface->GetInt8Value(state, 2);
  4291. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4292. int8 value = lua_interface->GetInt8Value(state, 4);
  4293. lua_interface->ResetFunctionStack(state);
  4294. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4295. Client* client = ((Player*)spawn)->GetClient();
  4296. if (client) {
  4297. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4298. switch (param) {
  4299. case 1: {
  4300. packet->setDataByName("parameter1", param_value);
  4301. break;
  4302. }
  4303. case 2: {
  4304. packet->setDataByName("parameter2", param_value);
  4305. break;
  4306. }
  4307. case 3: {
  4308. packet->setDataByName("parameter3", param_value);
  4309. break;
  4310. }
  4311. case 4: {
  4312. packet->setDataByName("parameter4", param_value);
  4313. break;
  4314. }
  4315. case 5: {
  4316. packet->setDataByName("parameter5", param_value);
  4317. break;
  4318. }
  4319. }
  4320. packet->setDataByName("value", value);
  4321. client->QueuePacket(packet->serialize());
  4322. safe_delete(packet);
  4323. }
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4328. Spawn* spawn = lua_interface->GetSpawn(state);
  4329. lua_interface->ResetFunctionStack(state);
  4330. if (spawn && spawn->IsPlayer()) {
  4331. if (((Player*)spawn)->GetIsTracking())
  4332. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4333. else
  4334. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4335. }
  4336. return 0;
  4337. }
  4338. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4339. Spawn* player = lua_interface->GetSpawn(state);
  4340. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4341. string name = lua_interface->GetStringValue(state, 3);
  4342. float distance = lua_interface->GetFloatValue(state, 4);
  4343. string command = lua_interface->GetStringValue(state, 5);
  4344. string error_text = lua_interface->GetStringValue(state, 6);
  4345. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4346. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4347. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4348. lua_interface->ResetFunctionStack(state);
  4349. if (spawn) {
  4350. if (distance == 0)
  4351. distance = 10.0f;
  4352. if (command.length() == 0)
  4353. command = name;
  4354. if (command.length() < 1 && name.length() < 1)
  4355. {
  4356. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4357. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4358. spawn->RemovePrimaryCommands();
  4359. }
  4360. else
  4361. {
  4362. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4363. }
  4364. }
  4365. return 0;
  4366. }
  4367. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4368. if (!lua_interface)
  4369. return 0;
  4370. Spawn* player = lua_interface->GetSpawn(state);
  4371. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4372. int16 tier = lua_interface->GetInt16Value(state, 3);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (player && player->IsPlayer()) {
  4375. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4376. return 1;
  4377. }
  4378. return 0;
  4379. }
  4380. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4381. if (!lua_interface)
  4382. return 0;
  4383. Spawn* player = lua_interface->GetSpawn(state);
  4384. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4385. int16 tier = lua_interface->GetInt16Value(state, 3);
  4386. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4387. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4388. bool add_to_hotbar = true;
  4389. if (num_args > 4) {
  4390. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4391. }
  4392. lua_interface->ResetFunctionStack(state);
  4393. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4394. if (player && spell && player->IsPlayer()) {
  4395. Client* client = player->GetClient();
  4396. if (client) {
  4397. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4398. {
  4399. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4400. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4401. client->GetPlayer()->UnlockSpell(spell);
  4402. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4403. }
  4404. else
  4405. {
  4406. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4407. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4408. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4409. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4410. client->GetPlayer()->UnlockSpell(spell);
  4411. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4412. }
  4413. //if (client ) {
  4414. // ((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);
  4415. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4416. if (outapp)
  4417. client->QueuePacket(outapp);
  4418. }
  4419. }
  4420. return 0;
  4421. }
  4422. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4423. if (!lua_interface)
  4424. return 0;
  4425. Spawn* player = lua_interface->GetSpawn(state);
  4426. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4427. lua_interface->ResetFunctionStack(state);
  4428. if (player && player->IsPlayer()) {
  4429. Client* client = player->GetClient();
  4430. if (client) {
  4431. ((Player*)player)->DeleteSpellBook(type_selection);
  4432. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4433. if (outapp)
  4434. client->QueuePacket(outapp);
  4435. }
  4436. }
  4437. return 0;
  4438. }
  4439. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4440. if (!lua_interface)
  4441. return 0;
  4442. Spawn* player = lua_interface->GetSpawn(state);
  4443. lua_interface->ResetFunctionStack(state);
  4444. if (player && player->IsPlayer()) {
  4445. Client* client = player->GetClient();
  4446. if (client) {
  4447. client->SendNewAdventureSpells();
  4448. }
  4449. }
  4450. return 0;
  4451. }
  4452. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4453. if (!lua_interface)
  4454. return 0;
  4455. Spawn* player = lua_interface->GetSpawn(state);
  4456. lua_interface->ResetFunctionStack(state);
  4457. if (player && player->IsPlayer()) {
  4458. Client* client = player->GetClient();
  4459. if (client) {
  4460. client->SendNewTradeskillSpells();
  4461. }
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4466. if (!lua_interface)
  4467. return 0;
  4468. Spawn* player = lua_interface->GetSpawn(state);
  4469. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4470. lua_interface->ResetFunctionStack(state);
  4471. if (player && player->IsPlayer()) {
  4472. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4473. Client* client = player->GetClient();
  4474. if (sbe && client) {
  4475. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4476. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4477. if (outapp)
  4478. client->QueuePacket(outapp);
  4479. }
  4480. }
  4481. return 0;
  4482. }
  4483. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4484. if (!lua_interface)
  4485. return 0;
  4486. Spawn* player = lua_interface->GetSpawn(state);
  4487. lua_interface->ResetFunctionStack(state);
  4488. if (player && player->IsPlayer()) {
  4489. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4490. return 1;
  4491. }
  4492. return 0;
  4493. }
  4494. int EQ2Emu_lua_Attack(lua_State* state) {
  4495. if (lua_interface) {
  4496. Spawn* npc = lua_interface->GetSpawn(state);
  4497. Spawn* player = lua_interface->GetSpawn(state, 2);
  4498. lua_interface->ResetFunctionStack(state);
  4499. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4500. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4501. }
  4502. return 0;
  4503. }
  4504. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4505. if (lua_interface) {
  4506. Spawn* target = lua_interface->GetSpawn(state);
  4507. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4508. lua_interface->ResetFunctionStack(state);
  4509. if (target && target->GetZone())
  4510. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4511. }
  4512. return 0;
  4513. }
  4514. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4515. Spawn* player;
  4516. if (lua_interface) {
  4517. player = lua_interface->GetSpawn(state);
  4518. lua_interface->ResetFunctionStack(state);
  4519. if (player && player->IsPlayer()) {
  4520. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4521. return 1;
  4522. }
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4527. Spawn* player;
  4528. Client* client;
  4529. if (lua_interface) {
  4530. player = lua_interface->GetSpawn(state);
  4531. lua_interface->ResetFunctionStack(state);
  4532. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4533. if ((client = ((Player*)player)->GetClient()))
  4534. client->HandInCollections();
  4535. }
  4536. return 0;
  4537. }
  4538. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4539. Spawn* widget;
  4540. if (lua_interface) {
  4541. widget = lua_interface->GetSpawn(state);
  4542. lua_interface->ResetFunctionStack(state);
  4543. if (widget && widget->IsWidget())
  4544. ((Widget*)widget)->HandleUse(nullptr, "");
  4545. }
  4546. return 0;
  4547. }
  4548. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4549. Spawn* spawn = 0;
  4550. int32 primary_list = 0;
  4551. int32 secondary_list = 0;
  4552. if (lua_interface) {
  4553. spawn = lua_interface->GetSpawn(state);
  4554. primary_list = lua_interface->GetInt32Value(state, 2);
  4555. secondary_list = lua_interface->GetInt32Value(state, 3);
  4556. lua_interface->ResetFunctionStack(state);
  4557. if (!spawn->IsNPC()) {
  4558. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4559. return 0;
  4560. }
  4561. NPC* npc = (NPC*)spawn;
  4562. npc->SetPrimarySpellList(primary_list);
  4563. npc->SetSecondarySpellList(secondary_list);
  4564. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4565. }
  4566. return 0;
  4567. }
  4568. int EQ2Emu_lua_GetPet(lua_State* state) {
  4569. if (!lua_interface)
  4570. return 0;
  4571. Spawn* spawn = lua_interface->GetSpawn(state);
  4572. lua_interface->ResetFunctionStack(state);
  4573. if (spawn) {
  4574. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4575. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4576. return 1;
  4577. }
  4578. }
  4579. return 0;
  4580. }
  4581. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4582. if (!lua_interface)
  4583. return 0;
  4584. Spawn* spawn = lua_interface->GetSpawn(state);
  4585. lua_interface->ResetFunctionStack(state);
  4586. if (spawn) {
  4587. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4588. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4589. return 1;
  4590. }
  4591. }
  4592. return 0;
  4593. }
  4594. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4595. if (!lua_interface)
  4596. return 0;
  4597. Spawn* spawn = lua_interface->GetSpawn(state);
  4598. lua_interface->ResetFunctionStack(state);
  4599. if (spawn) {
  4600. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4601. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4602. return 1;
  4603. }
  4604. }
  4605. return 0;
  4606. }
  4607. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4608. if (!lua_interface)
  4609. return 0;
  4610. Spawn* spawn = lua_interface->GetSpawn(state);
  4611. lua_interface->ResetFunctionStack(state);
  4612. if (spawn) {
  4613. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4614. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4615. return 1;
  4616. }
  4617. }
  4618. return 0;
  4619. }
  4620. int EQ2Emu_lua_Charm(lua_State* state) {
  4621. if (!lua_interface)
  4622. return 0;
  4623. Spawn* owner = lua_interface->GetSpawn(state);
  4624. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4625. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4626. lua_interface->ResetFunctionStack(state);
  4627. if (!luaspell) {
  4628. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4629. return 0;
  4630. }
  4631. if(luaspell->resisted) {
  4632. return 0;
  4633. }
  4634. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4635. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4636. pet->SetPet(true);
  4637. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4638. ((NPC*)pet)->SetOwner((Entity*)owner);
  4639. // If owner is player and player does not have a summoned pet set the players charsheet
  4640. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4641. Player* player = (Player*)owner;
  4642. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4643. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4644. player->GetInfoStruct()->set_pet_movement(2);
  4645. player->GetInfoStruct()->set_pet_behavior(3);
  4646. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4647. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4648. // Make sure the values get sent to the client
  4649. player->SetCharSheetChanged(true);
  4650. }
  4651. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4652. pet->SetSpawnScript("");
  4653. // Set faction to the same as the owner
  4654. pet->SetFactionID(owner->GetFactionID());
  4655. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4656. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4657. // Clear hate list
  4658. ((NPC*)pet)->Brain()->ClearHate();
  4659. // Set the brain to a pet brain
  4660. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4661. }
  4662. return 0;
  4663. }
  4664. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4665. if (!lua_interface)
  4666. return 0;
  4667. Spawn* spawn = lua_interface->GetSpawn(state);
  4668. lua_interface->ResetFunctionStack(state);
  4669. if (!spawn) {
  4670. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4671. return 0;
  4672. }
  4673. vector<Spawn*> groupMembers;
  4674. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4675. groupMembers = *spawn->GetSpawnGroup();
  4676. }
  4677. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4678. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4679. deque<GroupMemberInfo*>::iterator itr;
  4680. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4681. if (group)
  4682. {
  4683. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4684. deque<GroupMemberInfo*>* members = group->GetMembers();
  4685. GroupMemberInfo* info = 0;
  4686. for (itr = members->begin(); itr != members->end(); itr++) {
  4687. info = *itr;
  4688. if (info->client)
  4689. groupMembers.push_back(info->client->GetPlayer());
  4690. }
  4691. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4692. }
  4693. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4694. }
  4695. else
  4696. return 0;
  4697. lua_createtable(state, groupMembers.size(), 0);
  4698. int newTable = lua_gettop(state);
  4699. for (int32 i = 0; i < groupMembers.size(); i++) {
  4700. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4701. lua_rawseti(state, newTable, i + 1);
  4702. }
  4703. return 1;
  4704. }
  4705. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4706. if (!lua_interface)
  4707. return 0;
  4708. lua_interface->ResetFunctionStack(state);
  4709. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4710. lua_interface->SetOptionWindowValue(state, option_window);
  4711. return 1;
  4712. }
  4713. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4714. if (!lua_interface)
  4715. return 0;
  4716. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4717. if (option_window) {
  4718. OptionWindowOption option_window_option;
  4719. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4720. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4721. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4722. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4723. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4724. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4725. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4726. option_window->push_back(option_window_option);
  4727. }
  4728. lua_interface->ResetFunctionStack(state);
  4729. return 0;
  4730. }
  4731. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4732. if (!lua_interface)
  4733. return 0;
  4734. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4735. Spawn* player = lua_interface->GetSpawn(state, 2);
  4736. string window_title = lua_interface->GetStringValue(state, 3);
  4737. string cancel_command = lua_interface->GetStringValue(state, 4);
  4738. lua_interface->ResetFunctionStack(state);
  4739. if (!player->IsPlayer()) {
  4740. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4741. return 0;
  4742. }
  4743. Client* client = ((Player*)player)->GetClient();
  4744. if (option_window && window_title.length() > 0 && client) {
  4745. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4746. if (!packet)
  4747. return 0;
  4748. packet->setDataByName("title_text", window_title.c_str());
  4749. if (cancel_command.length() > 0)
  4750. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4751. packet->setArrayLengthByName("num_selections", option_window->size());
  4752. vector<OptionWindowOption>::iterator itr;
  4753. int8 i = 0;
  4754. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4755. OptionWindowOption opt = *itr;
  4756. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4757. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4758. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4759. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4760. if (opt.optionCommand.length() > 0)
  4761. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4762. if (opt.optionConfirmTitle.length() > 0)
  4763. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4764. i++;
  4765. }
  4766. client->QueuePacket(packet->serialize());
  4767. lua_interface->SetLuaUserDataStale(option_window);
  4768. safe_delete(option_window);
  4769. safe_delete(packet);
  4770. }
  4771. return 0;
  4772. }
  4773. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4774. if (!lua_interface)
  4775. return 0;
  4776. Spawn* spawn = lua_interface->GetSpawn(state);
  4777. lua_interface->ResetFunctionStack(state);
  4778. if (spawn) {
  4779. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4780. return 1;
  4781. }
  4782. else
  4783. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4784. return 0;
  4785. }
  4786. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4787. if (!lua_interface)
  4788. return 0;
  4789. Spawn* spawn = lua_interface->GetSpawn(state);
  4790. lua_interface->ResetFunctionStack(state);
  4791. if (spawn) {
  4792. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4793. return 1;
  4794. }
  4795. else
  4796. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4797. return 0;
  4798. }
  4799. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4800. if (!lua_interface)
  4801. return 0;
  4802. Spawn* spawn = lua_interface->GetSpawn(state);
  4803. lua_interface->ResetFunctionStack(state);
  4804. if (spawn) {
  4805. int8 class_id = spawn->GetTradeskillClass();
  4806. // Need to add 42 for the offset in the array
  4807. class_id += 44;
  4808. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4809. return 1;
  4810. }
  4811. else
  4812. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4813. return 0;
  4814. }
  4815. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4816. if (!lua_interface)
  4817. return 0;
  4818. Spawn* spawn = lua_interface->GetSpawn(state);
  4819. int16 level = lua_interface->GetInt8Value(state, 2);
  4820. lua_interface->ResetFunctionStack(state);
  4821. if (spawn) {
  4822. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4823. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4824. else
  4825. spawn->SetTSLevel(level);
  4826. }
  4827. else
  4828. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4829. return 0;
  4830. }
  4831. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4832. if (!lua_interface)
  4833. return 0;
  4834. Spawn* spawn = lua_interface->GetSpawn(state);
  4835. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4836. lua_interface->ResetFunctionStack(state);
  4837. if (spawn) {
  4838. spawn->SetAttackable(attackable);
  4839. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4840. }
  4841. return 0;
  4842. }
  4843. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4844. // Check to see if we have a valid lua_interface
  4845. if (!lua_interface)
  4846. return 0;
  4847. // Get the spawn that is getting the pet
  4848. Spawn* spawn = lua_interface->GetSpawn(state);
  4849. // Get the DB ID of the pet
  4850. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4851. // The max level the pet can gain
  4852. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4853. // Get the spell that this command was called from
  4854. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4855. lua_interface->ResetFunctionStack(state);
  4856. // Check to make sure the spawn pointer is valid
  4857. if (!spawn) {
  4858. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4859. return 0;
  4860. }
  4861. // Check to make sure the spawn is an entity
  4862. if (!spawn->IsEntity()) {
  4863. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4864. return 0;
  4865. }
  4866. // Check to make sure the spawn doesn't already have a pet of this type
  4867. if (((Entity*)spawn)->GetPet()) {
  4868. if (spawn->IsPlayer()) {
  4869. Client* client = ((Player*)spawn)->GetClient();
  4870. if (client)
  4871. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4872. }
  4873. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4874. return 0;
  4875. }
  4876. // Check to see if the DB ID for the pet is set
  4877. if (pet_id == 0) {
  4878. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4879. return 0;
  4880. }
  4881. // Check to see if the pointer to the spell is valid
  4882. if (!luaspell) {
  4883. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4884. return 0;
  4885. }
  4886. if(luaspell->resisted) {
  4887. return 0;
  4888. }
  4889. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4890. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4891. if (!pet) {
  4892. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4893. return 0;
  4894. }
  4895. // Check to make sure the pet is an npc
  4896. if (!pet->IsNPC()) {
  4897. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4898. return 0;
  4899. }
  4900. // Spawn the pet at the same location as the owner
  4901. pet->SetX(spawn->GetX());
  4902. pet->SetY(spawn->GetY());
  4903. pet->SetZ(spawn->GetZ());
  4904. pet->SetLocation(spawn->GetLocation());
  4905. pet->SetHeading(spawn->GetHeading());
  4906. std::string petName = std::string("");
  4907. if(spawn->IsEntity()) {
  4908. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4909. }
  4910. if(petName.size() < 1) {
  4911. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4912. petName = spawn->GetZone()->pet_names.at(rand_index);
  4913. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4914. }
  4915. // If player set various values for the char sheet (pet window)
  4916. if (spawn->IsPlayer()) {
  4917. Player* player = (Player*)spawn;
  4918. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4919. player->GetInfoStruct()->set_pet_name(petName);
  4920. player->GetInfoStruct()->set_pet_movement(2);
  4921. player->GetInfoStruct()->set_pet_behavior(3);
  4922. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4923. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4924. // Make sure the values get sent to the client
  4925. player->SetCharSheetChanged(true);
  4926. }
  4927. // Set the pets name
  4928. pet->SetName(petName.c_str());
  4929. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4930. if (max_level > 0)
  4931. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4932. else
  4933. pet->SetLevel(spawn->GetLevel());
  4934. // Set the max level this pet can reach
  4935. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4936. // Set the faction of the pet to the same faction as the owner
  4937. pet->SetFactionID(spawn->GetFactionID());
  4938. // Set the spawn as a pet
  4939. pet->SetPet(true);
  4940. // Give a pointer of the owner to the pet
  4941. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4942. // Give a pointer of the pet to the owner
  4943. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4944. // Set the pet type
  4945. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4946. // Set the spell id used to create this pet
  4947. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4948. // Set the spell tier used to create this pet
  4949. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4950. // Set the pets spawn type to 6
  4951. pet->SetSpawnType(6);
  4952. // Set the pets brain
  4953. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4954. // Check to see if the pet has a subtitle
  4955. if (strlen(pet->GetSubTitle()) > 0) {
  4956. // Add the players name to the front of the sub title
  4957. string pet_subtitle;
  4958. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4959. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4960. // Set the pets subtitle to the new one
  4961. pet->SetSubTitle(pet_subtitle.c_str());
  4962. }
  4963. // Add the "Pet Options" entity command to the pet
  4964. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4965. const char* spawn_script = world.GetSpawnScript(pet_id);
  4966. bool runScript = false;
  4967. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4968. runScript = true;
  4969. pet->SetSpawnScript(string(spawn_script));
  4970. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  4971. }
  4972. spawn->GetZone()->AddSpawn(pet);
  4973. if(runScript){
  4974. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  4975. }
  4976. // Set the pet as the return value for this function
  4977. lua_interface->SetSpawnValue(state, pet);
  4978. return 1;
  4979. }
  4980. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4981. if (!lua_interface)
  4982. return 0;
  4983. Spawn* spawn = lua_interface->GetSpawn(state);
  4984. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4986. lua_interface->ResetFunctionStack(state);
  4987. if (!spawn) {
  4988. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. if (!spawn->IsEntity()) {
  4992. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4993. return 0;
  4994. }
  4995. if (((Entity*)spawn)->GetDeityPet()) {
  4996. if (spawn->IsPlayer()) {
  4997. Client* client = ((Player*)spawn)->GetClient();
  4998. if (client)
  4999. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5000. }
  5001. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5002. return 0;
  5003. }
  5004. if (pet_id == 0) {
  5005. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5006. return 0;
  5007. }
  5008. if (!luaspell) {
  5009. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. if(luaspell->resisted) {
  5013. return 0;
  5014. }
  5015. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5016. if (!pet) {
  5017. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5018. return 0;
  5019. }
  5020. if (!pet->IsNPC()) {
  5021. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5022. return 0;
  5023. }
  5024. pet->SetX(spawn->GetX());
  5025. pet->SetY(spawn->GetY());
  5026. pet->SetZ(spawn->GetZ());
  5027. pet->SetLocation(spawn->GetLocation());
  5028. pet->SetHeading(spawn->GetHeading());
  5029. spawn->GetZone()->AddSpawn(pet);
  5030. string random_pet_name;
  5031. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5032. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5033. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5034. pet->SetName(random_pet_name.c_str());
  5035. pet->SetLevel(spawn->GetLevel());
  5036. pet->SetFactionID(spawn->GetFactionID());
  5037. pet->SetPet(true);
  5038. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5039. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5040. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5041. pet->SetSpawnType(6);
  5042. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5043. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5044. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5045. if (strlen(pet->GetSubTitle()) > 0) {
  5046. string pet_subtitle;
  5047. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5048. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5049. pet->SetSubTitle(pet_subtitle.c_str());
  5050. }
  5051. // deity and cosmetic pets are not attackable
  5052. pet->SetAttackable(false);
  5053. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5054. lua_interface->SetSpawnValue(state, pet);
  5055. return 1;
  5056. }
  5057. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5058. if (!lua_interface)
  5059. return 0;
  5060. Spawn* spawn = lua_interface->GetSpawn(state);
  5061. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5062. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5063. lua_interface->ResetFunctionStack(state);
  5064. if (!spawn) {
  5065. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5066. return 0;
  5067. }
  5068. if (!spawn->IsEntity()) {
  5069. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5070. return 0;
  5071. }
  5072. if (((Entity*)spawn)->GetCosmeticPet()) {
  5073. if (spawn->IsPlayer()) {
  5074. Client* client = ((Player*)spawn)->GetClient();
  5075. if (client)
  5076. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5077. }
  5078. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5079. return 0;
  5080. }
  5081. if (pet_id == 0) {
  5082. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5083. return 0;
  5084. }
  5085. if (!luaspell) {
  5086. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5087. return 0;
  5088. }
  5089. if(luaspell->resisted) {
  5090. return 0;
  5091. }
  5092. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5093. if (!pet) {
  5094. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5095. return 0;
  5096. }
  5097. if (!pet->IsNPC()) {
  5098. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5099. return 0;
  5100. }
  5101. pet->SetX(spawn->GetX());
  5102. pet->SetY(spawn->GetY());
  5103. pet->SetZ(spawn->GetZ());
  5104. pet->SetLocation(spawn->GetLocation());
  5105. pet->SetHeading(spawn->GetHeading());
  5106. spawn->GetZone()->AddSpawn(pet);
  5107. string random_pet_name;
  5108. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5109. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5110. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5111. pet->SetName(random_pet_name.c_str());
  5112. pet->SetLevel(spawn->GetLevel());
  5113. pet->SetFactionID(spawn->GetFactionID());
  5114. pet->SetPet(true);
  5115. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5116. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5117. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5118. pet->SetSpawnType(6);
  5119. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5120. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5121. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5122. if (strlen(pet->GetSubTitle()) > 0) {
  5123. string pet_subtitle;
  5124. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5125. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5126. pet->SetSubTitle(pet_subtitle.c_str());
  5127. }
  5128. pet->SetAttackable(false);
  5129. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5130. lua_interface->SetSpawnValue(state, pet);
  5131. return 1;
  5132. }
  5133. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5134. if (!lua_interface)
  5135. return 0;
  5136. Spawn* spawn = lua_interface->GetSpawn(state);
  5137. lua_interface->ResetFunctionStack(state);
  5138. if (!spawn) {
  5139. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5140. return 0;
  5141. }
  5142. if (!spawn->IsPet()) {
  5143. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5144. return 0;
  5145. }
  5146. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5147. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5148. return 0;
  5149. }
  5150. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5151. if (!lua_interface)
  5152. return 0;
  5153. Quest* quest = lua_interface->GetQuest(state);
  5154. if (!quest) {
  5155. 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));
  5156. lua_interface->ResetFunctionStack(state);
  5157. return 0;
  5158. }
  5159. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5160. lua_interface->ResetFunctionStack(state);
  5161. if (feather_color > 0)
  5162. quest->SetFeatherColor(feather_color);
  5163. return 0;
  5164. }
  5165. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5166. if (!lua_interface)
  5167. return 0;
  5168. Spawn* spawn = lua_interface->GetSpawn(state);
  5169. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5170. lua_interface->ResetFunctionStack(state);
  5171. if (!spawn) {
  5172. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5173. return 0;
  5174. }
  5175. if (!spawn2) {
  5176. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5177. return 0;
  5178. }
  5179. spawn->RemoveSpawnAccess(spawn2);
  5180. return 0;
  5181. }
  5182. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5183. if (!lua_interface)
  5184. return 0;
  5185. ZoneServer* zone = lua_interface->GetZone(state);
  5186. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5187. lua_interface->ResetFunctionStack(state);
  5188. if (!zone) {
  5189. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. if (location_id == 0) {
  5193. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5197. if (!location) {
  5198. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5199. return 0;
  5200. }
  5201. Spawn* spawn = 0;
  5202. if (location->entities[0]) {
  5203. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5204. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5205. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5206. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5207. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5208. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5209. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5210. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5211. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5212. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5213. if(spawn && spawn->IsOmittedByDBFlag())
  5214. {
  5215. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5216. safe_delete(spawn);
  5217. spawn = 0;
  5218. return 0;
  5219. }
  5220. if (spawn) {
  5221. const char* script = 0;
  5222. for (int x = 0; x < 3; x++) {
  5223. switch (x) {
  5224. case 0:
  5225. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5226. break;
  5227. case 1:
  5228. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5229. break;
  5230. case 2:
  5231. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5232. break;
  5233. }
  5234. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5235. spawn->SetSpawnScript(string(script));
  5236. break;
  5237. }
  5238. }
  5239. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5240. lua_interface->SetSpawnValue(state, spawn);
  5241. return 1;
  5242. }
  5243. else {
  5244. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5245. safe_delete(spawn);
  5246. }
  5247. }
  5248. return 0;
  5249. }
  5250. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5251. if (!lua_interface)
  5252. return 0;
  5253. Spawn* caster = lua_interface->GetSpawn(state);
  5254. Spawn* target = lua_interface->GetSpawn(state, 2);
  5255. int32 id = lua_interface->GetInt32Value(state, 3);
  5256. string command = lua_interface->GetStringValue(state, 4);
  5257. lua_interface->ResetFunctionStack(state);
  5258. if (!caster) {
  5259. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5260. return 0;
  5261. }
  5262. if (!target) {
  5263. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5264. return 0;
  5265. }
  5266. if (!caster->IsPlayer()) {
  5267. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5268. return 0;
  5269. }
  5270. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5271. if (!entity_command) {
  5272. 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());
  5273. return 0;
  5274. }
  5275. Client* client = ((Player*)caster)->GetClient();
  5276. if (!client) {
  5277. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5278. return 0;
  5279. }
  5280. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5281. return 0;
  5282. }
  5283. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5284. if (!lua_interface)
  5285. return 0;
  5286. Spawn* spawn = lua_interface->GetSpawn(state);
  5287. lua_interface->ResetFunctionStack(state);
  5288. if (!spawn) {
  5289. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5290. return 0;
  5291. }
  5292. if (!spawn->IsNPC()) {
  5293. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5294. return 0;
  5295. }
  5296. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5297. return 0;
  5298. }
  5299. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5300. if (!lua_interface)
  5301. return 0;
  5302. Spawn* spawn = lua_interface->GetSpawn(state);
  5303. int16 tick = lua_interface->GetInt16Value(state, 2);
  5304. lua_interface->ResetFunctionStack(state);
  5305. if (!spawn) {
  5306. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. if (!spawn->IsNPC()) {
  5310. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5311. return 0;
  5312. }
  5313. if (tick < 20) {
  5314. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. ((NPC*)spawn)->Brain()->SetTick(tick);
  5318. return 0;
  5319. }
  5320. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5321. if (!lua_interface)
  5322. return 0;
  5323. Spawn* spawn = lua_interface->GetSpawn(state);
  5324. Spawn* target = lua_interface->GetSpawn(state, 2);
  5325. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5326. lua_interface->ResetFunctionStack(state);
  5327. if (!spawn) {
  5328. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5329. return 0;
  5330. }
  5331. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5332. spawn->SetFollowTarget(target, follow_distance);
  5333. return 0;
  5334. }
  5335. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5336. if (!lua_interface)
  5337. return 0;
  5338. Spawn* spawn = lua_interface->GetSpawn(state);
  5339. lua_interface->ResetFunctionStack(state);
  5340. if (!spawn) {
  5341. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5342. return 0;
  5343. }
  5344. Spawn* target = spawn->GetFollowTarget();
  5345. if (target) {
  5346. lua_interface->SetSpawnValue(state, target);
  5347. return 1;
  5348. }
  5349. return 0;
  5350. }
  5351. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5352. if (!lua_interface)
  5353. return 0;
  5354. Spawn* spawn = lua_interface->GetSpawn(state);
  5355. lua_interface->ResetFunctionStack(state);
  5356. if (!spawn) {
  5357. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5358. return 0;
  5359. }
  5360. if (spawn->following)
  5361. spawn->following = false;
  5362. else
  5363. spawn->following = true;
  5364. return 0;
  5365. }
  5366. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5367. if (!lua_interface)
  5368. return 0;
  5369. Spawn* spawn = lua_interface->GetSpawn(state);
  5370. lua_interface->ResetFunctionStack(state);
  5371. if (!spawn) {
  5372. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5373. return 0;
  5374. }
  5375. lua_interface->SetBooleanValue(state, spawn->following);
  5376. return 1;
  5377. }
  5378. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5379. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5380. // I will attempt to explain how this function works for future refrence
  5381. // Fist lets make sure lua_interface is valid, if not return out
  5382. if (!lua_interface)
  5383. return 0;
  5384. // Next we grab the first 2 params same as we usually would
  5385. Spawn* spawn = lua_interface->GetSpawn(state);
  5386. string var = lua_interface->GetStringValue(state, 2);
  5387. // 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
  5388. // 1 = Spawn
  5389. // 2 = Zone
  5390. // 3 = Item
  5391. // 4 = Quest
  5392. // 5 = String
  5393. // 6 = nil (null)
  5394. int8 dataType = 0;
  5395. // Define pointers for each potential type
  5396. Spawn* spawnVal = 0;
  5397. ZoneServer* zone = 0;
  5398. Item* item = 0;
  5399. Quest* quest = 0;
  5400. string val;
  5401. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5402. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5403. // options window are also light user data be we do not handle those.
  5404. // We check with lua_islightuserdata(lua_State*, index)
  5405. if (lua_islightuserdata(state, 3)) {
  5406. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5407. // and convert it to LUAUserData*
  5408. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5409. // Check to make sure the data we got is valid, if not give an error
  5410. if (!data || !data->IsCorrectlyInitialized()) {
  5411. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5412. }
  5413. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5414. else if (data->IsSpawn()) {
  5415. spawnVal = data->spawn;
  5416. dataType = 1;
  5417. }
  5418. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5419. else if (data->IsZone()) {
  5420. zone = data->zone;
  5421. dataType = 2;
  5422. }
  5423. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5424. else if (data->IsItem()) {
  5425. item = data->item;
  5426. dataType = 3;
  5427. }
  5428. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5429. else if (data->IsQuest()) {
  5430. quest = data->quest;
  5431. dataType = 4;
  5432. }
  5433. }
  5434. // Wasn't light user data, check if it is nil(null)
  5435. else if (lua_isnil(state, 3)) {
  5436. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5437. dataType = 6;
  5438. }
  5439. // Wasn't light user data or nil (null), must be a string
  5440. else {
  5441. // Set the string and dataType variable
  5442. val = lua_interface->GetStringValue(state, 3);
  5443. dataType = 5;
  5444. }
  5445. lua_interface->ResetFunctionStack(state);
  5446. // We now have all the params, lets check to make sure they are valid
  5447. if (!spawn) {
  5448. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5449. return 0;
  5450. }
  5451. if (var.length() == 0) {
  5452. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. if (dataType == 0) {
  5456. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5457. return 0;
  5458. }
  5459. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5460. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5461. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5462. switch (dataType) {
  5463. case 1:
  5464. // 1 = Spawn
  5465. spawn->AddTempVariable(var, spawnVal);
  5466. break;
  5467. case 2:
  5468. // 2 = Zone
  5469. spawn->AddTempVariable(var, zone);
  5470. break;
  5471. case 3:
  5472. // 3 = Item
  5473. spawn->AddTempVariable(var, item);
  5474. break;
  5475. case 4:
  5476. // 4 = Quest
  5477. spawn->AddTempVariable(var, quest);
  5478. break;
  5479. case 5:
  5480. // 5 = String
  5481. spawn->AddTempVariable(var, val);
  5482. break;
  5483. case 6:
  5484. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5485. spawn->DeleteTempVariable(var);
  5486. break;
  5487. }
  5488. // And we are done so return out
  5489. return 0;
  5490. }
  5491. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5492. if (!lua_interface)
  5493. return 0;
  5494. Spawn* spawn = lua_interface->GetSpawn(state);
  5495. string var = lua_interface->GetStringValue(state, 2);
  5496. lua_interface->ResetFunctionStack(state);
  5497. if (!spawn) {
  5498. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5499. return 0;
  5500. }
  5501. if (var.length() == 0) {
  5502. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5503. return 0;
  5504. }
  5505. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5506. int8 type = spawn->GetTempVariableType(var);
  5507. Spawn* spawn2 = 0;
  5508. ZoneServer* zone = 0;
  5509. Item* item = 0;
  5510. Quest* quest = 0;
  5511. // Set the lua function return value based on the type of data the variable contains
  5512. switch (type) {
  5513. case 1:
  5514. spawn2 = spawn->GetTempVariableSpawn(var);
  5515. if (!spawn2)
  5516. return 0;
  5517. lua_interface->SetSpawnValue(state, spawn2);
  5518. break;
  5519. case 2:
  5520. zone = spawn->GetTempVariableZone(var);
  5521. if (!zone)
  5522. return 0;
  5523. lua_interface->SetZoneValue(state, zone);
  5524. break;
  5525. case 3:
  5526. item = spawn->GetTempVariableItem(var);
  5527. if (!item)
  5528. return 0;
  5529. lua_interface->SetItemValue(state, item);
  5530. break;
  5531. case 4:
  5532. quest = spawn->GetTempVariableQuest(var);
  5533. if (!quest)
  5534. return 0;
  5535. lua_interface->SetQuestValue(state, quest);
  5536. break;
  5537. case 5:
  5538. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5539. break;
  5540. default:
  5541. // Not a valid type then the variable was not set so return out
  5542. return 0;
  5543. }
  5544. // Return value was set so return out
  5545. return 1;
  5546. }
  5547. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5548. {
  5549. if (!lua_interface)
  5550. return 0;
  5551. Quest* quest = lua_interface->GetQuest(state);
  5552. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5553. string description = lua_interface->GetStringValue(state, 3);
  5554. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5555. if (!quest) {
  5556. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5557. lua_interface->ResetFunctionStack(state);
  5558. lua_interface->SetBooleanValue(state, false);
  5559. return 1;
  5560. }
  5561. if (!spawn) {
  5562. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5563. lua_interface->ResetFunctionStack(state);
  5564. lua_interface->SetBooleanValue(state, false);
  5565. return 1;
  5566. }
  5567. if (!spawn->IsPlayer()) {
  5568. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5569. lua_interface->ResetFunctionStack(state);
  5570. lua_interface->SetBooleanValue(state, false);
  5571. return 1;
  5572. }
  5573. if (item_id == 0) {
  5574. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5575. lua_interface->ResetFunctionStack(state);
  5576. lua_interface->SetBooleanValue(state, false);
  5577. return 1;
  5578. }
  5579. Client* client = ((Player*)spawn)->GetClient();
  5580. if (!client) {
  5581. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5582. lua_interface->ResetFunctionStack(state);
  5583. lua_interface->SetBooleanValue(state, false);
  5584. return 1;
  5585. }
  5586. Item* item = master_item_list.GetItem(item_id);
  5587. if (!item) {
  5588. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5589. lua_interface->ResetFunctionStack(state);
  5590. lua_interface->SetBooleanValue(state, false);
  5591. return 1;
  5592. }
  5593. Item* firstItem = new Item(item);
  5594. quest->AddTmpRewardItem(firstItem);
  5595. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5596. bool itemsAddedSuccessfully = true;
  5597. if(num_args > 4)
  5598. {
  5599. for(int8 n=5;n<num_args+1;n++)
  5600. {
  5601. int32 new_item = lua_interface->GetInt32Value(state, n);
  5602. Item* tmpItem = master_item_list.GetItem(new_item);
  5603. if(tmpItem)
  5604. {
  5605. Item* newTmpItem = new Item(tmpItem);
  5606. quest->AddTmpRewardItem(newTmpItem);
  5607. }
  5608. else
  5609. itemsAddedSuccessfully = false;
  5610. }
  5611. }
  5612. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5613. lua_interface->ResetFunctionStack(state);
  5614. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5615. return 1;
  5616. }
  5617. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5618. if (!lua_interface)
  5619. return 0;
  5620. Quest* quest = lua_interface->GetQuest(state);
  5621. lua_interface->ResetFunctionStack(state);
  5622. if (!quest) {
  5623. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5624. return 0;
  5625. }
  5626. quest->SetRepeatable(true);
  5627. return 0;
  5628. }
  5629. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5630. if (!lua_interface)
  5631. return 0;
  5632. Spawn* spawn = lua_interface->GetSpawn(state);
  5633. lua_interface->ResetFunctionStack(state);
  5634. if (!spawn) {
  5635. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5636. return 0;
  5637. }
  5638. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5639. string ret = classes.GetClassNameCase(base_class);
  5640. if (ret.length() > 0) {
  5641. lua_interface->SetStringValue(state, ret.c_str());
  5642. return 1;
  5643. }
  5644. return 0;
  5645. }
  5646. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5647. if (!lua_interface)
  5648. return 0;
  5649. Spawn* player = lua_interface->GetSpawn(state);
  5650. lua_interface->ResetFunctionStack(state);
  5651. if (player && player->IsPlayer()) {
  5652. Client* client = player->GetClient();
  5653. if (client)
  5654. client->SendWaypoints();
  5655. }
  5656. return 0;
  5657. }
  5658. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5659. if (!lua_interface)
  5660. return 0;
  5661. Spawn* player = lua_interface->GetSpawn(state);
  5662. string name = lua_interface->GetStringValue(state, 2);
  5663. int32 type = lua_interface->GetInt32Value(state, 3);
  5664. lua_interface->ResetFunctionStack(state);
  5665. if (type == 0)
  5666. type = 2;
  5667. if (name.length() > 0) {
  5668. if (player && player->IsPlayer()) {
  5669. Client* client = player->GetClient();
  5670. if (client)
  5671. client->AddWaypoint(name, type);
  5672. }
  5673. }
  5674. return 0;
  5675. }
  5676. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5677. if (!lua_interface)
  5678. return 0;
  5679. Spawn* player = lua_interface->GetSpawn(state);
  5680. string name = lua_interface->GetStringValue(state, 2);
  5681. lua_interface->ResetFunctionStack(state);
  5682. if (name.length() > 0) {
  5683. if (player && player->IsPlayer()) {
  5684. Client* client = player->GetClient();
  5685. if (client)
  5686. client->RemoveWaypoint(name);
  5687. }
  5688. }
  5689. return 0;
  5690. }
  5691. int EQ2Emu_lua_AddWard(lua_State* state) {
  5692. if (!lua_interface)
  5693. return 0;
  5694. int32 damage = lua_interface->GetInt32Value(state);
  5695. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5696. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5697. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5698. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5699. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5700. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5701. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5702. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5703. lua_interface->ResetFunctionStack(state);
  5704. if(!spell || spell->resisted) {
  5705. return 0;
  5706. }
  5707. bool ward_was_added = false;
  5708. ZoneServer* zone = spell->caster->GetZone();
  5709. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5710. for (int32 i = 0; i < spell->targets.size(); i++) {
  5711. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5712. if (!target)
  5713. continue;
  5714. if (target->IsEntity()) {
  5715. // If the ward is already active remove it
  5716. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5717. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5718. // Create new ward info
  5719. WardInfo* ward = new WardInfo;
  5720. ward->Spell = spell;
  5721. ward->BaseDamage = damage;
  5722. ward->DamageLeft = damage;
  5723. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5724. ward->keepWard = keepWard;
  5725. ward->WardType = wardType;
  5726. if (damageAbsorptionPercent > 100)
  5727. damageAbsorptionPercent = 100;
  5728. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5729. if (damageAbsorptionMaxHealthPercent > 100)
  5730. damageAbsorptionMaxHealthPercent = 100;
  5731. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5732. ward->RedirectDamagePercent = redirectDamagePercent;
  5733. ward->LastRedirectDamage = 0;
  5734. ward->LastAbsorbedDamage = 0;
  5735. ward->HitCount = 0;
  5736. spell->num_triggers = maxHitCount;
  5737. spell->had_triggers = true;
  5738. spell->cancel_after_all_triggers = false;
  5739. ward->MaxHitCount = maxHitCount;
  5740. ward->RoundTriggered = false;
  5741. if (wardType == WARD_TYPE_MAGICAL)
  5742. ward->DamageType = damageTypes;
  5743. // Add the ward to the entity
  5744. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5745. ward_was_added = true;
  5746. }
  5747. }
  5748. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5749. if (ward_was_added && spell->caster->IsPlayer()) {
  5750. spell->had_dmg_remaining = true;
  5751. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5752. }
  5753. return 0;
  5754. }
  5755. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5756. if (!lua_interface)
  5757. return 0;
  5758. int32 amount = lua_interface->GetInt32Value(state);
  5759. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5760. lua_interface->ResetFunctionStack(state);
  5761. WardInfo* ward = 0;
  5762. if(!spell || spell->resisted) {
  5763. return 0;
  5764. }
  5765. ZoneServer* zone = spell->caster->GetZone();
  5766. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5767. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5768. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5769. ward = target->GetWard(spell->spell->GetSpellID());
  5770. if (target && ward) {
  5771. ward->DamageLeft += amount;
  5772. if (ward->DamageLeft > ward->BaseDamage)
  5773. ward->DamageLeft = ward->BaseDamage;
  5774. for (int32 i = 0; i < spell->targets.size(); i++) {
  5775. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5776. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5777. }
  5778. }
  5779. }
  5780. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5781. if (ward && spell->caster->IsPlayer())
  5782. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5783. return 0;
  5784. }
  5785. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5786. if (!lua_interface)
  5787. return 0;
  5788. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5789. lua_interface->ResetFunctionStack(state);
  5790. if (!spell) {
  5791. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5792. return 0;
  5793. }
  5794. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5795. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5796. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5797. if (ward) {
  5798. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5799. return 1;
  5800. }
  5801. }
  5802. return 0;
  5803. }
  5804. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5805. if (!lua_interface)
  5806. return 0;
  5807. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5808. if (!spell) {
  5809. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5810. lua_interface->ResetFunctionStack(state);
  5811. return 0;
  5812. }
  5813. string type = lua_interface->GetStringValue(state, 2);
  5814. lua_interface->ResetFunctionStack(state);
  5815. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5816. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5817. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5818. if (ward) {
  5819. if (boost::iequals(type, "damageleft"))
  5820. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5821. else if (boost::iequals(type, "basedamage"))
  5822. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5823. else if (boost::iequals(type, "keepward"))
  5824. lua_interface->SetBooleanValue(state, ward->keepWard);
  5825. else if (boost::iequals(type, "wardtype"))
  5826. lua_interface->SetInt32Value(state, ward->WardType);
  5827. else if (boost::iequals(type, "dmgabsorptionpct"))
  5828. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5829. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5830. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5831. else if (boost::iequals(type, "redirectdamagepercent"))
  5832. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5833. else if (boost::iequals(type, "lastredirectdamage"))
  5834. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5835. else if (boost::iequals(type, "lastabsorbeddamage"))
  5836. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5837. else if (boost::iequals(type, "hitcount"))
  5838. lua_interface->SetInt32Value(state, ward->HitCount);
  5839. else if (boost::iequals(type, "maxhitcount"))
  5840. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5841. else
  5842. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5843. return 1;
  5844. }
  5845. }
  5846. return 0;
  5847. }
  5848. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5849. if (!lua_interface)
  5850. return 0;
  5851. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5852. lua_interface->ResetFunctionStack(state);
  5853. if(!spell) {
  5854. return 0;
  5855. }
  5856. ZoneServer* zone = spell->caster->GetZone();
  5857. Spawn* target = 0;
  5858. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5859. for (int32 i = 0; i < spell->targets.size(); i++) {
  5860. target = zone->GetSpawnByID(spell->targets.at(i));
  5861. if (target && target->IsEntity()) {
  5862. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5863. }
  5864. }
  5865. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5866. return 0;
  5867. }
  5868. int EQ2Emu_lua_Interrupt(lua_State* state)
  5869. {
  5870. if (!lua_interface)
  5871. return 0;
  5872. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5873. Spawn* target = lua_interface->GetSpawn(state, 2);
  5874. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5875. lua_interface->ResetFunctionStack(state);
  5876. if (!caster)
  5877. {
  5878. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5879. return 0;
  5880. }
  5881. if (!target)
  5882. {
  5883. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. if (!spell) {
  5887. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. if (!target->IsEntity() && !spell)
  5891. {
  5892. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5893. return 0;
  5894. }
  5895. if (!target && spell) {
  5896. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5897. for (int8 i = 0; i < spell->targets.size(); i++) {
  5898. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5899. if (!target || !target->IsEntity())
  5900. continue;
  5901. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5902. }
  5903. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5904. }
  5905. else
  5906. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5907. return 0;
  5908. }
  5909. int EQ2Emu_lua_Stealth(lua_State* state) {
  5910. if (!lua_interface)
  5911. return 0;
  5912. int8 type = lua_interface->GetInt8Value(state);
  5913. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5914. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5915. lua_interface->ResetFunctionStack(state);
  5916. if (!spell) {
  5917. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5918. return 0;
  5919. }
  5920. ZoneServer* zone = spell->caster->GetZone();
  5921. if (spawn) {
  5922. if (spawn->IsEntity()) {
  5923. if (type == 1) {
  5924. ((Entity*)spawn)->AddStealthSpell(spell);
  5925. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5926. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5927. }
  5928. else if (type == 2) {
  5929. ((Entity*)spawn)->AddInvisSpell(spell);
  5930. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5931. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5932. }
  5933. return 0;
  5934. }
  5935. else {
  5936. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5937. return 0;
  5938. }
  5939. }
  5940. else {
  5941. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5942. for (int32 i = 0; i < spell->targets.size(); i++) {
  5943. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5944. if (!spawn || !spawn->IsEntity())
  5945. continue;
  5946. if (type == 1) {
  5947. ((Entity*)spawn)->AddStealthSpell(spell);
  5948. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5949. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5950. }
  5951. else if (type == 2) {
  5952. ((Entity*)spawn)->AddInvisSpell(spell);
  5953. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5954. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5955. }
  5956. else {
  5957. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5958. break;
  5959. }
  5960. }
  5961. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5962. }
  5963. return 0;
  5964. }
  5965. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5966. if (!lua_interface)
  5967. return 0;
  5968. Spawn* spawn = lua_interface->GetSpawn(state);
  5969. lua_interface->ResetFunctionStack(state);
  5970. if (!spawn) {
  5971. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5972. return 0;
  5973. }
  5974. if (spawn->IsEntity()) {
  5975. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5976. return 1;
  5977. }
  5978. else
  5979. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5980. return 0;
  5981. }
  5982. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5983. if (!lua_interface)
  5984. return 0;
  5985. Spawn* spawn = lua_interface->GetSpawn(state);
  5986. lua_interface->ResetFunctionStack(state);
  5987. if (!spawn) {
  5988. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5989. return 0;
  5990. }
  5991. if (spawn->IsEntity()) {
  5992. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5993. return 1;
  5994. }
  5995. else
  5996. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5997. return 0;
  5998. }
  5999. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6000. if (!lua_interface)
  6001. return 0;
  6002. Spawn* player = lua_interface->GetSpawn(state);
  6003. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6004. lua_interface->ResetFunctionStack(state);
  6005. if (!player->IsPlayer()) {
  6006. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6010. return 1;
  6011. }
  6012. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6013. if (!lua_interface)
  6014. return 0;
  6015. Spawn* spawn = lua_interface->GetSpawn(state);
  6016. int8 slot = lua_interface->GetInt8Value(state, 2);
  6017. lua_interface->ResetFunctionStack(state);
  6018. if (!spawn) {
  6019. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. if (!spawn->IsEntity()) {
  6023. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6027. if (!item) {
  6028. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6029. return 0;
  6030. }
  6031. lua_interface->SetItemValue(state, item);
  6032. return 1;
  6033. }
  6034. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6035. if (!lua_interface)
  6036. return 0;
  6037. Spawn* player = lua_interface->GetSpawn(state);
  6038. int32 id = lua_interface->GetInt32Value(state, 2);
  6039. lua_interface->ResetFunctionStack(state);
  6040. if (!player) {
  6041. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. if (!player->IsPlayer()) {
  6045. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6046. return 0;
  6047. }
  6048. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6049. if (!item) {
  6050. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6051. return 0;
  6052. }
  6053. lua_interface->SetItemValue(state, item);
  6054. return 1;
  6055. }
  6056. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6057. if (!lua_interface)
  6058. return 0;
  6059. Spawn* spawn = lua_interface->GetSpawn(state);
  6060. int8 slot = lua_interface->GetInt8Value(state, 2);
  6061. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6062. lua_interface->ResetFunctionStack(state);
  6063. if (!spawn) {
  6064. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. if (!spawn->IsEntity()) {
  6068. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6069. return 0;
  6070. }
  6071. Item* item = master_item_list.GetItem(item_id);
  6072. if (!item) {
  6073. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6074. return 0;
  6075. }
  6076. Item* copy = new Item(item);
  6077. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6078. if(result)
  6079. {
  6080. ((Entity*)spawn)->SetEquipment(copy, slot);
  6081. spawn->vis_changed = true;
  6082. if(spawn->IsPlayer())
  6083. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6084. }
  6085. else
  6086. {
  6087. safe_delete(copy);
  6088. }
  6089. lua_interface->SetBooleanValue(state, result);
  6090. return 1;
  6091. }
  6092. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6093. if (!lua_interface)
  6094. return 0;
  6095. Spawn* spawn = lua_interface->GetSpawn(state);
  6096. int8 slot = lua_interface->GetInt8Value(state, 2);
  6097. Item* item = lua_interface->GetItem(state, 3);
  6098. lua_interface->ResetFunctionStack(state);
  6099. if (!spawn) {
  6100. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. if (!spawn->IsEntity()) {
  6104. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6105. return 0;
  6106. }
  6107. if (!item) {
  6108. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6109. return 0;
  6110. }
  6111. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6112. if(result)
  6113. {
  6114. ((Entity*)spawn)->SetEquipment(item, slot);
  6115. spawn->vis_changed = true;
  6116. if(spawn->IsPlayer())
  6117. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6118. }
  6119. lua_interface->SetBooleanValue(state, result);
  6120. return 1;
  6121. }
  6122. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6123. if (!lua_interface)
  6124. return 0;
  6125. Spawn* spawn = lua_interface->GetSpawn(state);
  6126. int8 slot = lua_interface->GetInt8Value(state, 2);
  6127. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6128. lua_interface->ResetFunctionStack(state);
  6129. if (!spawn) {
  6130. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6131. return 0;
  6132. }
  6133. if (!spawn->IsEntity()) {
  6134. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. if(slot >= NUM_SLOTS) {
  6138. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6139. return 0;
  6140. }
  6141. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6142. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6143. if(item) {
  6144. item->save_needed = true;
  6145. if(no_delete_item) {
  6146. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6147. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6148. }
  6149. else{
  6150. Client* client = ((Player*)spawn)->GetClient();
  6151. client->UnequipItem(item->details.index);
  6152. }
  6153. }
  6154. }
  6155. else
  6156. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6157. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6158. spawn->vis_changed = true;
  6159. if(spawn->IsPlayer())
  6160. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6161. lua_interface->SetBooleanValue(state, true);
  6162. return 1;
  6163. }
  6164. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6165. if (!lua_interface)
  6166. return 0;
  6167. Spawn* spawn = lua_interface->GetSpawn(state);
  6168. int8 slot = lua_interface->GetInt8Value(state, 2);
  6169. int16 type = lua_interface->GetInt16Value(state, 3);
  6170. int8 r = lua_interface->GetInt8Value(state, 4);
  6171. int8 g = lua_interface->GetInt8Value(state, 5);
  6172. int8 b = lua_interface->GetInt8Value(state, 6);
  6173. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6174. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6175. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6176. lua_interface->ResetFunctionStack(state);
  6177. if (!spawn) {
  6178. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. if (!spawn->IsEntity()) {
  6182. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6183. return 0;
  6184. }
  6185. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6186. spawn->vis_changed = true;
  6187. lua_interface->SetBooleanValue(state, true);
  6188. return 1;
  6189. }
  6190. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6191. if (!lua_interface)
  6192. return 0;
  6193. Spawn* player = lua_interface->GetSpawn(state);
  6194. int32 id = lua_interface->GetInt32Value(state, 2);
  6195. int8 count = lua_interface->GetInt8Value(state, 3);
  6196. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6197. lua_interface->ResetFunctionStack(state);
  6198. if (!player) {
  6199. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6200. return 0;
  6201. }
  6202. if (!player->IsPlayer()) {
  6203. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. if (!count)
  6207. count = 1;
  6208. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6209. if (!item) {
  6210. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6211. return 0;
  6212. }
  6213. lua_interface->SetItemValue(state, item);
  6214. return 1;
  6215. }
  6216. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6217. if (!lua_interface)
  6218. return 0;
  6219. Spawn* spawn = lua_interface->GetSpawn(state);
  6220. int32 anim = lua_interface->GetInt32Value(state, 2);
  6221. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6222. int8 type = lua_interface->GetInt8Value(state, 4);
  6223. lua_interface->ResetFunctionStack(state);
  6224. if (!spawn) {
  6225. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (spawn2) {
  6229. if (spawn2->IsPlayer()) {
  6230. if (type != 1 && type != 2)
  6231. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6232. else
  6233. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6234. return 0;
  6235. }
  6236. else {
  6237. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. }
  6241. else
  6242. spawn->GetZone()->PlayAnimation(spawn, anim);
  6243. return 0;
  6244. }
  6245. int EQ2Emu_lua_IsPet(lua_State* state) {
  6246. if (!lua_interface)
  6247. return 0;
  6248. Spawn* spawn = lua_interface->GetSpawn(state);
  6249. lua_interface->ResetFunctionStack(state);
  6250. if (!spawn) {
  6251. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6252. return 0;
  6253. }
  6254. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6255. return 1;
  6256. }
  6257. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6258. if (!lua_interface)
  6259. return 0;
  6260. Spawn* spawn = lua_interface->GetSpawn(state);
  6261. lua_interface->ResetFunctionStack(state);
  6262. if (!spawn) {
  6263. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6264. return 0;
  6265. }
  6266. if (!spawn->IsNPC()) {
  6267. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. if (((NPC*)spawn)->GetOwner()) {
  6271. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6272. return 1;
  6273. }
  6274. return 0;
  6275. }
  6276. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6277. if (!lua_interface)
  6278. return 0;
  6279. Spawn* spawn = lua_interface->GetSpawn(state);
  6280. Spawn* target = lua_interface->GetSpawn(state, 2);
  6281. lua_interface->ResetFunctionStack(state);
  6282. if (!spawn) {
  6283. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6284. return 0;
  6285. }
  6286. if (!spawn) {
  6287. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6288. return 0;
  6289. }
  6290. spawn->SetTarget(target);
  6291. return 0;
  6292. }
  6293. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6294. if (!lua_interface)
  6295. return 0;
  6296. Spawn* spawn = lua_interface->GetSpawn(state);
  6297. bool val = lua_interface->GetBooleanValue(state, 2);
  6298. lua_interface->ResetFunctionStack(state);
  6299. if (!spawn) {
  6300. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6301. return 0;
  6302. }
  6303. if (!spawn->IsEntity()) {
  6304. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6305. return 0;
  6306. }
  6307. ((Entity*)spawn)->InCombat(val);
  6308. if (val) {
  6309. spawn->ClearRunningLocations();
  6310. spawn->CalculateRunningLocation(true);
  6311. }
  6312. return 0;
  6313. }
  6314. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6315. if (!lua_interface)
  6316. return 0;
  6317. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6318. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6319. lua_interface->ResetFunctionStack(state);
  6320. if (!spawn1) {
  6321. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6322. return 0;
  6323. }
  6324. if (!spawn2) {
  6325. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6326. return 0;
  6327. }
  6328. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6329. return 1;
  6330. }
  6331. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6332. if (!lua_interface)
  6333. return 0;
  6334. Spawn* spawn = lua_interface->GetSpawn(state);
  6335. lua_interface->ResetFunctionStack(state);
  6336. if (!spawn) {
  6337. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!spawn->IsNPC()) {
  6341. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. ((NPC*)spawn)->ClearRunback();
  6345. return 0;
  6346. }
  6347. int EQ2Emu_lua_Runback(lua_State* state) {
  6348. if (!lua_interface)
  6349. return 0;
  6350. Spawn* spawn = lua_interface->GetSpawn(state);
  6351. lua_interface->ResetFunctionStack(state);
  6352. if (!spawn) {
  6353. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6354. return 0;
  6355. }
  6356. if (!spawn->IsNPC()) {
  6357. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6358. return 0;
  6359. }
  6360. ((NPC*)spawn)->Runback();
  6361. return 0;
  6362. }
  6363. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6364. if (!lua_interface)
  6365. return 0;
  6366. Spawn* spawn = lua_interface->GetSpawn(state);
  6367. lua_interface->ResetFunctionStack(state);
  6368. if (!spawn) {
  6369. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6370. return 0;
  6371. }
  6372. if (!spawn->IsNPC()) {
  6373. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6377. return 1;
  6378. }
  6379. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6380. if (!lua_interface)
  6381. return 0;
  6382. Spawn* spawn = lua_interface->GetSpawn(state);
  6383. lua_interface->ResetFunctionStack(state);
  6384. if (!spawn) {
  6385. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. if (!spawn->IsEntity()) {
  6389. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6393. return 1;
  6394. }
  6395. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6396. if (!lua_interface)
  6397. return 0;
  6398. Spawn* spawn = lua_interface->GetSpawn(state);
  6399. lua_interface->ResetFunctionStack(state);
  6400. if (!spawn) {
  6401. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6402. return 0;
  6403. }
  6404. if (!spawn->IsEntity()) {
  6405. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6406. return 0;
  6407. }
  6408. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6409. return 1;
  6410. }
  6411. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6412. if (!lua_interface)
  6413. return 0;
  6414. Spawn* spawn = lua_interface->GetSpawn(state);
  6415. lua_interface->ResetFunctionStack(state);
  6416. if (!spawn) {
  6417. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. if (!spawn->IsEntity()) {
  6421. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6425. return 1;
  6426. }
  6427. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6428. if (!lua_interface)
  6429. return 0;
  6430. Spawn* spawn = lua_interface->GetSpawn(state);
  6431. lua_interface->ResetFunctionStack(state);
  6432. if (!spawn) {
  6433. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6434. return 0;
  6435. }
  6436. if (!spawn->IsEntity()) {
  6437. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6438. return 0;
  6439. }
  6440. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6441. return 1;
  6442. }
  6443. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6444. if (!lua_interface)
  6445. return 0;
  6446. Spawn* spawn = lua_interface->GetSpawn(state);
  6447. Spawn* target = lua_interface->GetSpawn(state, 2);
  6448. float distance = lua_interface->GetFloatValue(state, 3);
  6449. lua_interface->ResetFunctionStack(state);
  6450. if (!spawn) {
  6451. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6452. return 0;
  6453. }
  6454. if (!target) {
  6455. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6456. return 0;
  6457. }
  6458. if (!spawn->IsNPC()) {
  6459. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. if (!target->IsEntity()) {
  6463. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6464. return 0;
  6465. }
  6466. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6467. return 1;
  6468. }
  6469. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6470. if (!lua_interface)
  6471. return 0;
  6472. Spawn* spawn = lua_interface->GetSpawn(state);
  6473. Spawn* target = lua_interface->GetSpawn(state, 2);
  6474. float distance = lua_interface->GetFloatValue(state, 3);
  6475. lua_interface->ResetFunctionStack(state);
  6476. if (!spawn) {
  6477. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6478. return 0;
  6479. }
  6480. if (!target) {
  6481. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6482. return 0;
  6483. }
  6484. if (!spawn->IsNPC()) {
  6485. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6486. return 0;
  6487. }
  6488. if (!target->IsEntity()) {
  6489. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6490. return 0;
  6491. }
  6492. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6493. return 0;
  6494. }
  6495. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6496. if (!lua_interface)
  6497. return 0;
  6498. Spawn* spawn = lua_interface->GetSpawn(state);
  6499. lua_interface->ResetFunctionStack(state);
  6500. if (!spawn) {
  6501. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6502. return 0;
  6503. }
  6504. if (!spawn->IsNPC()) {
  6505. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6506. return 0;
  6507. }
  6508. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6509. return 1;
  6510. }
  6511. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6512. if (!lua_interface)
  6513. return 0;
  6514. Spawn* spawn = lua_interface->GetSpawn(state);
  6515. lua_interface->ResetFunctionStack(state);
  6516. if (!spawn) {
  6517. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6518. return 0;
  6519. }
  6520. if (!spawn->IsNPC()) {
  6521. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6522. return 0;
  6523. }
  6524. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6525. return 1;
  6526. }
  6527. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6528. if (!lua_interface)
  6529. return 0;
  6530. Spawn* spawn = lua_interface->GetSpawn(state);
  6531. lua_interface->ResetFunctionStack(state);
  6532. if (!spawn) {
  6533. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6534. return 0;
  6535. }
  6536. if (!spawn->IsNPC()) {
  6537. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6541. if (hated) {
  6542. lua_interface->SetSpawnValue(state, hated);
  6543. return 1;
  6544. }
  6545. return 0;
  6546. }
  6547. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6548. if (!lua_interface)
  6549. return 0;
  6550. Spawn* spawn = lua_interface->GetSpawn(state);
  6551. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6552. lua_interface->ResetFunctionStack(state);
  6553. if (!spawn) {
  6554. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. if (!spawn->IsNPC()) {
  6558. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6559. return 0;
  6560. }
  6561. if (!hated) {
  6562. ((NPC*)spawn)->Brain()->ClearHate();
  6563. return 0;
  6564. }
  6565. else
  6566. {
  6567. if (!hated->IsEntity()) {
  6568. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6569. return 0;
  6570. }
  6571. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6572. return 0;
  6573. }
  6574. return 0;
  6575. }
  6576. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6577. if (!lua_interface)
  6578. return 0;
  6579. Spawn* spawn = lua_interface->GetSpawn(state);
  6580. lua_interface->ResetFunctionStack(state);
  6581. if (!spawn) {
  6582. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6583. return 0;
  6584. }
  6585. if (!spawn->IsNPC()) {
  6586. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6587. return 0;
  6588. }
  6589. ((NPC*)spawn)->Brain()->ClearEncounter();
  6590. return 0;
  6591. }
  6592. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6593. if (!lua_interface)
  6594. return 0;
  6595. Spawn* spawn = lua_interface->GetSpawn(state);
  6596. lua_interface->ResetFunctionStack(state);
  6597. if (!spawn) {
  6598. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6599. return 0;
  6600. }
  6601. if (!spawn->IsNPC()) {
  6602. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6603. return 0;
  6604. }
  6605. // Temp list to store hate list
  6606. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6607. if (encounterList->size() == 0) {
  6608. safe_delete(encounterList);
  6609. return 0;
  6610. }
  6611. lua_createtable(state, encounterList->size(), 0);
  6612. int newTable = lua_gettop(state);
  6613. for (int32 i = 0; i < encounterList->size(); i++) {
  6614. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6615. if (temp)
  6616. lua_interface->SetSpawnValue(state, temp);
  6617. lua_rawseti(state, newTable, i + 1);
  6618. }
  6619. safe_delete(encounterList);
  6620. return 1;
  6621. }
  6622. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6623. if (!lua_interface)
  6624. return 0;
  6625. Spawn* spawn = lua_interface->GetSpawn(state);
  6626. lua_interface->ResetFunctionStack(state);
  6627. if (!spawn) {
  6628. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. if (!spawn->IsNPC()) {
  6632. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. // Temp list to store hate list
  6636. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6637. if (hateList->size() == 0) {
  6638. safe_delete(hateList);
  6639. return 0;
  6640. }
  6641. lua_createtable(state, hateList->size(), 0);
  6642. int newTable = lua_gettop(state);
  6643. for (int32 i = 0; i < hateList->size(); i++) {
  6644. lua_interface->SetSpawnValue(state, hateList->at(i));
  6645. lua_rawseti(state, newTable, i + 1);
  6646. }
  6647. safe_delete(hateList);
  6648. return 1;
  6649. }
  6650. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6651. if (!lua_interface)
  6652. return 0;
  6653. Spawn* spawn = lua_interface->GetSpawn(state);
  6654. lua_interface->ResetFunctionStack(state);
  6655. if (!spawn) {
  6656. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6657. return 0;
  6658. }
  6659. if (spawn->IsPlayer()) {
  6660. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6661. lua_interface->SetBooleanValue(state, true);
  6662. else
  6663. lua_interface->SetBooleanValue(state, false);
  6664. return 1;
  6665. }
  6666. else {
  6667. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6668. return 1;
  6669. }
  6670. }
  6671. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6672. if (!lua_interface)
  6673. return 0;
  6674. Quest* quest = lua_interface->GetQuest(state);
  6675. lua_interface->ResetFunctionStack(state);
  6676. if (!quest) {
  6677. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6678. return 0;
  6679. }
  6680. quest->SetCompletedFlag(true);
  6681. return 0;
  6682. }
  6683. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6684. if (!lua_interface)
  6685. return 0;
  6686. Spawn* spawn = lua_interface->GetSpawn(state);
  6687. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6688. int8 tier = lua_interface->GetInt8Value(state, 3);
  6689. lua_interface->ResetFunctionStack(state);
  6690. if (!spawn) {
  6691. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. if (!spawn->IsEntity()) {
  6695. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6696. return 0;
  6697. }
  6698. if (spellID == 0) {
  6699. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6700. return 0;
  6701. }
  6702. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6703. if (effect) {
  6704. if (tier > 0) {
  6705. // If a tier was passed chec to see if it is the same as the effect
  6706. if (tier == effect->tier)
  6707. lua_interface->SetBooleanValue(state, true);
  6708. else
  6709. lua_interface->SetBooleanValue(state, false);
  6710. return 1;
  6711. }
  6712. else {
  6713. // Have an effect but no tier was passed so return true
  6714. lua_interface->SetBooleanValue(state, true);
  6715. }
  6716. return 1;
  6717. }
  6718. // no effect so return false
  6719. lua_interface->SetBooleanValue(state, false);
  6720. return 1;
  6721. }
  6722. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6723. if (!lua_interface)
  6724. return 0;
  6725. Spawn* spawn = lua_interface->GetSpawn(state);
  6726. int32 id = lua_interface->GetInt32Value(state, 2);
  6727. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6728. lua_interface->ResetFunctionStack(state);
  6729. Spawn* spawn2 = 0;
  6730. vector<Spawn*> list;
  6731. if (!spawn) {
  6732. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6733. return 0;
  6734. }
  6735. //If zone not provided, use spawn's zone
  6736. if (!zone)
  6737. zone = spawn->GetZone();
  6738. list = zone->GetSpawnsByID(id);
  6739. if (list.size() == 0) {
  6740. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. vector<Spawn*>::iterator itr = list.begin();
  6744. for (int8 i = 0; i < list.size(); i++) {
  6745. spawn2 = itr[i];
  6746. if (spawn2)
  6747. spawn2->AddAllowAccessSpawn(spawn);
  6748. }
  6749. return 0;
  6750. }
  6751. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6752. if (!lua_interface)
  6753. return 0;
  6754. Spawn* spawn = lua_interface->GetSpawn(state);
  6755. int32 id = lua_interface->GetInt32Value(state, 2);
  6756. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6757. lua_interface->ResetFunctionStack(state);
  6758. Spawn* spawn2 = 0;
  6759. if (!spawn) {
  6760. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6761. return 0;
  6762. }
  6763. //If zone not provided, use spawn's zone
  6764. if (!zone)
  6765. zone = spawn->GetZone();
  6766. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6767. vector<Spawn*>::iterator itr = list.begin();
  6768. if (list.size() == 0) {
  6769. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6770. return 0;
  6771. }
  6772. for (int8 i = 0; i < list.size(); i++) {
  6773. spawn2 = itr[i];
  6774. if (spawn2)
  6775. spawn2->RemoveSpawnAccess(spawn);
  6776. }
  6777. return 0;
  6778. }
  6779. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6780. if (!lua_interface)
  6781. return 0;
  6782. Quest* quest = lua_interface->GetQuest(state);
  6783. lua_interface->ResetFunctionStack(state);
  6784. if (!quest) {
  6785. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6786. return 0;
  6787. }
  6788. quest->SetYellowName(true);
  6789. return 0;
  6790. }
  6791. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6792. if (!lua_interface)
  6793. return 0;
  6794. Spawn* spawn = lua_interface->GetSpawn(state);
  6795. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6796. lua_interface->ResetFunctionStack(state);
  6797. if (!spawn) {
  6798. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6799. return 0;
  6800. }
  6801. if (!spawn->IsPlayer()) {
  6802. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6803. return 0;
  6804. }
  6805. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6806. return 1;
  6807. }
  6808. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6809. if (!lua_interface)
  6810. return 0;
  6811. Spawn* spawn = lua_interface->GetSpawn(state);
  6812. lua_interface->ResetFunctionStack(state);
  6813. if (!spawn) {
  6814. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6815. return 0;
  6816. }
  6817. if (!spawn->IsPlayer()) {
  6818. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6819. return 0;
  6820. }
  6821. ZoneServer* zone = spawn->GetZone();
  6822. if (!zone) {
  6823. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6824. return 0;
  6825. }
  6826. Instance_Type iType = zone->GetInstanceType();
  6827. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6828. iType == GROUP_LOCKOUT_INSTANCE ||
  6829. iType == RAID_LOCKOUT_INSTANCE ||
  6830. iType == SOLO_PERSIST_INSTANCE ||
  6831. iType == GROUP_PERSIST_INSTANCE ||
  6832. iType == RAID_PERSIST_INSTANCE) {
  6833. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6834. if (data) {
  6835. // Check to see if the timer has already been set, if it has return out.
  6836. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6837. return 0;
  6838. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6839. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6840. if(spawn->IsPlayer()) {
  6841. Client* client = ((Player*)spawn)->GetClient();
  6842. if (client) {
  6843. string time_msg = "";
  6844. int32 time = data->success_lockout_time;
  6845. int16 hour;
  6846. int8 min;
  6847. int8 sec;
  6848. hour = time / 3600;
  6849. time = time % 3600;
  6850. min = time / 60;
  6851. time = time % 60;
  6852. sec = time;
  6853. if (hour > 0) {
  6854. char temp[10];
  6855. sprintf(temp, " %i", hour);
  6856. time_msg.append(temp);
  6857. time_msg.append(" hour");
  6858. time_msg.append((hour > 1) ? "s" : "");
  6859. }
  6860. if (min > 0) {
  6861. char temp[5];
  6862. sprintf(temp, " %i", min);
  6863. time_msg.append(temp);
  6864. time_msg.append(" minute");
  6865. time_msg.append((min > 1) ? "s" : "");
  6866. }
  6867. // Only add seconds if minutes and hours are 0
  6868. if (hour == 0 && min == 0 && sec > 0) {
  6869. char temp[5];
  6870. sprintf(temp, " %i", sec);
  6871. time_msg.append(temp);
  6872. time_msg.append(" second");
  6873. time_msg.append((sec > 1) ? "s" : "");
  6874. }
  6875. 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());
  6876. }
  6877. else {
  6878. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6879. }
  6880. }
  6881. }
  6882. else
  6883. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6884. }
  6885. else
  6886. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6887. return 0;
  6888. }
  6889. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6890. if (!lua_interface)
  6891. return 0;
  6892. Spawn* spawn = lua_interface->GetSpawn(state);
  6893. lua_interface->ResetFunctionStack(state);
  6894. if (!spawn) {
  6895. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6896. return 0;
  6897. }
  6898. if (!spawn->IsPlayer()) {
  6899. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6900. return 0;
  6901. }
  6902. ZoneServer* zone = spawn->GetZone();
  6903. if (!zone) {
  6904. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6905. return 0;
  6906. }
  6907. Instance_Type iType = zone->GetInstanceType();
  6908. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6909. iType == GROUP_LOCKOUT_INSTANCE ||
  6910. iType == RAID_LOCKOUT_INSTANCE ||
  6911. iType == SOLO_PERSIST_INSTANCE ||
  6912. iType == GROUP_PERSIST_INSTANCE ||
  6913. iType == RAID_PERSIST_INSTANCE) {
  6914. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6915. if (data) {
  6916. // Check to see if the timer has already been set, if it has return out.
  6917. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6918. return 0;
  6919. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6920. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6921. if(spawn->IsPlayer()) {
  6922. Client* client = ((Player*)spawn)->GetClient();
  6923. if (client) {
  6924. string time_msg = "";
  6925. int32 time = data->failure_lockout_time;
  6926. int16 hour;
  6927. int8 min;
  6928. int8 sec;
  6929. hour = time / 3600;
  6930. time = time % 3600;
  6931. min = time / 60;
  6932. time = time % 60;
  6933. sec = time;
  6934. if (hour > 0) {
  6935. char temp[10];
  6936. sprintf(temp, " %i", hour);
  6937. time_msg.append(temp);
  6938. time_msg.append(" hour");
  6939. time_msg.append((hour > 1) ? "s" : "");
  6940. }
  6941. if (min > 0) {
  6942. char temp[5];
  6943. sprintf(temp, " %i", min);
  6944. time_msg.append(temp);
  6945. time_msg.append(" minute");
  6946. time_msg.append((min > 1) ? "s" : "");
  6947. }
  6948. // Only add seconds if minutes and hours are 0
  6949. if (hour == 0 && min == 0 && sec > 0) {
  6950. char temp[5];
  6951. sprintf(temp, " %i", sec);
  6952. time_msg.append(temp);
  6953. time_msg.append(" second");
  6954. time_msg.append((sec > 1) ? "s" : "");
  6955. }
  6956. 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());
  6957. }
  6958. }
  6959. else {
  6960. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6961. }
  6962. }
  6963. else
  6964. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6965. }
  6966. else
  6967. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6968. return 0;
  6969. }
  6970. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6971. if (!lua_interface)
  6972. return 0;
  6973. Spawn* spawn = lua_interface->GetSpawn(state);
  6974. lua_interface->ResetFunctionStack(state);
  6975. if (!spawn) {
  6976. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6980. return 1;
  6981. }
  6982. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6983. if (!lua_interface)
  6984. return 0;
  6985. Spawn* player = lua_interface->GetSpawn(state);
  6986. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6987. if (!player) {
  6988. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6989. lua_interface->ResetFunctionStack(state);
  6990. return 0;
  6991. }
  6992. if (!player->IsPlayer()) {
  6993. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6994. lua_interface->ResetFunctionStack(state);
  6995. return 0;
  6996. }
  6997. if (!ground) {
  6998. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6999. lua_interface->ResetFunctionStack(state);
  7000. return 0;
  7001. }
  7002. if (!ground->IsGroundSpawn()) {
  7003. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7004. lua_interface->ResetFunctionStack(state);
  7005. return 0;
  7006. }
  7007. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7008. if (!groundspawn_entries) {
  7009. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7010. lua_interface->ResetFunctionStack(state);
  7011. return 0;
  7012. }
  7013. Skill* skill = 0;
  7014. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7015. if (collection_skill == "Collecting")
  7016. skill = ((Player*)player)->GetSkillByName("Gathering");
  7017. else
  7018. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7019. if (!skill) {
  7020. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7021. lua_interface->ResetFunctionStack(state);
  7022. return 0;
  7023. }
  7024. vector<GroundSpawnEntry*>::iterator itr;
  7025. GroundSpawnEntry* entry = 0;
  7026. bool can_harvest = false;
  7027. sint32 min_skill = -1;
  7028. int16 totalSkill = skill->current_val;
  7029. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7030. if(skillID != 0xFFFFFFFF)
  7031. {
  7032. ((Entity*)player)->MStats.lock();
  7033. totalSkill += ((Entity*)player)->stats[skillID];
  7034. ((Entity*)player)->MStats.unlock();
  7035. }
  7036. // first, iterate through groundspawn_entries, discard tables player cannot use
  7037. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7038. {
  7039. entry = *itr;
  7040. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7041. min_skill = entry->min_skill_level;
  7042. // if player lacks skill, skip table
  7043. if (entry->min_skill_level > totalSkill)
  7044. continue;
  7045. // if bonus, but player lacks level, skip table
  7046. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7047. continue;
  7048. can_harvest = true;
  7049. break;
  7050. }
  7051. lua_interface->SetBooleanValue(state, can_harvest);
  7052. // If false, send the message to the client
  7053. if (!can_harvest) {
  7054. Client* client = ((Player*)player)->GetClient();
  7055. if (client) {
  7056. string msg = "You do not have enough skill to ";
  7057. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7058. msg.append("gather");
  7059. else if (collection_skill == "Mining")
  7060. msg.append("mine");
  7061. else if (collection_skill == "Trapping")
  7062. msg.append("trap");
  7063. else if (collection_skill == "Foresting")
  7064. msg.append("forest");
  7065. else if (collection_skill == "Fishing")
  7066. msg.append("catch");
  7067. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7068. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7069. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7070. }
  7071. }
  7072. lua_interface->ResetFunctionStack(state);
  7073. return 1;
  7074. }
  7075. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7076. if (!lua_interface)
  7077. return 0;
  7078. Spawn* player = lua_interface->GetSpawn(state);
  7079. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7080. lua_interface->ResetFunctionStack(state);
  7081. if (!player) {
  7082. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7083. return 0;
  7084. }
  7085. if (!player->IsPlayer()) {
  7086. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7087. return 0;
  7088. }
  7089. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7090. lua_interface->SetBooleanValue(state, ret);
  7091. return 1;
  7092. }
  7093. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7094. // Check to see if we have a valid lua_interface
  7095. if (!lua_interface)
  7096. return 0;
  7097. // Get the spawn that is getting the pet
  7098. Spawn* spawn = lua_interface->GetSpawn(state);
  7099. Spawn* target = lua_interface->GetSpawn(state, 2);
  7100. // Get the DB ID of the pet
  7101. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7102. float x = lua_interface->GetFloatValue(state, 4);
  7103. float y = lua_interface->GetFloatValue(state, 5);
  7104. float z = lua_interface->GetFloatValue(state, 6);
  7105. // Get the spell that this command was called from
  7106. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7107. lua_interface->ResetFunctionStack(state);
  7108. // Check to make sure the spawn pointer is valid
  7109. if (!spawn) {
  7110. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7111. return 0;
  7112. }
  7113. // Check to make sure the spawn is an entity
  7114. if (!spawn->IsEntity()) {
  7115. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7116. return 0;
  7117. }
  7118. if (!target) {
  7119. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7120. return 0;
  7121. }
  7122. if (!target->IsEntity()) {
  7123. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7124. return 0;
  7125. }
  7126. // Check to see if the DB ID for the pet is set
  7127. if (pet_id == 0) {
  7128. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7129. return 0;
  7130. }
  7131. // Check to see if the pointer to the spell is valid
  7132. if (!luaspell) {
  7133. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. if(luaspell->resisted) {
  7137. return 0;
  7138. }
  7139. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7140. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7141. if (!pet) {
  7142. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7143. return 0;
  7144. }
  7145. // Check to make sure the pet is an npc
  7146. if (!pet->IsNPC()) {
  7147. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7148. return 0;
  7149. }
  7150. if (x == 0)
  7151. x = spawn->GetX();
  7152. if (y == 0)
  7153. y = spawn->GetY();
  7154. if (z == 0)
  7155. z = spawn->GetZ();
  7156. // Spawn the pet at the same location as the owner
  7157. pet->SetX(x);
  7158. pet->SetY(y);
  7159. pet->SetZ(z);
  7160. pet->SetLocation(spawn->GetLocation());
  7161. pet->SetHeading(spawn->GetHeading());
  7162. spawn->GetZone()->AddSpawn(pet);
  7163. const char* spawn_script = world.GetSpawnScript(pet_id);
  7164. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7165. spawn->SetSpawnScript(string(spawn_script));
  7166. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7167. }
  7168. std::string petName = std::string("");
  7169. if(spawn->IsEntity()) {
  7170. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7171. }
  7172. if(petName.size() < 1) {
  7173. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7174. petName = spawn->GetZone()->pet_names.at(rand_index);
  7175. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7176. }
  7177. // Set the pets name
  7178. pet->SetName(petName.c_str());
  7179. // Set the level of the pet to the owners level
  7180. pet->SetLevel(spawn->GetLevel());
  7181. // Set the faction of the pet to the same faction as the owner
  7182. pet->SetFactionID(spawn->GetFactionID());
  7183. // Set the spawn as a pet
  7184. pet->SetPet(true);
  7185. // Give a pointer of the owner to the pet
  7186. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7187. // Set the pet type
  7188. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7189. // Set the spell id used to create this pet
  7190. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7191. // Set the spell tier used to create this pet
  7192. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7193. // Set the pets spawn type to 6
  7194. pet->SetSpawnType(6);
  7195. // Set the pets brain
  7196. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7197. // Check to see if the pet has a subtitle
  7198. if (strlen(pet->GetSubTitle()) > 0) {
  7199. // Add the players name to the front of the sub title
  7200. string pet_subtitle;
  7201. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7202. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7203. // Set the pets subtitle to the new one
  7204. pet->SetSubTitle(pet_subtitle.c_str());
  7205. }
  7206. // Set the pet as the return value for this function
  7207. lua_interface->SetSpawnValue(state, pet);
  7208. return 1;
  7209. }
  7210. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7211. if (!lua_interface)
  7212. return 0;
  7213. Spawn* spawn = lua_interface->GetSpawn(state);
  7214. Spawn* player = lua_interface->GetSpawn(state, 2);
  7215. float max_distance = lua_interface->GetFloatValue(state, 3);
  7216. string type = lua_interface->GetStringValue(state, 4);
  7217. lua_interface->ResetFunctionStack(state);
  7218. if (!spawn || (spawn && spawn->IsPlayer())) {
  7219. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7220. return 0;
  7221. }
  7222. if (!player || !player->IsPlayer()) {
  7223. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7224. return 0;
  7225. }
  7226. Client* client = ((Player*)player)->GetClient();
  7227. if (!client) {
  7228. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7229. return 0;
  7230. }
  7231. //Set max_distance to default if not set or not proper value
  7232. if (max_distance <= 0)
  7233. max_distance = 500;
  7234. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7235. if (packet) {
  7236. float unknown2_3 = 0;
  7237. int8 placement_mode = 0;
  7238. if (type == "wall") {
  7239. placement_mode = 2;
  7240. unknown2_3 = 150;
  7241. }
  7242. else if (type == "ceiling")
  7243. placement_mode = 1;
  7244. packet->setDataByName("placement_mode", placement_mode);
  7245. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7246. packet->setDataByName("model_type", spawn->GetModelType());
  7247. packet->setDataByName("unknown", 1); //size
  7248. packet->setDataByName("unknown2", 1); //size 2
  7249. packet->setDataByName("unknown2", .5, 1); //size 3
  7250. packet->setDataByName("unknown2", 3, 2);
  7251. packet->setDataByName("unknown2", unknown2_3, 3);
  7252. packet->setDataByName("max_distance", max_distance);
  7253. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7254. client->QueuePacket(packet->serialize());
  7255. safe_delete(packet);
  7256. }
  7257. return 0;
  7258. }
  7259. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7260. if (!lua_interface)
  7261. return 0;
  7262. Item* item = lua_interface->GetItem(state);
  7263. lua_interface->ResetFunctionStack(state);
  7264. if (!item) {
  7265. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7266. return 0;
  7267. }
  7268. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7269. return 1;
  7270. }
  7271. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7272. if (!lua_interface)
  7273. return 0;
  7274. Item* item = lua_interface->GetItem(state);
  7275. lua_interface->ResetFunctionStack(state);
  7276. if (!item) {
  7277. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7278. return 0;
  7279. }
  7280. lua_interface->SetInt32Value(state, item->effect_type);
  7281. return 1;
  7282. }
  7283. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7284. if (!lua_interface)
  7285. return 0;
  7286. Spawn* spawn = lua_interface->GetSpawn(state);
  7287. lua_interface->ResetFunctionStack(state);
  7288. if (!spawn) {
  7289. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7290. return 0;
  7291. }
  7292. if (spawn->GetZone())
  7293. spawn->GetZone()->AddTransportSpawn(spawn);
  7294. return 0;
  7295. }
  7296. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7297. if (!lua_interface)
  7298. return 0;
  7299. Spawn* spawn = lua_interface->GetSpawn(state);
  7300. lua_interface->ResetFunctionStack(state);
  7301. if (!spawn) {
  7302. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7306. return 1;
  7307. }
  7308. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7309. if (!lua_interface)
  7310. return 0;
  7311. Skill* skill = lua_interface->GetSkill(state);
  7312. lua_interface->ResetFunctionStack(state);
  7313. if (!skill) {
  7314. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. lua_interface->SetInt32Value(state, skill->current_val);
  7318. return 1;
  7319. }
  7320. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7321. if (!lua_interface)
  7322. return 0;
  7323. Skill* skill = lua_interface->GetSkill(state);
  7324. lua_interface->ResetFunctionStack(state);
  7325. if (!skill) {
  7326. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7327. return 0;
  7328. }
  7329. lua_interface->SetInt32Value(state, skill->max_val);
  7330. return 1;
  7331. }
  7332. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7333. if (!lua_interface)
  7334. return 0;
  7335. Skill* skill = lua_interface->GetSkill(state);
  7336. lua_interface->ResetFunctionStack(state);
  7337. if (!skill) {
  7338. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7339. return 0;
  7340. }
  7341. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7342. return 1;
  7343. }
  7344. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7345. if (!lua_interface)
  7346. return 0;
  7347. Skill* skill = lua_interface->GetSkill(state);
  7348. int16 value = lua_interface->GetInt16Value(state, 2);
  7349. lua_interface->ResetFunctionStack(state);
  7350. if (!skill) {
  7351. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7352. return 0;
  7353. }
  7354. skill->max_val = value;
  7355. if (skill->max_val < skill->current_val)
  7356. skill->current_val = skill->max_val;
  7357. return 0;
  7358. }
  7359. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7360. if (!lua_interface)
  7361. return 0;
  7362. Skill* skill = lua_interface->GetSkill(state);
  7363. int16 value = lua_interface->GetInt16Value(state, 2);
  7364. lua_interface->ResetFunctionStack(state);
  7365. if (!skill) {
  7366. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7367. return 0;
  7368. }
  7369. if (value > skill->max_val)
  7370. skill->current_val = skill->max_val;
  7371. else
  7372. skill->current_val = value;
  7373. return 0;
  7374. }
  7375. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7376. if (!lua_interface)
  7377. return 0;
  7378. Spawn* player = lua_interface->GetSpawn(state);
  7379. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7380. lua_interface->ResetFunctionStack(state);
  7381. if (skill_id > 0 && player && player->IsPlayer()) {
  7382. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7383. return 1;
  7384. }
  7385. return 0;
  7386. }
  7387. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7388. if (!lua_interface)
  7389. return 0;
  7390. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7391. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7392. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7393. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7394. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7395. lua_interface->ResetFunctionStack(state);
  7396. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7397. if (player_spawn && player_spawn->IsPlayer()) {
  7398. Player* player = (Player*)player_spawn;
  7399. bool added = false;
  7400. if (!player->skill_list.HasSkill(skill_id)) {
  7401. player->AddSkill(skill_id, current_val, max_val, true);
  7402. added = true;
  7403. }
  7404. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  7405. Client* client = player->GetClient();
  7406. if (client) {
  7407. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7408. if (packet)
  7409. client->QueuePacket(packet);
  7410. }
  7411. }
  7412. if (added) {
  7413. lua_interface->SetBooleanValue(state, true);
  7414. return 1;
  7415. }
  7416. }
  7417. else {
  7418. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7419. }
  7420. }
  7421. else {
  7422. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7423. }
  7424. lua_interface->SetBooleanValue(state, false);
  7425. return 1;
  7426. }
  7427. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7428. if (!lua_interface)
  7429. return 0;
  7430. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7431. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7432. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7433. lua_interface->ResetFunctionStack(state);
  7434. if (skill_id > 0) {
  7435. if (player_spawn && player_spawn->IsPlayer()) {
  7436. Player* player = (Player*)player_spawn;
  7437. if (player->skill_list.HasSkill(skill_id)) {
  7438. player->RemovePlayerSkill(skill_id);
  7439. if (!more_to_remove) {
  7440. Client* client = player->GetClient();
  7441. if (client) {
  7442. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7443. if (packet)
  7444. client->QueuePacket(packet);
  7445. }
  7446. }
  7447. }
  7448. }
  7449. else {
  7450. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7451. }
  7452. }
  7453. else {
  7454. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7455. }
  7456. return 0;
  7457. }
  7458. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7459. if (!lua_interface)
  7460. return 0;
  7461. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7462. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7463. int16 amount = lua_interface->GetInt8Value(state, 3);
  7464. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7465. lua_interface->ResetFunctionStack(state);
  7466. if (amount > 0 && skill_type < 100) {
  7467. if (player_spawn && player_spawn->IsPlayer()) {
  7468. Player* player = (Player*)player_spawn;
  7469. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7470. if (!more_to_increase) {
  7471. Client* client = player->GetClient();
  7472. if (client) {
  7473. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7474. if (packet)
  7475. client->QueuePacket(packet);
  7476. }
  7477. }
  7478. }
  7479. else {
  7480. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7481. }
  7482. }
  7483. else {
  7484. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7485. }
  7486. return 0;
  7487. }
  7488. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7489. if (!lua_interface)
  7490. return 0;
  7491. Spawn* spawn = lua_interface->GetSpawn(state);
  7492. string name = lua_interface->GetStringValue(state, 2);
  7493. lua_interface->ResetFunctionStack(state);
  7494. if (!spawn) {
  7495. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7496. return 0;
  7497. }
  7498. if (!spawn->IsEntity()) {
  7499. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7503. if (skill) {
  7504. lua_interface->SetSkillValue(state, skill);
  7505. return 1;
  7506. }
  7507. return 0;
  7508. }
  7509. int EQ2Emu_lua_AddProc(lua_State* state) {
  7510. if (!lua_interface)
  7511. return 0;
  7512. Spawn* spawn = lua_interface->GetSpawn(state);
  7513. int8 type = lua_interface->GetInt8Value(state, 2);
  7514. float chance = lua_interface->GetFloatValue(state, 3);
  7515. Item* item = lua_interface->GetItem(state, 4);
  7516. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7517. LuaSpell* spell = 0;
  7518. if (!spawn && (!spell || !use_all_spelltargets)) {
  7519. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7523. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7524. return 0;
  7525. }
  7526. if (!item)
  7527. spell = lua_interface->GetCurrentSpell(state);
  7528. if (!item && !spell) {
  7529. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7530. return 0;
  7531. }
  7532. if(spell && spell->resisted) {
  7533. return 0;
  7534. }
  7535. if (spell && use_all_spelltargets) {
  7536. Spawn* target;
  7537. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7538. for (int8 i = 0; i < spell->targets.size(); i++) {
  7539. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7540. if (!target || !target->IsEntity())
  7541. continue;
  7542. ((Entity*)target)->AddProc(type, chance, item, spell);
  7543. }
  7544. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7545. }
  7546. else
  7547. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7548. return 0;
  7549. }
  7550. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7551. if (!lua_interface)
  7552. return 0;
  7553. Spawn* spawn = lua_interface->GetSpawn(state);
  7554. Item* item = lua_interface->GetItem(state, 2);
  7555. LuaSpell* spell = 0;
  7556. if (!spawn) {
  7557. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7558. lua_interface->ResetFunctionStack(state);
  7559. return 0;
  7560. }
  7561. if (!spawn->IsEntity()) {
  7562. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7563. lua_interface->ResetFunctionStack(state);
  7564. return 0;
  7565. }
  7566. if (!item)
  7567. spell = lua_interface->GetCurrentSpell(state);
  7568. lua_interface->ResetFunctionStack(state);
  7569. if (!item && !spell) {
  7570. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7571. return 0;
  7572. }
  7573. if (spell) {
  7574. Spawn* target;
  7575. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7576. for (int8 i = 0; i < spell->targets.size(); i++) {
  7577. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7578. if (!target || !target->IsEntity())
  7579. continue;
  7580. ((Entity*)target)->RemoveProc(item, spell);
  7581. }
  7582. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7583. spell->caster->RemoveProc(item, spell);
  7584. }
  7585. else
  7586. ((Entity*)spawn)->RemoveProc(item, spell);
  7587. return 0;
  7588. }
  7589. int EQ2Emu_lua_Knockback(lua_State* state) {
  7590. if (!lua_interface)
  7591. return 0;
  7592. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7593. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7594. int32 duration = lua_interface->GetInt32Value(state, 3);
  7595. float vertical = lua_interface->GetFloatValue(state, 4);
  7596. float horizontal = lua_interface->GetFloatValue(state, 5);
  7597. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7598. lua_interface->ResetFunctionStack(state);
  7599. if (!target_spawn) {
  7600. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7601. return 0;
  7602. }
  7603. if (!spawn) {
  7604. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7605. return 0;
  7606. }
  7607. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7608. Client* client = ((Player*)spawn)->GetClient();
  7609. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7610. if (packet) {
  7611. packet->setDataByName("target_x", target_spawn->GetX());
  7612. packet->setDataByName("target_y", target_spawn->GetY());
  7613. packet->setDataByName("target_z", target_spawn->GetZ());
  7614. packet->setDataByName("vertical_movement", vertical);
  7615. packet->setDataByName("horizontal_movement", horizontal);
  7616. if (use_heading)
  7617. packet->setDataByName("use_player_heading", 1);
  7618. client->QueuePacket(packet->serialize());
  7619. }
  7620. safe_delete(packet);
  7621. }
  7622. return 0;
  7623. }
  7624. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7625. if (!lua_interface)
  7626. return 0;
  7627. Spawn* spawn = lua_interface->GetSpawn(state);
  7628. lua_interface->ResetFunctionStack(state);
  7629. if (!spawn) {
  7630. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7631. return 0;
  7632. }
  7633. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7634. return 1;
  7635. }
  7636. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7637. if (!lua_interface)
  7638. return 0;
  7639. Spawn* caster = lua_interface->GetSpawn(state);
  7640. Spawn* target = lua_interface->GetSpawn(state, 2);
  7641. string name = lua_interface->GetStringValue(state, 3);
  7642. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7643. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7644. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7645. string success_msg = lua_interface->GetStringValue(state, 7);
  7646. string effect_msg = lua_interface->GetStringValue(state, 8);
  7647. lua_interface->ResetFunctionStack(state);
  7648. if (!caster) {
  7649. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7650. return 0;
  7651. }
  7652. if (!caster->IsEntity()) {
  7653. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if (!target) {
  7657. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7658. return 0;
  7659. }
  7660. if (!target->IsEntity()) {
  7661. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7662. return 0;
  7663. }
  7664. if (name.length() == 0) {
  7665. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7666. return 0;
  7667. }
  7668. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7669. return 0;
  7670. }
  7671. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7672. if (!lua_interface)
  7673. return 0;
  7674. string name = lua_interface->GetStringValue(state);
  7675. lua_interface->ResetFunctionStack(state);
  7676. if (name.length() == 0) {
  7677. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7678. return 0;
  7679. }
  7680. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7681. if (!skill) {
  7682. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7683. return 0;
  7684. }
  7685. lua_interface->SetInt32Value(state, skill->skill_id);
  7686. return 1;
  7687. }
  7688. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Spawn* spawn = lua_interface->GetSpawn(state);
  7692. lua_interface->ResetFunctionStack(state);
  7693. if (!spawn) {
  7694. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7695. return 0;
  7696. }
  7697. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7698. return 1;
  7699. }
  7700. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7701. if (!lua_interface)
  7702. return 0;
  7703. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7704. lua_interface->ResetFunctionStack(state);
  7705. if (!luaspell) {
  7706. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7707. return 0;
  7708. }
  7709. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7710. return 1;
  7711. }
  7712. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7713. if (!lua_interface)
  7714. return 0;
  7715. Spawn* spawn = lua_interface->GetSpawn(state);
  7716. Spawn* target = lua_interface->GetSpawn(state, 2);
  7717. lua_interface->ResetFunctionStack(state);
  7718. if (!spawn) {
  7719. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7720. return 0;
  7721. }
  7722. if (!spawn->IsEntity()) {
  7723. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7724. return 0;
  7725. }
  7726. if (!target) {
  7727. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7728. return 0;
  7729. }
  7730. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7731. return 1;
  7732. }
  7733. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7734. if (!lua_interface)
  7735. return 0;
  7736. Spawn* spawn = lua_interface->GetSpawn(state);
  7737. Spawn* target = lua_interface->GetSpawn(state, 2);
  7738. lua_interface->ResetFunctionStack(state);
  7739. if (!spawn) {
  7740. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7741. return 0;
  7742. }
  7743. if (!spawn->IsEntity()) {
  7744. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7745. return 0;
  7746. }
  7747. if (!target) {
  7748. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7749. return 0;
  7750. }
  7751. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7752. return 1;
  7753. }
  7754. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7755. if (!lua_interface)
  7756. return 0;
  7757. Item* item = lua_interface->GetItem(state);
  7758. lua_interface->ResetFunctionStack(state);
  7759. if (!item) {
  7760. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7761. return 0;
  7762. }
  7763. lua_interface->SetInt32Value(state, item->details.count);
  7764. return 1;
  7765. }
  7766. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7767. if (!lua_interface)
  7768. return 0;
  7769. Item* item = lua_interface->GetItem(state);
  7770. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7771. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7772. lua_interface->ResetFunctionStack(state);
  7773. if (!item) {
  7774. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7775. return 0;
  7776. }
  7777. if (!owner) {
  7778. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7779. return 0;
  7780. }
  7781. if (!owner->IsPlayer()) {
  7782. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7783. return 0;
  7784. }
  7785. if (item->stack_count < new_count) {
  7786. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7787. return 0;
  7788. }
  7789. if (new_count > 0) {
  7790. item->details.count = new_count;
  7791. item->save_needed = true;
  7792. }
  7793. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7794. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7795. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7796. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7797. else
  7798. {
  7799. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7800. return 0;
  7801. }
  7802. Client* client = ((Player*)owner)->GetClient();
  7803. if (!client)
  7804. return 0;
  7805. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7806. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7807. if (app)
  7808. client->QueuePacket(app);
  7809. return 0;
  7810. }
  7811. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7812. if (!lua_interface)
  7813. return 0;
  7814. int32 time = lua_interface->GetInt32Value(state);
  7815. string function = lua_interface->GetStringValue(state, 2);
  7816. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7817. Spawn* target = lua_interface->GetSpawn(state, 4);
  7818. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7819. lua_interface->ResetFunctionStack(state);
  7820. if (time == 0) {
  7821. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7822. return 0;
  7823. }
  7824. if (function.length() == 0) {
  7825. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7826. return 0;
  7827. }
  7828. if (!spell) {
  7829. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. SpellScriptTimer* timer = new SpellScriptTimer;
  7833. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7834. #ifdef WIN32
  7835. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7836. #else
  7837. bzero(timer, sizeof(SpellScriptTimer));
  7838. #endif*/
  7839. timer->caster = 0;
  7840. timer->deleteWhenDone = false;
  7841. timer->target = 0;
  7842. timer->time = Timer::GetCurrentTime2() + time;
  7843. timer->customFunction = function;
  7844. timer->spell = spell;
  7845. if (caster)
  7846. timer->caster = caster->GetID();
  7847. if (target)
  7848. timer->target = target->GetID();
  7849. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7850. return 0;
  7851. }
  7852. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7853. if (!lua_interface)
  7854. return 0;
  7855. float hp_perc = lua_interface->GetFloatValue(state);
  7856. float power_perc = lua_interface->GetFloatValue(state, 2);
  7857. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7858. Spawn* target = lua_interface->GetSpawn(state, 4);
  7859. string heal_name = lua_interface->GetStringValue(state, 5);
  7860. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7861. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7862. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7863. lua_interface->ResetFunctionStack(state);
  7864. if (!spell) {
  7865. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7866. return 0;
  7867. }
  7868. Entity* caster = spell->caster;
  7869. if (!caster) {
  7870. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7871. return 0;
  7872. }
  7873. Client* client = 0;
  7874. PendingResurrection* rez = 0;
  7875. ZoneServer* zone = spell->caster->GetZone();
  7876. if (!target) {
  7877. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7878. if (spell->targets.size() > 0) {
  7879. vector<int32> spell_targets = spell->targets;
  7880. for (int8 i = 0; i < spell_targets.size(); i++) {
  7881. target = zone->GetSpawnByID(spell_targets.at(i));
  7882. if (!target)
  7883. continue;
  7884. if (!target->IsPlayer())
  7885. continue;
  7886. client = ((Player*)target)->GetClient();
  7887. if (!client)
  7888. continue;
  7889. rez = client->GetCurrentRez();
  7890. if (rez->active)
  7891. continue;
  7892. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7893. rez->active = true;
  7894. rez->caster = caster;
  7895. rez->expire_timer = new Timer;
  7896. int32 duration = spell->spell->GetSpellDuration();
  7897. rez->expire_timer->Start(duration * 100);
  7898. rez->hp_perc = hp_perc;
  7899. rez->mp_perc = power_perc;
  7900. rez->range = spell->spell->GetSpellData()->range;
  7901. rez->spell_name = spell->spell->GetName();
  7902. if (heal_name.length() > 0)
  7903. rez->heal_name = heal_name;
  7904. else
  7905. rez->heal_name = rez->spell_name;
  7906. rez->no_calcs = no_calcs;
  7907. rez->crit_mod = crit_mod;
  7908. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7909. if (send_window)
  7910. client->SendResurrectionWindow();
  7911. else {
  7912. target->GetZone()->ResurrectSpawn(target, client);
  7913. rez->should_delete = true;
  7914. }
  7915. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7916. }
  7917. }
  7918. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7919. }
  7920. else {
  7921. if(!target->IsPlayer())
  7922. return 0;
  7923. client = ((Player*)target)->GetClient();
  7924. if (!client)
  7925. return 0;
  7926. rez = client->GetCurrentRez();
  7927. if (rez->active)
  7928. return 0;
  7929. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7930. rez->active = true;
  7931. rez->caster = caster;
  7932. rez->expire_timer = new Timer;
  7933. int32 duration = spell->spell->GetSpellDuration();
  7934. rez->expire_timer->Start(duration * 100);
  7935. rez->hp_perc = hp_perc;
  7936. rez->mp_perc = power_perc;
  7937. rez->range = spell->spell->GetSpellData()->range;
  7938. rez->spell_name = spell->spell->GetName();
  7939. if (heal_name.length() > 0)
  7940. rez->heal_name = heal_name;
  7941. else
  7942. rez->heal_name = rez->spell_name;
  7943. rez->no_calcs = no_calcs;
  7944. rez->crit_mod = crit_mod;
  7945. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7946. if (send_window)
  7947. client->SendResurrectionWindow();
  7948. else {
  7949. target->GetZone()->ResurrectSpawn(target, client);
  7950. rez->should_delete = true;
  7951. }
  7952. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7953. }
  7954. return 0;
  7955. }
  7956. int EQ2Emu_lua_SetVision(lua_State* state) {
  7957. if (!lua_interface)
  7958. return 0;
  7959. Spawn* spawn = lua_interface->GetSpawn(state);
  7960. int32 vision = lua_interface->GetInt32Value(state, 2);
  7961. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7962. lua_interface->ResetFunctionStack(state);
  7963. if (!spawn) {
  7964. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7965. return 0;
  7966. }
  7967. if (!spawn->IsEntity()) {
  7968. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7969. return 0;
  7970. }
  7971. if (spell && spell->targets.size() > 0) {
  7972. ZoneServer* zone = spell->caster->GetZone();
  7973. for (int8 i = 0; i < spell->targets.size(); i++) {
  7974. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7975. if (target && target->IsEntity()) {
  7976. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7977. if (target->IsPlayer())
  7978. ((Player*)target)->SetCharSheetChanged(true);
  7979. }
  7980. }
  7981. }
  7982. else {
  7983. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7984. if (spawn->IsPlayer())
  7985. ((Player*)spawn)->SetCharSheetChanged(true);
  7986. }
  7987. return 0;
  7988. }
  7989. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7990. if (!lua_interface)
  7991. return 0;
  7992. Spawn* spawn = lua_interface->GetSpawn(state);
  7993. float intensity = lua_interface->GetFloatValue(state, 2);
  7994. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7995. lua_interface->ResetFunctionStack(state);
  7996. if (!spawn) {
  7997. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7998. return 0;
  7999. }
  8000. if (!spawn->IsEntity()) {
  8001. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. if (spell && spell->targets.size() > 0) {
  8005. ZoneServer* zone = spell->caster->GetZone();
  8006. for (int8 i = 0; i < spell->targets.size(); i++) {
  8007. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8008. if (target && target->IsEntity()) {
  8009. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8010. if (target->IsPlayer())
  8011. ((Player*)target)->SetCharSheetChanged(true);
  8012. }
  8013. }
  8014. }
  8015. else {
  8016. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8017. if (spawn->IsPlayer())
  8018. ((Player*)spawn)->SetCharSheetChanged(true);
  8019. }
  8020. return 0;
  8021. }
  8022. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8023. if (!lua_interface)
  8024. return 0;
  8025. Spawn* spawn = lua_interface->GetSpawn(state);
  8026. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8027. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8028. lua_interface->ResetFunctionStack(state);
  8029. if (!spawn) {
  8030. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. if (!spawn->IsEntity()) {
  8034. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. if (spell && spell->targets.size() > 0) {
  8038. ZoneServer* zone = spell->caster->GetZone();
  8039. for (int8 i = 0; i < spell->targets.size(); i++) {
  8040. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8041. if (target && target->IsEntity()) {
  8042. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8043. if (target->IsPlayer())
  8044. ((Player*)target)->SetCharSheetChanged(true);
  8045. }
  8046. }
  8047. }
  8048. else {
  8049. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8050. if (spawn->IsPlayer())
  8051. ((Player*)spawn)->SetCharSheetChanged(true);
  8052. }
  8053. return 0;
  8054. }
  8055. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8056. if (!lua_interface)
  8057. return 0;
  8058. Item* item = lua_interface->GetItem(state);
  8059. int8 type = lua_interface->GetInt32Value(state, 2);
  8060. lua_interface->ResetFunctionStack(state);
  8061. if (!item) {
  8062. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8063. return 0;
  8064. }
  8065. if (type == 1)
  8066. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8067. else if (type == 2)
  8068. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8069. return 1;
  8070. }
  8071. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8072. if (!lua_interface)
  8073. return 0;
  8074. Spawn* target = lua_interface->GetSpawn(state);
  8075. float val = lua_interface->GetFloatValue(state, 2);
  8076. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8077. lua_interface->ResetFunctionStack(state);
  8078. // Added from Gangrenous post
  8079. if (spell && spell->resisted)
  8080. return 0;
  8081. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8082. if (val > 1.0f)
  8083. val = 1.0f - (val / 100.0f);
  8084. if (spell && spell->spell && spell->targets.size() > 0) {
  8085. ZoneServer* zone = spell->caster->GetZone();
  8086. for (int32 i = 0; i != spell->targets.size(); i++) {
  8087. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8088. if (spawn && spawn->IsEntity()) {
  8089. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8090. if (spawn->IsPlayer())
  8091. ((Player*)spawn)->SetCharSheetChanged(true);
  8092. }
  8093. }
  8094. }
  8095. else {
  8096. if (target && target->IsEntity()) {
  8097. ((Entity*)target)->SetSpeedMultiplier(val);
  8098. if (target->IsPlayer())
  8099. ((Player*)target)->SetCharSheetChanged(true);
  8100. }
  8101. }
  8102. return 0;
  8103. }
  8104. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8105. if (!lua_interface)
  8106. return 0;
  8107. Spawn* spawn = lua_interface->GetSpawn(state);
  8108. int16 model = lua_interface->GetInt16Value(state, 2);
  8109. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8110. lua_interface->ResetFunctionStack(state);
  8111. if (spell && spell->spell && spell->targets.size() > 0) {
  8112. ZoneServer* zone = spell->caster->GetZone();
  8113. for (int32 i = 0; i < spell->targets.size(); i++) {
  8114. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8115. if (target)
  8116. target->SetIllusionModel(model);
  8117. }
  8118. }
  8119. else {
  8120. if (!spawn) {
  8121. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8122. return 0;
  8123. }
  8124. spawn->SetIllusionModel(model);
  8125. }
  8126. return 0;
  8127. }
  8128. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8129. if (!lua_interface)
  8130. return 0;
  8131. Spawn* spawn = lua_interface->GetSpawn(state);
  8132. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8133. lua_interface->ResetFunctionStack(state);
  8134. if (spell && spell->spell && spell->targets.size() > 0) {
  8135. ZoneServer* zone = spell->caster->GetZone();
  8136. for (int32 i = 0; i < spell->targets.size(); i++) {
  8137. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8138. if (target)
  8139. target->SetIllusionModel(0);
  8140. }
  8141. }
  8142. else {
  8143. if (!spawn) {
  8144. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8145. return 0;
  8146. }
  8147. spawn->SetIllusionModel(0);
  8148. }
  8149. return 0;
  8150. }
  8151. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8152. if (!lua_interface)
  8153. return 0;
  8154. Spawn* caster = lua_interface->GetSpawn(state);
  8155. Spawn* target = lua_interface->GetSpawn(state, 2);
  8156. float chance = lua_interface->GetFloatValue(state, 3);
  8157. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8158. lua_interface->ResetFunctionStack(state);
  8159. if (!caster) {
  8160. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8161. return 0;
  8162. }
  8163. if (!caster->IsEntity()) {
  8164. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8165. return 0;
  8166. }
  8167. if (!target) {
  8168. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8169. return 0;
  8170. }
  8171. if (!target->IsEntity()) {
  8172. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8173. return 0;
  8174. }
  8175. if (chance <= 0) {
  8176. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8177. return 0;
  8178. }
  8179. if (!spell) {
  8180. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8181. return 0;
  8182. }
  8183. if(spell->resisted) {
  8184. return 0;
  8185. }
  8186. if (((Entity*)caster)->GetThreatTransfer()) {
  8187. return 0;
  8188. }
  8189. ThreatTransfer* transfer = new ThreatTransfer;
  8190. transfer->Target = target->GetID();
  8191. transfer->Amount = chance;
  8192. transfer->Spell = spell;
  8193. ((Entity*)caster)->SetThreatTransfer(transfer);
  8194. return 0;
  8195. }
  8196. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8197. if (!lua_interface)
  8198. return 0;
  8199. Spawn* spawn = lua_interface->GetSpawn(state);
  8200. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8201. lua_interface->ResetFunctionStack(state);
  8202. if (!spawn) {
  8203. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8204. return 0;
  8205. }
  8206. if (!spell) {
  8207. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8211. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8212. if(transfer && transfer->Spell != spell) {
  8213. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8214. return 0;
  8215. }
  8216. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8217. }
  8218. return 0;
  8219. }
  8220. int EQ2Emu_lua_CureByType(lua_State* state) {
  8221. if (!lua_interface)
  8222. return 0;
  8223. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8224. int8 cure_count = lua_interface->GetInt8Value(state);
  8225. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8226. string cure_name = lua_interface->GetStringValue(state, 3);
  8227. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8228. Spawn* target = lua_interface->GetSpawn(state, 5);
  8229. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8230. lua_interface->ResetFunctionStack(state);
  8231. if(spell && spell->resisted) {
  8232. return 0;
  8233. }
  8234. if (target) {
  8235. if (!target->IsEntity()) {
  8236. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8240. std::string alternate_name = "item";
  8241. if(spell)
  8242. alternate_name = std::string(spell->spell->GetName());
  8243. if(!caster && spell)
  8244. caster = (Spawn*)spell->caster;
  8245. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8246. }
  8247. }
  8248. else {
  8249. ZoneServer* zone = spell->caster->GetZone();
  8250. vector<int32> targets = spell->targets;
  8251. vector<Entity*> targets_to_cure;
  8252. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8253. for (int8 i = 0; i < targets.size(); i++) {
  8254. target = zone->GetSpawnByID(targets.at(i));
  8255. if (!target || !target->IsEntity())
  8256. continue;
  8257. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8258. targets_to_cure.push_back((Entity*)target);
  8259. }
  8260. }
  8261. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8262. vector<Entity*>::iterator itr;
  8263. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8264. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8265. }
  8266. }
  8267. return 0;
  8268. }
  8269. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8270. if (!lua_interface)
  8271. return 0;
  8272. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8273. if (!spell) {
  8274. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8275. lua_interface->ResetFunctionStack(state);
  8276. return 0;
  8277. }
  8278. if(spell->resisted) {
  8279. lua_interface->ResetFunctionStack(state);
  8280. return 0;
  8281. }
  8282. int8 cure_count = lua_interface->GetInt8Value(state);
  8283. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8284. string cure_name = lua_interface->GetStringValue(state, 3);
  8285. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8286. Spawn* target = lua_interface->GetSpawn(state, 5);
  8287. lua_interface->ResetFunctionStack(state);
  8288. if (target) {
  8289. if (!target->IsEntity()) {
  8290. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8291. return 0;
  8292. }
  8293. if (((Entity*)target)->GetDetCount() > 0)
  8294. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8295. }
  8296. else {
  8297. ZoneServer* zone = spell->caster->GetZone();
  8298. vector<int32> targets = spell->targets;
  8299. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8300. for (int8 i = 0; i < targets.size(); i++) {
  8301. target = zone->GetSpawnByID(targets.at(i));
  8302. if (!target || !target->IsEntity())
  8303. continue;
  8304. if (((Entity*)target)->GetDetCount() > 0)
  8305. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8306. }
  8307. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8308. }
  8309. return 0;
  8310. }
  8311. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8312. if (!lua_interface)
  8313. return 0;
  8314. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8315. lua_interface->ResetFunctionStack(state);
  8316. if (!spell) {
  8317. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (!spell->caster) {
  8321. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!spell->caster->GetZone()) {
  8325. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8329. return 0;
  8330. }
  8331. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8332. if (!lua_interface)
  8333. return 0;
  8334. Spawn* spawn = lua_interface->GetSpawn(state);
  8335. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8336. lua_interface->ResetFunctionStack(state);
  8337. if (!spell) {
  8338. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. if (spawn && spawn->IsEntity())
  8342. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8343. else {
  8344. ZoneServer* zone = spell->caster->GetZone();
  8345. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8346. for (int32 i = 0; i < spell->targets.size(); i++) {
  8347. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8348. if (!spawn || !spawn->IsEntity())
  8349. continue;
  8350. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8351. }
  8352. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8353. }
  8354. return 0;
  8355. }
  8356. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8357. if (!lua_interface)
  8358. return 0;
  8359. Spawn* spawn = lua_interface->GetSpawn(state);
  8360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8361. lua_interface->ResetFunctionStack(state);
  8362. if (!spell) {
  8363. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8364. return 0;
  8365. }
  8366. if (spawn && spawn->IsEntity())
  8367. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8368. else {
  8369. ZoneServer* zone = spell->caster->GetZone();
  8370. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8371. for (int32 i = 0; i < spell->targets.size(); i++) {
  8372. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8373. if (!spawn || !spawn->IsEntity())
  8374. continue;
  8375. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8376. }
  8377. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8378. }
  8379. return 0;
  8380. }
  8381. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8382. if (!lua_interface)
  8383. return 0;
  8384. Spawn* caster = lua_interface->GetSpawn(state);
  8385. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8386. lua_interface->ResetFunctionStack(state);
  8387. if (!caster) {
  8388. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. if (!caster->IsPlayer()) {
  8392. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. Spawn* target = caster->GetTarget();
  8396. if (!target) {
  8397. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8398. return 0;
  8399. }
  8400. Client* client = ((Player*)caster)->GetClient();
  8401. if (!client) {
  8402. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8403. return 0;
  8404. }
  8405. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8406. if (ho) {
  8407. ho->SetTarget(target->GetID());
  8408. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8409. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8410. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8411. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8412. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8413. deque<GroupMemberInfo*>::iterator itr;
  8414. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8415. if (group)
  8416. {
  8417. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8418. deque<GroupMemberInfo*>* members = group->GetMembers();
  8419. for (itr = members->begin(); itr != members->end(); itr++) {
  8420. if ((*itr)->client)
  8421. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8422. }
  8423. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8424. }
  8425. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8426. }
  8427. else
  8428. safe_delete(ho);
  8429. }
  8430. else {
  8431. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8432. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8433. }
  8434. else
  8435. safe_delete(ho);
  8436. }
  8437. }
  8438. return 0;
  8439. }
  8440. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8441. if (!lua_interface)
  8442. return 0;
  8443. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8444. if (!spell) {
  8445. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. int16 triggerCount = lua_interface->GetInt16Value(state);
  8449. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8450. if (!triggerCount) {
  8451. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. spell->num_triggers = triggerCount;
  8455. spell->had_triggers = true;
  8456. spell->cancel_after_all_triggers = cancel_after_triggers;
  8457. return 0;
  8458. }
  8459. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8460. if (!lua_interface)
  8461. return 0;
  8462. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8463. lua_interface->ResetFunctionStack(state);
  8464. if (!spell) {
  8465. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8466. return 0;
  8467. }
  8468. lua_interface->SetInt32Value(state, spell->num_triggers);
  8469. return 1;
  8470. }
  8471. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8472. if (!lua_interface)
  8473. return 0;
  8474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8475. if (!spell) {
  8476. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8477. lua_interface->ResetFunctionStack(state);
  8478. return 0;
  8479. }
  8480. int16 remove_count = lua_interface->GetInt16Value(state);
  8481. lua_interface->ResetFunctionStack(state);
  8482. if (!remove_count)
  8483. remove_count = 1;
  8484. if (remove_count >= spell->num_triggers) {
  8485. spell->num_triggers = 0;
  8486. if (spell->cancel_after_all_triggers)
  8487. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8488. }
  8489. else {
  8490. spell->num_triggers -= remove_count;
  8491. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8492. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8493. }
  8494. return 0;
  8495. }
  8496. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8497. if (!lua_interface)
  8498. return 0;
  8499. Spawn* spawn = lua_interface->GetSpawn(state);
  8500. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8501. lua_interface->ResetFunctionStack(state);
  8502. if (!spawn) {
  8503. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8504. return 0;
  8505. }
  8506. if (!copy_spawn) {
  8507. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. spawn->CopySpawnAppearance(copy_spawn);
  8511. return 0;
  8512. }
  8513. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8514. Spawn* spawn = lua_interface->GetSpawn(state);
  8515. int8 type = lua_interface->GetInt8Value(state, 2);
  8516. lua_interface->ResetFunctionStack(state);
  8517. if (!spawn) {
  8518. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8519. return 0;
  8520. }
  8521. else if (!spawn->IsEntity()) {
  8522. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8523. return 0;
  8524. }
  8525. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8526. return 1;
  8527. }
  8528. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8529. if (!lua_interface)
  8530. return 0;
  8531. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8532. int8 type = lua_interface->GetInt8Value(state);
  8533. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8534. lua_interface->ResetFunctionStack(state);
  8535. if (!spell) {
  8536. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. if(spell->resisted) {
  8540. return 0;
  8541. }
  8542. if (spawn) {
  8543. if (!spawn->IsEntity()) {
  8544. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8545. return 0;
  8546. }
  8547. Entity* entity = ((Entity*)spawn);
  8548. entity->AddImmunity(spell, type);
  8549. }
  8550. else {
  8551. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8552. for (int8 i = 0; i < spell->targets.size(); i++) {
  8553. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8554. if (!spawn || !spawn->IsEntity())
  8555. continue;
  8556. Entity* entity = ((Entity*)spawn);
  8557. entity->AddImmunity(spell, type);
  8558. }
  8559. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8560. }
  8561. return 0;
  8562. }
  8563. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8564. if (!lua_interface)
  8565. return 0;
  8566. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8567. int8 type = lua_interface->GetInt8Value(state);
  8568. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8569. lua_interface->ResetFunctionStack(state);
  8570. if (!spell) {
  8571. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8572. return 0;
  8573. }
  8574. if (spawn) {
  8575. if (!spawn->IsEntity()) {
  8576. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8577. return 0;
  8578. }
  8579. Entity* entity = ((Entity*)spawn);
  8580. entity->RemoveImmunity(spell, type);
  8581. }
  8582. else {
  8583. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8584. for (int8 i = 0; i < spell->targets.size(); i++) {
  8585. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8586. if (!spawn || !spawn->IsEntity())
  8587. continue;
  8588. Entity* entity = ((Entity*)spawn);
  8589. entity->RemoveImmunity(spell, type);
  8590. }
  8591. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8592. }
  8593. return 0;
  8594. }
  8595. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8596. if (!lua_interface)
  8597. return 0;
  8598. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8599. if (!spell) {
  8600. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8601. lua_interface->ResetFunctionStack(state);
  8602. return 0;
  8603. }
  8604. if(spell->resisted) {
  8605. lua_interface->ResetFunctionStack(state);
  8606. return 0;
  8607. }
  8608. float snare = lua_interface->GetFloatValue(state);
  8609. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8610. lua_interface->ResetFunctionStack(state);
  8611. // convert the val to the speed multipler value (100 - val)
  8612. float val = 100.0 - snare;
  8613. val /= 100.0;
  8614. if (spawn) {
  8615. if (!spawn->IsEntity()) {
  8616. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8617. return 0;
  8618. }
  8619. ((Entity*)spawn)->SetSnareValue(spell, val);
  8620. }
  8621. else {
  8622. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8623. for (int8 i = 0; i < spell->targets.size(); i++) {
  8624. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8625. if (!spawn || !spawn->IsEntity())
  8626. continue;
  8627. ((Entity*)spawn)->SetSnareValue(spell, val);
  8628. }
  8629. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8630. }
  8631. return 0;
  8632. }
  8633. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8634. if (!lua_interface)
  8635. return 0;
  8636. Spawn* spawn = lua_interface->GetSpawn(state);
  8637. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8638. lua_interface->ResetFunctionStack(state);
  8639. if (!spawn) {
  8640. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8641. return 0;
  8642. }
  8643. if (race_id == 0) {
  8644. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8645. return 0;
  8646. }
  8647. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8648. return 1;
  8649. }
  8650. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8651. if (!lua_interface)
  8652. return 0;
  8653. Spawn* spawn = lua_interface->GetSpawn(state);
  8654. lua_interface->ResetFunctionStack(state);
  8655. if (!spawn) {
  8656. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8657. return 0;
  8658. }
  8659. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8660. return 1;
  8661. }
  8662. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8663. if (!lua_interface)
  8664. return 0;
  8665. Spawn* spawn = lua_interface->GetSpawn(state);
  8666. lua_interface->ResetFunctionStack(state);
  8667. if (!spawn) {
  8668. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8672. return 1;
  8673. }
  8674. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8675. if (!lua_interface)
  8676. return 0;
  8677. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8678. lua_interface->ResetFunctionStack(state);
  8679. if (!spell) {
  8680. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8681. return 0;
  8682. }
  8683. lua_interface->SetStringValue(state, spell->spell->GetName());
  8684. return 1;
  8685. }
  8686. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8687. if (!lua_interface)
  8688. return 0;
  8689. Quest* quest = lua_interface->GetQuest(state);
  8690. lua_interface->ResetFunctionStack(state);
  8691. if (!quest) {
  8692. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8693. return 0;
  8694. }
  8695. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8696. return 1;
  8697. }
  8698. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8699. if (!lua_interface)
  8700. return 0;
  8701. Quest* quest = lua_interface->GetQuest(state);
  8702. int32 flags = lua_interface->GetInt32Value(state, 2);
  8703. lua_interface->ResetFunctionStack(state);
  8704. if (!quest) {
  8705. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8706. return 0;
  8707. }
  8708. quest->SetQuestFlags(flags);
  8709. return 0;
  8710. }
  8711. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8712. if (!lua_interface)
  8713. return 0;
  8714. Quest* quest = lua_interface->GetQuest(state);
  8715. Spawn* player = lua_interface->GetSpawn(state, 2);
  8716. int32 step = lua_interface->GetInt32Value(state, 3);
  8717. int32 duration = lua_interface->GetInt32Value(state, 4);
  8718. string action = lua_interface->GetStringValue(state, 5);
  8719. lua_interface->ResetFunctionStack(state);
  8720. if (!quest) {
  8721. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8722. return 0;
  8723. }
  8724. if (!player) {
  8725. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. if (!player->IsPlayer()) {
  8729. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. if (step == 0) {
  8733. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. if (duration == 0) {
  8737. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8738. return 0;
  8739. }
  8740. if (action.length() == 0) {
  8741. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8742. return 0;
  8743. }
  8744. Client* client = ((Player*)player)->GetClient();
  8745. if (!client) {
  8746. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. quest->SetTimerStep(step);
  8750. quest->AddFailedAction(step, action);
  8751. quest->SetStepTimer(duration);
  8752. client->AddQuestTimer(quest->GetQuestID());
  8753. return 0;
  8754. }
  8755. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8756. if (!lua_interface)
  8757. return 0;
  8758. Quest* quest = lua_interface->GetQuest(state);
  8759. Spawn* player = lua_interface->GetSpawn(state, 2);
  8760. lua_interface->ResetFunctionStack(state);
  8761. if (!quest) {
  8762. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8763. return 0;
  8764. }
  8765. if (!player) {
  8766. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8767. return 0;
  8768. }
  8769. if (!player->IsPlayer()) {
  8770. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8771. return 0;
  8772. }
  8773. Client* client = ((Player*)player)->GetClient();
  8774. if (!client) {
  8775. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8776. return 0;
  8777. }
  8778. quest->SetTimerStep(0);
  8779. quest->SetStepTimer(0);
  8780. client->RemoveQuestTimer(quest->GetQuestID());
  8781. return 0;
  8782. }
  8783. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8784. if (!lua_interface)
  8785. return 0;
  8786. Spawn* player = lua_interface->GetSpawn(state);
  8787. Quest* quest = lua_interface->GetQuest(state, 2);
  8788. int32 step = lua_interface->GetInt32Value(state, 3);
  8789. lua_interface->ResetFunctionStack(state);
  8790. if (!player) {
  8791. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8792. return 0;
  8793. }
  8794. if (!player->IsPlayer()) {
  8795. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8796. return 0;
  8797. }
  8798. if (!quest) {
  8799. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8800. return 0;
  8801. }
  8802. if (step == 0) {
  8803. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8804. return 0;
  8805. }
  8806. Client* client = ((Player*)player)->GetClient();
  8807. if (!client) {
  8808. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8809. return 0;
  8810. }
  8811. if (quest->RemoveQuestStep(step, client)) {
  8812. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8813. client->GetCurrentZone()->SendQuestUpdates(client);
  8814. }
  8815. else
  8816. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8817. return 0;
  8818. }
  8819. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. Quest* quest = lua_interface->GetQuest(state, 1);
  8823. int32 step = lua_interface->GetInt32Value(state, 2);
  8824. string desc = lua_interface->GetStringValue(state, 3);
  8825. string task_group = lua_interface->GetStringValue(state, 4);
  8826. lua_interface->ResetFunctionStack(state);
  8827. if (!quest) {
  8828. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8829. return 0;
  8830. }
  8831. if (step == 0) {
  8832. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8833. return 0;
  8834. }
  8835. QuestStep* quest_step = quest->GetQuestStep(step);
  8836. if (!quest_step) {
  8837. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8838. return 0;
  8839. }
  8840. quest_step->SetStepProgress(0);
  8841. quest_step->SetTaskGroup(task_group);
  8842. quest_step->SetDescription(desc);
  8843. return 0;
  8844. }
  8845. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8846. if (!lua_interface)
  8847. return 0;
  8848. Quest* quest = lua_interface->GetQuest(state);
  8849. int32 step = lua_interface->GetInt32Value(state, 2);
  8850. string action = lua_interface->GetStringValue(state, 3);
  8851. lua_interface->ResetFunctionStack(state);
  8852. if (!quest) {
  8853. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8854. return 0;
  8855. }
  8856. if (step == 0) {
  8857. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. if (action.length() == 0) {
  8861. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8862. return 0;
  8863. }
  8864. quest->AddFailedAction(step, action);
  8865. return 0;
  8866. }
  8867. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8868. if (!lua_interface)
  8869. return 0;
  8870. Spawn* player = lua_interface->GetSpawn(state);
  8871. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8872. int32 step = lua_interface->GetInt32Value(state, 3);
  8873. lua_interface->ResetFunctionStack(state);
  8874. if (!player) {
  8875. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8876. return 0;
  8877. }
  8878. if (!player->IsPlayer()) {
  8879. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8880. return 0;
  8881. }
  8882. if (quest_id == 0) {
  8883. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8884. return 0;
  8885. }
  8886. if (step == 0) {
  8887. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8888. return 0;
  8889. }
  8890. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8891. if (!quest) {
  8892. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8893. return 0;
  8894. }
  8895. quest->StepFailed(step);
  8896. return 0;
  8897. }
  8898. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8899. if (!lua_interface)
  8900. return 0;
  8901. Spawn* player = lua_interface->GetSpawn(state);
  8902. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8903. lua_interface->ResetFunctionStack(state);
  8904. if (!player) {
  8905. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8906. return 0;
  8907. }
  8908. if (!player->IsPlayer()) {
  8909. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8910. return 0;
  8911. }
  8912. if (quest_id == 0) {
  8913. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8914. return 0;
  8915. }
  8916. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8917. if (!quest) {
  8918. lua_interface->SetInt32Value(state, 0);
  8919. return 1;
  8920. }
  8921. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8922. return 1;
  8923. }
  8924. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8925. if (!lua_interface)
  8926. return 0;
  8927. string name = lua_interface->GetStringValue(state);
  8928. string value = lua_interface->GetStringValue(state, 2);
  8929. string comment = lua_interface->GetStringValue(state, 3);
  8930. lua_interface->ResetFunctionStack(state);
  8931. if (name.length() == 0) {
  8932. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8933. return 0;
  8934. }
  8935. if (value.length() == 0) {
  8936. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8937. return 0;
  8938. }
  8939. string varname = string("lua_").append(name);
  8940. Variable* var = variables.FindVariable(varname);
  8941. if (var)
  8942. var->SetValue(value.c_str());
  8943. else {
  8944. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8945. variables.AddVariable(var);
  8946. }
  8947. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8948. return 0;
  8949. }
  8950. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8951. if (!lua_interface)
  8952. return 0;
  8953. string name = lua_interface->GetStringValue(state);
  8954. lua_interface->ResetFunctionStack(state);
  8955. if (name.length() == 0) {
  8956. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. string varname = string("lua_").append(name);
  8960. Variable* var = variables.FindVariable(varname);
  8961. if (var)
  8962. lua_interface->SetStringValue(state, var->GetValue());
  8963. else
  8964. lua_interface->SetStringValue(state, "NULL");
  8965. return 1;
  8966. }
  8967. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8968. if (!lua_interface)
  8969. return 0;
  8970. Spawn* player = lua_interface->GetSpawn(state);
  8971. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8972. lua_interface->ResetFunctionStack(state);
  8973. if (!player) {
  8974. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8975. return 0;
  8976. }
  8977. if (!player->IsPlayer()) {
  8978. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8979. return 0;
  8980. }
  8981. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8982. return 1;
  8983. }
  8984. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8985. if (!lua_interface)
  8986. return 0;
  8987. Spawn* player = lua_interface->GetSpawn(state);
  8988. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8989. lua_interface->ResetFunctionStack(state);
  8990. if (!player) {
  8991. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8992. return 0;
  8993. }
  8994. if (!player->IsPlayer()) {
  8995. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8996. return 0;
  8997. }
  8998. Language* language = master_languages_list.GetLanguage(language_id);
  8999. if (language)
  9000. {
  9001. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9002. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9003. }
  9004. return 0;
  9005. }
  9006. int EQ2Emu_lua_IsNight(lua_State* state) {
  9007. if (!lua_interface)
  9008. return 0;
  9009. ZoneServer* zone = lua_interface->GetZone(state);
  9010. lua_interface->ResetFunctionStack(state);
  9011. if (!zone) {
  9012. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9013. return 0;
  9014. }
  9015. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9016. return 1;
  9017. }
  9018. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9019. if (!lua_interface)
  9020. return 0;
  9021. Spawn* spawn = lua_interface->GetSpawn(state);
  9022. lua_interface->ResetFunctionStack(state);
  9023. if (!spawn) {
  9024. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9025. return 0;
  9026. }
  9027. if (!spawn->IsWidget()) {
  9028. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9029. return 0;
  9030. }
  9031. ((Widget*)spawn)->SetMultiFloorLift(true);
  9032. if (spawn->GetZone())
  9033. spawn->GetZone()->AddTransportSpawn(spawn);
  9034. return 0;
  9035. }
  9036. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9037. if (!lua_interface)
  9038. return 0;
  9039. Spawn* player = lua_interface->GetSpawn(state);
  9040. int32 path = lua_interface->GetInt32Value(state, 2);
  9041. lua_interface->ResetFunctionStack(state);
  9042. if (!player) {
  9043. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9044. return 0;
  9045. }
  9046. if (!player->IsPlayer()) {
  9047. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9048. return 0;
  9049. }
  9050. if (path == 0) {
  9051. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. Client* client = ((Player*)player)->GetClient();
  9055. if (!client) {
  9056. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. client->SendFlightAutoMount(path);
  9060. return 0;
  9061. }
  9062. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9063. if (!lua_interface)
  9064. return 0;
  9065. Spawn* player = lua_interface->GetSpawn(state);
  9066. if (!player) {
  9067. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9068. return 0;
  9069. }
  9070. if (!player->IsPlayer()) {
  9071. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9072. return 0;
  9073. }
  9074. Client* client = ((Player*)player)->GetClient();
  9075. if (!client) {
  9076. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. client->EndAutoMount();
  9080. return 0;
  9081. }
  9082. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9083. if (!lua_interface)
  9084. return 0;
  9085. Spawn* player = lua_interface->GetSpawn(state);
  9086. lua_interface->ResetFunctionStack(state);
  9087. if (!player) {
  9088. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9089. return 0;
  9090. }
  9091. if (!player->IsPlayer()) {
  9092. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9093. return 0;
  9094. }
  9095. Client* client = ((Player*)player)->GetClient();
  9096. if (!client) {
  9097. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9098. return 0;
  9099. }
  9100. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9101. return 1;
  9102. }
  9103. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9104. if (!lua_interface)
  9105. return 0;
  9106. Spawn* player = lua_interface->GetSpawn(state);
  9107. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9108. int32 value = lua_interface->GetInt32Value(state, 3);
  9109. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9110. lua_interface->ResetFunctionStack(state);
  9111. if (!player) {
  9112. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9113. return 0;
  9114. }
  9115. if (!player->IsPlayer()) {
  9116. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9117. return 0;
  9118. }
  9119. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9120. return 0;
  9121. }
  9122. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9123. if (!lua_interface)
  9124. return 0;
  9125. Spawn* player = lua_interface->GetSpawn(state);
  9126. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9127. lua_interface->ResetFunctionStack(state);
  9128. if (!player) {
  9129. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9130. return 0;
  9131. }
  9132. if (!player->IsPlayer()) {
  9133. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9134. return 0;
  9135. }
  9136. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9137. if (!hd)
  9138. return 0;
  9139. lua_interface->SetInt32Value(state, hd->Value);
  9140. lua_interface->SetInt32Value(state, hd->Value2);
  9141. return 2;
  9142. }
  9143. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9144. if (!lua_interface)
  9145. return 0;
  9146. Spawn* spawn = lua_interface->GetSpawn(state);
  9147. int32 grid = lua_interface->GetInt32Value(state, 2);
  9148. lua_interface->ResetFunctionStack(state);
  9149. if (!spawn) {
  9150. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9151. return 0;
  9152. }
  9153. if (grid == 0) {
  9154. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9155. return 0;
  9156. }
  9157. spawn->SetLocation(grid);
  9158. return 0;
  9159. }
  9160. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9161. if (!lua_interface)
  9162. return 0;
  9163. Spawn* spawn = lua_interface->GetSpawn(state);
  9164. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9165. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9166. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9167. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9168. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9169. lua_interface->ResetFunctionStack(state);
  9170. if (!spawn) {
  9171. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9172. return 0;
  9173. }
  9174. //Add this quest to the list of required quests for this spawn
  9175. spawn->SetRequiredHistory(event_id, value1, value2);
  9176. //If private spawn value set
  9177. if (private_spawn) {
  9178. //Set the spawn to be private when not granted access via history
  9179. spawn->AddAllowAccessSpawn(spawn);
  9180. spawn->SetPrivateQuestSpawn(true);
  9181. }
  9182. //This value will override vis_flags in the vis packet
  9183. if (flag_override > 0)
  9184. spawn->SetQuestsRequiredOverride(flag_override);
  9185. return 0;
  9186. }
  9187. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9188. if (!lua_interface)
  9189. return 0;
  9190. Spawn* player = lua_interface->GetSpawn(state);
  9191. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9192. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9193. lua_interface->ResetFunctionStack(state);
  9194. if (!player) {
  9195. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9196. return 0;
  9197. }
  9198. if (!player->IsPlayer()) {
  9199. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9200. return 0;
  9201. }
  9202. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9203. return 1;
  9204. }
  9205. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9206. if (!lua_interface)
  9207. return 0;
  9208. Spawn* player = lua_interface->GetSpawn(state);
  9209. int8 level = lua_interface->GetInt8Value(state, 2);
  9210. lua_interface->ResetFunctionStack(state);
  9211. if (!player) {
  9212. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9213. return 0;
  9214. }
  9215. if (!player->IsPlayer()) {
  9216. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9217. return 0;
  9218. }
  9219. if (level == 0) {
  9220. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9221. return 0;
  9222. }
  9223. Client* client = ((Player*)player)->GetClient();
  9224. if (!client) {
  9225. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9229. return 0;
  9230. }
  9231. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9232. if (!lua_interface)
  9233. return 0;
  9234. Spawn* player = lua_interface->GetSpawn(state);
  9235. int32 amount = lua_interface->GetInt32Value(state, 2);
  9236. lua_interface->ResetFunctionStack(state);
  9237. if (!player) {
  9238. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9239. return 0;
  9240. }
  9241. if (!player->IsPlayer()) {
  9242. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9243. return 0;
  9244. }
  9245. if (amount == 0) {
  9246. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9247. return 0;
  9248. }
  9249. ((Player*)player)->AddCoins(amount);
  9250. return 0;
  9251. }
  9252. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9253. if (!lua_interface)
  9254. return 0;
  9255. Spawn* player = lua_interface->GetSpawn(state);
  9256. int32 amount = lua_interface->GetInt32Value(state, 2);
  9257. lua_interface->ResetFunctionStack(state);
  9258. if (!player) {
  9259. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9260. return 0;
  9261. }
  9262. if (!player->IsPlayer()) {
  9263. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9264. return 0;
  9265. }
  9266. if (amount == 0) {
  9267. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9268. return 0;
  9269. }
  9270. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9271. return 1;
  9272. }
  9273. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9274. if (!lua_interface)
  9275. return 0;
  9276. ZoneServer* zone = lua_interface->GetZone(state);
  9277. lua_interface->ResetFunctionStack(state);
  9278. if (!zone) {
  9279. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9280. return 0;
  9281. }
  9282. vector<Entity*> players = zone->GetPlayers();
  9283. if (players.size() == 0)
  9284. return 0;
  9285. lua_createtable(state, players.size(), 0);
  9286. int newTable = lua_gettop(state);
  9287. for (int32 i = 0; i < players.size(); i++) {
  9288. lua_interface->SetSpawnValue(state, players.at(i));
  9289. lua_rawseti(state, newTable, i + 1);
  9290. }
  9291. return 1;
  9292. }
  9293. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9294. if (!lua_interface)
  9295. return 0;
  9296. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9297. if (!zone) {
  9298. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9302. lua_interface->ResetFunctionStack(state);
  9303. //Map of <placement_id, location_id>
  9304. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9305. map<int32, int32>::iterator itr;
  9306. vector<Spawn*> group;
  9307. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9308. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9309. if (!location) {
  9310. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9311. return 0;
  9312. }
  9313. Spawn* spawn = 0;
  9314. if (location->entities[0]) {
  9315. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9316. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9317. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9318. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9319. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9320. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9321. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9322. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9323. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9324. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9325. if(spawn && spawn->IsOmittedByDBFlag())
  9326. {
  9327. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9328. safe_delete(spawn);
  9329. continue;
  9330. }
  9331. if (spawn) {
  9332. const char* script = 0;
  9333. for (int x = 0; x < 3; x++) {
  9334. switch (x) {
  9335. case 0:
  9336. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9337. break;
  9338. case 1:
  9339. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9340. break;
  9341. case 2:
  9342. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9343. break;
  9344. }
  9345. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9346. spawn->SetSpawnScript(string(script));
  9347. break;
  9348. }
  9349. }
  9350. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9351. lua_interface->SetSpawnValue(state, spawn);
  9352. group.push_back(spawn);
  9353. }
  9354. else {
  9355. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9356. safe_delete(spawn);
  9357. }
  9358. }
  9359. }
  9360. if (!group.empty()) {
  9361. lua_createtable(state, group.size(), 0);
  9362. int newTable = lua_gettop(state);
  9363. for (int32 i = 0; i < group.size(); i++) {
  9364. lua_interface->SetSpawnValue(state, group[i]);
  9365. lua_rawseti(state, newTable, i + 1);
  9366. }
  9367. }
  9368. else
  9369. lua_pushnil(state);
  9370. return 1;
  9371. }
  9372. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9373. if (!lua_interface)
  9374. return 0;
  9375. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9376. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9377. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9378. lua_interface->ResetFunctionStack(state);
  9379. if (!spawn) {
  9380. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9381. return 0;
  9382. }
  9383. if (anim_id == 0) {
  9384. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9385. return 0;
  9386. }
  9387. if (leeway == 0)
  9388. leeway = 5000;
  9389. spawn->SetSpawnAnim(anim_id);
  9390. spawn->SetSpawnAnimLeeway(leeway);
  9391. return 0;
  9392. }
  9393. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9394. if (!lua_interface)
  9395. return 0;
  9396. Spawn* player = lua_interface->GetSpawn(state);
  9397. lua_interface->ResetFunctionStack(state);
  9398. if (!player || !player->IsPlayer()) {
  9399. return 0;
  9400. }
  9401. Client* client = ((Player*)player)->GetClient();
  9402. if (!client) {
  9403. return 0;
  9404. }
  9405. lua_interface->SetInt32Value(state, client->GetVersion());
  9406. return 1;
  9407. }
  9408. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9409. if (!lua_interface)
  9410. return 0;
  9411. Item* item = lua_interface->GetItem(state);
  9412. lua_interface->ResetFunctionStack(state);
  9413. if (!item) {
  9414. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9415. return 0;
  9416. }
  9417. lua_interface->SetInt32Value(state, item->details.item_id);
  9418. return 1;
  9419. }
  9420. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9421. if (!lua_interface)
  9422. return 0;
  9423. Spawn* spawn = lua_interface->GetSpawn(state);
  9424. lua_interface->ResetFunctionStack(state);
  9425. if (!spawn) {
  9426. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9427. return 0;
  9428. }
  9429. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9430. return 1;
  9431. }
  9432. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9433. if (!lua_interface)
  9434. return 0;
  9435. Spawn* spawn = lua_interface->GetSpawn(state);
  9436. lua_interface->ResetFunctionStack(state);
  9437. if (!spawn) {
  9438. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9439. return 0;
  9440. }
  9441. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9442. return 1;
  9443. }
  9444. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9445. if (!lua_interface)
  9446. return 0;
  9447. Spawn* spawn = lua_interface->GetSpawn(state);
  9448. lua_interface->ResetFunctionStack(state);
  9449. if (!spawn) {
  9450. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9451. return 0;
  9452. }
  9453. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9454. return 1;
  9455. }
  9456. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9457. if (!lua_interface)
  9458. return 0;
  9459. Spawn* spawn = lua_interface->GetSpawn(state);
  9460. lua_interface->ResetFunctionStack(state);
  9461. if (!spawn) {
  9462. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9463. return 0;
  9464. }
  9465. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9466. return 1;
  9467. }
  9468. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9469. if (!lua_interface)
  9470. return 0;
  9471. Spawn* spawn = lua_interface->GetSpawn(state);
  9472. float pct = lua_interface->GetFloatValue(state, 2);
  9473. lua_interface->ResetFunctionStack(state);
  9474. if (!spawn) {
  9475. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9476. return 0;
  9477. }
  9478. if (pct == 0) {
  9479. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9480. return 0;
  9481. }
  9482. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9483. lua_interface->SetInt32Value(state, amount);
  9484. return 1;
  9485. }
  9486. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9487. if (!lua_interface)
  9488. return 0;
  9489. Spawn* spawn = lua_interface->GetSpawn(state);
  9490. float pct = lua_interface->GetFloatValue(state, 2);
  9491. lua_interface->ResetFunctionStack(state);
  9492. if (!spawn) {
  9493. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9494. return 0;
  9495. }
  9496. if (pct == 0) {
  9497. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9498. return 0;
  9499. }
  9500. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9501. lua_interface->SetInt32Value(state, amount);
  9502. return 1;
  9503. }
  9504. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9505. if (!lua_interface)
  9506. return 0;
  9507. Spawn* spawn = lua_interface->GetSpawn(state);
  9508. lua_interface->ResetFunctionStack(state);
  9509. if (!spawn) {
  9510. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9511. return 0;
  9512. }
  9513. if (!spawn->IsPlayer()) {
  9514. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9515. return 0;
  9516. }
  9517. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9518. return 1;
  9519. }
  9520. int EQ2Emu_lua_Evac(lua_State* state) {
  9521. if (!lua_interface)
  9522. return 0;
  9523. Spawn* target = lua_interface->GetSpawn(state);
  9524. if (target) {
  9525. float x = target->GetZone()->GetSafeX();
  9526. float y = target->GetZone()->GetSafeY();
  9527. float z = target->GetZone()->GetSafeZ();
  9528. float h = target->GetZone()->GetSafeHeading();
  9529. target->SetX(x);
  9530. target->SetY(y);
  9531. target->SetZ(z);
  9532. target->SetHeading(h);
  9533. target->SetSpawnOrigX(x);
  9534. target->SetSpawnOrigY(y);
  9535. target->SetSpawnOrigZ(z);
  9536. target->SetSpawnOrigHeading(h);
  9537. if (target->IsPlayer()) {
  9538. Client* client = ((Player*)target)->GetClient();
  9539. if (client) {
  9540. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9541. int numargs = lua_interface->GetNumberOfArgs(state);
  9542. if(numargs == 4) {
  9543. x = lua_interface->GetFloatValue(state,1);
  9544. y = lua_interface->GetFloatValue(state,2);
  9545. z = lua_interface->GetFloatValue(state,3);
  9546. h = lua_interface->GetFloatValue(state,4);
  9547. }
  9548. client->SetReloadingZone(true);
  9549. target->SetX(x);
  9550. target->SetY(y);
  9551. target->SetZ(z);
  9552. target->SetHeading(h);
  9553. target->SetSpawnOrigX(x);
  9554. target->SetSpawnOrigY(y);
  9555. target->SetSpawnOrigZ(z);
  9556. target->SetSpawnOrigHeading(h);
  9557. target->SetAppearancePosition(x,y,z);
  9558. client->SetZoningCoords(x,y,z,h);
  9559. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9560. if (packet)
  9561. {
  9562. packet->setDataByName("x", x);
  9563. packet->setDataByName("y", y);
  9564. packet->setDataByName("z", z);
  9565. client->QueuePacket(packet->serialize());
  9566. safe_delete(packet);
  9567. }
  9568. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9569. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9570. }
  9571. }
  9572. lua_interface->ResetFunctionStack(state);
  9573. }
  9574. else {
  9575. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9576. if(!spell) {
  9577. lua_interface->ResetFunctionStack(state);
  9578. return 0;
  9579. }
  9580. ZoneServer* zone = spell->caster->GetZone();
  9581. float x = spell->caster->GetZone()->GetSafeX();
  9582. float y = spell->caster->GetZone()->GetSafeY();
  9583. float z = spell->caster->GetZone()->GetSafeZ();
  9584. float h = spell->caster->GetZone()->GetSafeHeading();
  9585. int numargs = lua_interface->GetNumberOfArgs(state);
  9586. if(numargs == 4) {
  9587. x = lua_interface->GetFloatValue(state,1);
  9588. y = lua_interface->GetFloatValue(state,2);
  9589. z = lua_interface->GetFloatValue(state,3);
  9590. h = lua_interface->GetFloatValue(state,4);
  9591. }
  9592. lua_interface->ResetFunctionStack(state);
  9593. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9594. for (int32 i = 0; i < spell->targets.size(); i++) {
  9595. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9596. if (!target2)
  9597. continue;
  9598. if (target2->IsPlayer()) {
  9599. Client* client = ((Player*)target2)->GetClient();
  9600. if (client) {
  9601. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9602. client->SetReloadingZone(true);
  9603. target2->SetX(x);
  9604. target2->SetY(y);
  9605. target2->SetZ(z);
  9606. target2->SetHeading(h);
  9607. target2->SetSpawnOrigX(x);
  9608. target2->SetSpawnOrigY(y);
  9609. target2->SetSpawnOrigZ(z);
  9610. target2->SetSpawnOrigHeading(h);
  9611. target2->SetAppearancePosition(x,y,z);
  9612. client->SetZoningCoords(x,y,z,h);
  9613. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9614. if (packet)
  9615. {
  9616. packet->setDataByName("x", x);
  9617. packet->setDataByName("y", y);
  9618. packet->setDataByName("z", z);
  9619. client->QueuePacket(packet->serialize());
  9620. safe_delete(packet);
  9621. }
  9622. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9623. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9624. }
  9625. }
  9626. }
  9627. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9628. }
  9629. return 0;
  9630. }
  9631. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9632. if (!lua_interface)
  9633. return 0;
  9634. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9635. lua_interface->ResetFunctionStack(state);
  9636. if (!luaspell) {
  9637. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9638. return 0;
  9639. }
  9640. int8 tier = luaspell->spell->GetSpellTier();
  9641. lua_interface->SetInt32Value(state, tier);
  9642. return 1;
  9643. }
  9644. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9645. if (!lua_interface)
  9646. return 0;
  9647. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9648. lua_interface->ResetFunctionStack(state);
  9649. if (!luaspell) {
  9650. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9651. return 0;
  9652. }
  9653. int32 spell_id = luaspell->spell->GetSpellID();
  9654. lua_interface->SetInt32Value(state, spell_id);
  9655. return 1;
  9656. }
  9657. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9658. if (!lua_interface)
  9659. return 0;
  9660. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9661. lua_interface->ResetFunctionStack(state);
  9662. if (!spawn) {
  9663. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9664. return 0;
  9665. }
  9666. if (!spawn->IsPlayer()) {
  9667. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9668. return 0;
  9669. }
  9670. ZoneServer* zone = spawn->GetZone();
  9671. if (!zone) {
  9672. return 0;
  9673. }
  9674. Client* client = ((Player*)spawn)->GetClient();
  9675. if (!client) {
  9676. return 0;
  9677. }
  9678. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9679. return 0;
  9680. }
  9681. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9682. if (!lua_interface)
  9683. return 0;
  9684. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9685. lua_interface->ResetFunctionStack(state);
  9686. if (!spawn) {
  9687. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9688. return 0;
  9689. }
  9690. if (!spawn->IsPlayer()) {
  9691. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9692. return 0;
  9693. }
  9694. ZoneServer* zone = spawn->GetZone();
  9695. if (!zone) {
  9696. return 0;
  9697. }
  9698. Client* client = ((Player*)spawn)->GetClient();
  9699. if (!client) {
  9700. return 0;
  9701. }
  9702. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9703. return 0;
  9704. }
  9705. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9706. if (!lua_interface)
  9707. return 0;
  9708. Spawn* caster = lua_interface->GetSpawn(state);
  9709. Spawn* target = lua_interface->GetSpawn(state, 2);
  9710. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9711. string spell_name = lua_interface->GetStringValue(state, 4);
  9712. lua_interface->ResetFunctionStack(state);
  9713. if (!caster) {
  9714. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9715. return 0;
  9716. }
  9717. if (!caster->IsEntity()) {
  9718. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9719. return 0;
  9720. }
  9721. if (!target) {
  9722. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9723. return 0;
  9724. }
  9725. if (!target->IsEntity()) {
  9726. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9727. return 0;
  9728. }
  9729. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9730. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9731. return 0;
  9732. }
  9733. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9734. if (!lua_interface)
  9735. return 0;
  9736. Spawn* player = lua_interface->GetSpawn(state);
  9737. int32 amount = lua_interface->GetInt32Value(state, 2);
  9738. lua_interface->ResetFunctionStack(state);
  9739. if (player && player->IsPlayer() && amount > 0) {
  9740. ((Player*)player)->AddXP(amount);
  9741. }
  9742. return 0;
  9743. }
  9744. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9745. if (!lua_interface)
  9746. return 0;
  9747. Spawn* player = lua_interface->GetSpawn(state);
  9748. int8 type = lua_interface->GetInt8Value(state, 2);
  9749. string text = lua_interface->GetStringValue(state, 3);
  9750. lua_interface->ResetFunctionStack(state);
  9751. Client* client = 0;
  9752. if (player && player->IsPlayer())
  9753. client = ((Player*)player)->GetClient();
  9754. if (!client || text.length() == 0) {
  9755. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9756. return 0;
  9757. }
  9758. client->SimpleMessage(type, text.c_str());
  9759. return 0;
  9760. }
  9761. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9762. if (!lua_interface)
  9763. return 0;
  9764. Spawn* player = lua_interface->GetSpawn(state);
  9765. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9766. lua_interface->ResetFunctionStack(state);
  9767. Client* client = 0;
  9768. if (player && player->IsPlayer())
  9769. client = ((Player*)player)->GetClient();
  9770. if (!client || !spawn) {
  9771. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9772. return 0;
  9773. }
  9774. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9775. if (!items) {
  9776. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9777. return 0;
  9778. }
  9779. client->Loot(spawn->GetLootCoins(), items, spawn);
  9780. return 0;
  9781. }
  9782. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9783. if (!lua_interface)
  9784. return 0;
  9785. Spawn* spawnref = lua_interface->GetSpawn(state);
  9786. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9787. lua_interface->ResetFunctionStack(state);
  9788. if (spawn_id > 0 && spawnref) {
  9789. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9790. if (spawns.size() == 0) {
  9791. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9792. return 0;
  9793. }
  9794. Spawn* spawn = 0;
  9795. int16 index = MakeRandomInt(0, spawns.size());
  9796. if (index >= spawns.size() || index < 0)
  9797. index = 0;
  9798. spawn = spawns[index];
  9799. lua_interface->SetSpawnValue(state, spawn);
  9800. return 1;
  9801. }
  9802. else {
  9803. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9804. }
  9805. return 0;
  9806. }
  9807. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9808. Spawn* player = lua_interface->GetSpawn(state);
  9809. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9810. string name = lua_interface->GetStringValue(state, 3);
  9811. float distance = lua_interface->GetFloatValue(state, 4);
  9812. string command = lua_interface->GetStringValue(state, 5);
  9813. string error_text = lua_interface->GetStringValue(state, 6);
  9814. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9815. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9816. lua_interface->ResetFunctionStack(state);
  9817. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9818. if (distance == 0)
  9819. distance = 10.0f;
  9820. if (command.length() == 0)
  9821. command = name;
  9822. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9823. if (spawns.size() == 0) {
  9824. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9825. return 0;
  9826. }
  9827. Spawn* spawn = 0;
  9828. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9829. spawn = *itr;
  9830. if (spawn) {
  9831. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9832. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9833. }
  9834. }
  9835. }
  9836. return 0;
  9837. }
  9838. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9839. if (!lua_interface)
  9840. return 0;
  9841. Client* client = 0;
  9842. Spawn* player = lua_interface->GetSpawn(state);
  9843. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9844. lua_interface->ResetFunctionStack(state);
  9845. if (player && player->IsPlayer() && player->GetZone())
  9846. client = ((Player*)player)->GetClient();
  9847. else{
  9848. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9849. return 0;
  9850. }
  9851. if (client) {
  9852. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9853. if (packet) {
  9854. packet->setDataByName("goal_num", goal_num);
  9855. client->QueuePacket(packet->serialize());
  9856. safe_delete(packet);
  9857. }
  9858. }
  9859. return 0;
  9860. }
  9861. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9862. if (!lua_interface)
  9863. return 0;
  9864. Client* client = 0;
  9865. Spawn* player = lua_interface->GetSpawn(state);
  9866. lua_interface->ResetFunctionStack(state);
  9867. if (player && player->IsPlayer() && player->GetZone())
  9868. client = ((Player*)player)->GetClient();
  9869. else {
  9870. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9871. return 0;
  9872. }
  9873. if (client) {
  9874. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9875. }
  9876. return 0;
  9877. }
  9878. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9879. if (!lua_interface)
  9880. return 0;
  9881. Client* client = 0;
  9882. Spawn* player = lua_interface->GetSpawn(state);
  9883. float duration = lua_interface->GetFloatValue(state, 2);
  9884. string text = lua_interface->GetStringValue(state, 3);
  9885. string voice = lua_interface->GetStringValue(state, 4);
  9886. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9887. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9888. string signal = lua_interface->GetStringValue(state, 7);
  9889. string goal1 = lua_interface->GetStringValue(state, 8);
  9890. string task1 = lua_interface->GetStringValue(state, 9);
  9891. string goal2 = lua_interface->GetStringValue(state, 10);
  9892. string task2 = lua_interface->GetStringValue(state, 11);
  9893. string goal3 = lua_interface->GetStringValue(state, 12);
  9894. string task3 = lua_interface->GetStringValue(state, 13);
  9895. string goal4 = lua_interface->GetStringValue(state, 14);
  9896. string task4 = lua_interface->GetStringValue(state, 15);
  9897. lua_interface->ResetFunctionStack(state);
  9898. if (!player) {
  9899. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9900. return 0;
  9901. }
  9902. if (!player->IsPlayer()) {
  9903. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9904. return 0;
  9905. }
  9906. else
  9907. client = ((Player*)player)->GetClient();
  9908. if (!client) {
  9909. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9910. return 0;
  9911. }
  9912. if (text.length() == 0) {
  9913. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9914. return 0;
  9915. }
  9916. if (duration >= 0 && duration < 2)
  9917. duration = 2;
  9918. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9919. if (packet) {
  9920. packet->setDataByName("open_seconds_max", duration);
  9921. packet->setDataByName("text", text.c_str());
  9922. packet->setDataByName("voice", voice.c_str());
  9923. int8 num_goals = 1;
  9924. if (task2.length() > 0)
  9925. num_goals++;
  9926. if (task3.length() > 0)
  9927. num_goals++;
  9928. if (task4.length() > 0)
  9929. num_goals++;
  9930. packet->setArrayLengthByName("num_goals", num_goals);
  9931. for (int8 i = 0; i < num_goals; i++) {
  9932. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9933. }
  9934. if (goal1.length() > 0)
  9935. packet->setArrayDataByName("goal_text", goal1.c_str());
  9936. if (goal2.length() > 0)
  9937. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9938. if (goal3.length() > 0)
  9939. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9940. if (goal4.length() > 0)
  9941. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9942. packet->setSubArrayDataByName("task_text", task1.c_str());
  9943. if (task2.length() > 0)
  9944. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9945. if (task3.length() > 0)
  9946. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9947. if (task4.length() > 0)
  9948. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9949. packet->setDataByName("complete_sound", "click");
  9950. packet->setDataByName("signal", signal.c_str());
  9951. packet->setDataByName("voice_key1", voice_key1);
  9952. packet->setDataByName("voice_key2", voice_key2);
  9953. client->QueuePacket(packet->serialize());
  9954. safe_delete(packet);
  9955. }
  9956. return 0;
  9957. }
  9958. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9959. if (!lua_interface)
  9960. return 0;
  9961. Client* client = 0;
  9962. Spawn* player = lua_interface->GetSpawn(state);
  9963. string window = lua_interface->GetStringValue(state, 2);
  9964. int8 show = lua_interface->GetInt8Value(state, 3);
  9965. lua_interface->ResetFunctionStack(state);
  9966. if (!player) {
  9967. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9968. return 0;
  9969. }
  9970. if (!player->IsPlayer()) {
  9971. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9972. return 0;
  9973. }
  9974. else
  9975. client = ((Player*)player)->GetClient();
  9976. if (!client) {
  9977. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9978. return 0;
  9979. }
  9980. if (window.length() == 0) {
  9981. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9982. return 0;
  9983. }
  9984. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9985. if (packet) {
  9986. packet->setDataByName("window", window.c_str());
  9987. packet->setDataByName("show", show);
  9988. client->QueuePacket(packet->serialize());
  9989. safe_delete(packet);
  9990. }
  9991. return 0;
  9992. }
  9993. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9994. //See GameEvents.txt for options that can be used for this function
  9995. if (!lua_interface)
  9996. return 0;
  9997. Client* client = 0;
  9998. Spawn* player = lua_interface->GetSpawn(state);
  9999. string event_name = lua_interface->GetStringValue(state, 2);
  10000. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10001. lua_interface->ResetFunctionStack(state);
  10002. if (!player || !player->IsPlayer()) {
  10003. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10004. return 0;
  10005. }
  10006. client = ((Player*)player)->GetClient();
  10007. if (!client) {
  10008. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10009. return 0;
  10010. }
  10011. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10012. if (packet) {
  10013. packet->setDataByName("event_name", event_name.c_str());
  10014. packet->setDataByName("enabled", enabled);
  10015. client->QueuePacket(packet->serialize());
  10016. safe_delete(packet);
  10017. }
  10018. return 0;
  10019. }
  10020. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10021. if (!lua_interface)
  10022. return 0;
  10023. Spawn* player = lua_interface->GetSpawn(state);
  10024. lua_interface->ResetFunctionStack(state);
  10025. if (player && player->IsPlayer()) {
  10026. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10027. return 1;
  10028. }
  10029. return 0;
  10030. }
  10031. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10032. if (!lua_interface)
  10033. return 0;
  10034. Spawn* player = lua_interface->GetSpawn(state);
  10035. int8 step = lua_interface->GetInt8Value(state, 2);
  10036. lua_interface->ResetFunctionStack(state);
  10037. if (player && player->IsPlayer() && step > 0) {
  10038. ((Player*)player)->SetTutorialStep(step);
  10039. }
  10040. return 0;
  10041. }
  10042. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10043. if (!lua_interface)
  10044. return 0;
  10045. Client* client = 0;
  10046. Spawn* player = lua_interface->GetSpawn(state);
  10047. string window = lua_interface->GetStringValue(state, 2);
  10048. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10049. lua_interface->ResetFunctionStack(state);
  10050. if (!player) {
  10051. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10052. return 0;
  10053. }
  10054. if (!player->IsPlayer()) {
  10055. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10056. return 0;
  10057. }
  10058. else
  10059. client = ((Player*)player)->GetClient();
  10060. if (!client) {
  10061. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10062. return 0;
  10063. }
  10064. if (window.length() == 0) {
  10065. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10066. return 0;
  10067. }
  10068. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10069. if (packet) {
  10070. packet->setDataByName("window", window.c_str());
  10071. packet->setDataByName("flash_seconds", flash_seconds);
  10072. client->QueuePacket(packet->serialize());
  10073. safe_delete(packet);
  10074. }
  10075. return 0;
  10076. }
  10077. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10078. if (!lua_interface)
  10079. return 0;
  10080. Spawn* spawn = lua_interface->GetSpawn(state);
  10081. Spawn* target = lua_interface->GetSpawn(state, 2);
  10082. lua_interface->ResetFunctionStack(state);
  10083. if (spawn && target)
  10084. return spawn->CheckLoS(target);
  10085. return 0;
  10086. }
  10087. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10088. if (!lua_interface)
  10089. return 0;
  10090. Spawn* spawn = lua_interface->GetSpawn(state);
  10091. float x = lua_interface->GetFloatValue(state, 2);
  10092. float y = lua_interface->GetFloatValue(state, 3);
  10093. float z = lua_interface->GetFloatValue(state, 4);
  10094. lua_interface->ResetFunctionStack(state);
  10095. if (spawn)
  10096. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10097. return 0;
  10098. }
  10099. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10100. if (!lua_interface)
  10101. return 0;
  10102. ZoneServer* zone = lua_interface->GetZone(state);
  10103. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10104. lua_interface->ResetFunctionStack(state);
  10105. if (zone)
  10106. zone->SetExpansionFlag(xpackFlag);
  10107. return 0;
  10108. }
  10109. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10110. if (!lua_interface)
  10111. return 0;
  10112. ZoneServer* zone = lua_interface->GetZone(state);
  10113. lua_interface->ResetFunctionStack(state);
  10114. if (zone) {
  10115. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10116. return 1;
  10117. }
  10118. return 0;
  10119. }
  10120. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. ZoneServer* zone = lua_interface->GetZone(state);
  10124. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10125. lua_interface->ResetFunctionStack(state);
  10126. if (zone)
  10127. zone->SetHolidayFlag(holidayFlag);
  10128. return 0;
  10129. }
  10130. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10131. if (!lua_interface)
  10132. return 0;
  10133. ZoneServer* zone = lua_interface->GetZone(state);
  10134. lua_interface->ResetFunctionStack(state);
  10135. if (zone) {
  10136. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10137. return 1;
  10138. }
  10139. return 0;
  10140. }
  10141. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10142. if (!lua_interface)
  10143. return 0;
  10144. Spawn* player = lua_interface->GetSpawn(state);
  10145. ZoneServer* zone = player->GetZone();
  10146. bool canbind = lua_interface->GetInt32Value(state, 2);
  10147. lua_interface->ResetFunctionStack(state);
  10148. if (zone)
  10149. zone->SetCanBind(canbind);
  10150. return 0;
  10151. }
  10152. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10153. if (!lua_interface)
  10154. return 0;
  10155. Spawn* player = lua_interface->GetSpawn(state);
  10156. ZoneServer* zone = player->GetZone();
  10157. lua_interface->ResetFunctionStack(state);
  10158. if (zone) {
  10159. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10160. return 1;
  10161. }
  10162. return 0;
  10163. }
  10164. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10165. if (!lua_interface)
  10166. return 0;
  10167. Spawn* player = lua_interface->GetSpawn(state);
  10168. ZoneServer* zone = player->GetZone();
  10169. bool cangate = lua_interface->GetInt32Value(state, 2);
  10170. lua_interface->ResetFunctionStack(state);
  10171. if (zone)
  10172. zone->SetCanGate(cangate);
  10173. return 0;
  10174. }
  10175. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10176. if (!lua_interface)
  10177. return 0;
  10178. Spawn* player = lua_interface->GetSpawn(state);
  10179. ZoneServer* zone = player->GetZone();
  10180. lua_interface->ResetFunctionStack(state);
  10181. if (zone) {
  10182. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10183. return 1;
  10184. }
  10185. return 0;
  10186. }
  10187. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10188. if (!lua_interface)
  10189. return 0;
  10190. Spawn* spawn = lua_interface->GetSpawn(state);
  10191. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10192. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10193. float distance = lua_interface->GetFloatValue(state, 4);
  10194. string in_range_function = lua_interface->GetStringValue(state, 5);
  10195. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10196. lua_interface->ResetFunctionStack(state);
  10197. if (spawn && distance > 0 && in_range_function.length() > 0)
  10198. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10199. return 0;
  10200. }
  10201. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10202. if (!lua_interface)
  10203. return 0;
  10204. Spawn* spawn = lua_interface->GetSpawn(state);
  10205. Spawn* target = lua_interface->GetSpawn(state, 2);
  10206. lua_interface->ResetFunctionStack(state);
  10207. if (spawn && target)
  10208. {
  10209. if (spawn->IsPlayer() && target->IsEntity())
  10210. {
  10211. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10212. return 1;
  10213. }
  10214. else if (spawn->IsEntity() && target->IsEntity())
  10215. {
  10216. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10217. return 1;
  10218. }
  10219. }
  10220. return 0;
  10221. }
  10222. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10223. if (!lua_interface)
  10224. return 0;
  10225. Spawn* spawn = lua_interface->GetSpawn(state);
  10226. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10227. lua_interface->ResetFunctionStack(state);
  10228. if (spawn && spawn->IsEntity())
  10229. {
  10230. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10231. if (spawn->IsPlayer())
  10232. {
  10233. Client* client = ((Player*)spawn)->GetClient();
  10234. if (client)
  10235. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10236. }
  10237. }
  10238. return 0;
  10239. }
  10240. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10241. if (!lua_interface)
  10242. return 0;
  10243. Spawn* spawn = lua_interface->GetSpawn(state);
  10244. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10245. lua_interface->ResetFunctionStack(state);
  10246. if (spawn && spawn->IsEntity())
  10247. {
  10248. ((Entity*)spawn)->SetSeeHideSpell(val);
  10249. if (spawn->IsPlayer())
  10250. {
  10251. Client* client = ((Player*)spawn)->GetClient();
  10252. if (client)
  10253. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10254. }
  10255. }
  10256. return 0;
  10257. }
  10258. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10259. {
  10260. if (!lua_interface)
  10261. return 0;
  10262. Spawn* player = lua_interface->GetSpawn(state);
  10263. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10264. string command = lua_interface->GetStringValue(state, 3);
  10265. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10266. lua_interface->ResetFunctionStack(state);
  10267. if (spawn && player && player->IsPlayer())
  10268. {
  10269. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10270. bool res = false;
  10271. if (cmd)
  10272. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10273. lua_interface->SetBooleanValue(state, res);
  10274. return 1;
  10275. }
  10276. return 0;
  10277. }
  10278. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10279. {
  10280. if (!lua_interface)
  10281. return 0;
  10282. Spawn* spawn = lua_interface->GetSpawn(state);
  10283. int32 charID = lua_interface->GetInt32Value(state, 2);
  10284. string command = lua_interface->GetStringValue(state, 3);
  10285. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10286. lua_interface->ResetFunctionStack(state);
  10287. if (spawn && charID)
  10288. {
  10289. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10290. bool res = false;
  10291. if (cmd)
  10292. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10293. lua_interface->SetBooleanValue(state, res);
  10294. return 1;
  10295. }
  10296. return 0;
  10297. }
  10298. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10299. {
  10300. if (!lua_interface)
  10301. return 0;
  10302. Spawn* spawn = lua_interface->GetSpawn(state);
  10303. string command = lua_interface->GetStringValue(state, 2);
  10304. lua_interface->ResetFunctionStack(state);
  10305. if (spawn && command.length() > 0)
  10306. spawn->RemovePrimaryEntityCommand(command.c_str());
  10307. return 0;
  10308. }
  10309. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10310. if (!lua_interface)
  10311. return 0;
  10312. Spawn* spawn = lua_interface->GetSpawn(state);
  10313. float distance = lua_interface->GetFloatValue(state, 2);
  10314. string command = lua_interface->GetStringValue(state, 3);
  10315. Spawn* player = lua_interface->GetSpawn(state, 4);
  10316. lua_interface->ResetFunctionStack(state);
  10317. if (spawn) {
  10318. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10319. }
  10320. return 0;
  10321. }
  10322. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10323. if (!lua_interface)
  10324. return 0;
  10325. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10326. Spawn* spawn = lua_interface->GetSpawn(state);
  10327. Spawn* player = lua_interface->GetSpawn(state, 2);
  10328. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10329. lua_interface->ResetFunctionStack(state);
  10330. if (spawn && player && transport_id && player->IsPlayer()) {
  10331. Client* client = 0;
  10332. if (player && player->IsPlayer())
  10333. client = ((Player*)player)->GetClient();
  10334. if (!client)
  10335. return 0;
  10336. vector<TransportDestination*> destinations;
  10337. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10338. if (destinations.size())
  10339. {
  10340. client->SetTemporaryTransportID(transport_id);
  10341. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10342. }
  10343. else
  10344. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10345. }
  10346. return 0;
  10347. }
  10348. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10349. if (!lua_interface)
  10350. return 0;
  10351. Spawn* player = lua_interface->GetSpawn(state);
  10352. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10353. lua_interface->ResetFunctionStack(state);
  10354. if (player && player->IsPlayer()) {
  10355. Client* client = 0;
  10356. if (player && player->IsPlayer())
  10357. client = ((Player*)player)->GetClient();
  10358. if (!client)
  10359. return 0;
  10360. client->SetTemporaryTransportID(transport_id);
  10361. }
  10362. return 0;
  10363. }
  10364. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10365. if (!lua_interface)
  10366. return 0;
  10367. Spawn* player = lua_interface->GetSpawn(state);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if (player && player->IsPlayer()) {
  10370. Client* client = 0;
  10371. if (player && player->IsPlayer())
  10372. client = ((Player*)player)->GetClient();
  10373. if (!client)
  10374. return 0;
  10375. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10376. return 1;
  10377. }
  10378. return 0;
  10379. }
  10380. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10381. if (!lua_interface)
  10382. return 0;
  10383. Spawn* spawn = lua_interface->GetSpawn(state);
  10384. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10385. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10386. if (!spawn) {
  10387. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10388. return 0;
  10389. }
  10390. if (!spawn->IsEntity()) {
  10391. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10392. return 0;
  10393. }
  10394. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10395. {
  10396. 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);
  10397. return 0;
  10398. }
  10399. lua_interface->ResetFunctionStack(state);
  10400. if (spell && spell->targets.size() > 0) {
  10401. ZoneServer* zone = spell->caster->GetZone();
  10402. for (int8 i = 0; i < spell->targets.size(); i++) {
  10403. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10404. if (target && target->IsEntity()) {
  10405. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10406. if (target->IsPlayer())
  10407. ((Player*)target)->SetCharSheetChanged(true);
  10408. }
  10409. }
  10410. }
  10411. else {
  10412. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10413. if (spawn->IsPlayer())
  10414. ((Player*)spawn)->SetCharSheetChanged(true);
  10415. }
  10416. return 0;
  10417. }
  10418. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10419. if (!lua_interface)
  10420. return 0;
  10421. Spawn* spawn = lua_interface->GetSpawn(state);
  10422. lua_interface->ResetFunctionStack(state);
  10423. if (!spawn) {
  10424. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10425. return 0;
  10426. }
  10427. if (!spawn->IsEntity()) {
  10428. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10429. return 0;
  10430. }
  10431. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10432. return 1;
  10433. }
  10434. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10435. if (!lua_interface)
  10436. return 0;
  10437. int32 spell_id = lua_interface->GetInt32Value(state);
  10438. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10439. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10440. if (spell_id > 0) {
  10441. if (spell_tier == 0)
  10442. spell_tier = 1;
  10443. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10444. LuaSpell* lua_spell = 0;
  10445. if(custom_lua_script.size() > 0)
  10446. {
  10447. // attempt to load the custom script since it isn't already loaded
  10448. // we will re-obtain the lua_spell further below
  10449. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10450. {
  10451. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  10452. lua_interface->LoadLuaSpell(custom_lua_script);
  10453. }
  10454. }
  10455. else
  10456. custom_lua_script = spell->GetSpellData()->lua_script;
  10457. if (!lua_spell && lua_interface)
  10458. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10459. if (!lua_spell)
  10460. {
  10461. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10462. return 0;
  10463. }
  10464. lua_spell->spell = new Spell(spell);
  10465. lua_interface->AddCustomSpell(lua_spell);
  10466. lua_interface->SetSpellValue(state, lua_spell);
  10467. return 1;
  10468. }
  10469. return 0;
  10470. }
  10471. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10472. if (!lua_interface)
  10473. return 0;
  10474. LuaSpell* spell = lua_interface->GetSpell(state);
  10475. string field = lua_interface->GetStringValue(state, 2);
  10476. if (!spell) {
  10477. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10478. return 0;
  10479. }
  10480. if (!spell->spell || !spell->spell->GetSpellData()) {
  10481. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10482. return 0;
  10483. }
  10484. boost::to_lower(field);
  10485. return spell->spell->GetSpellData(state, field);
  10486. }
  10487. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10488. if (!lua_interface)
  10489. return 0;
  10490. LuaSpell* spell = lua_interface->GetSpell(state);
  10491. string field = lua_interface->GetStringValue(state, 2);
  10492. int8 fieldArg = 3; // field value after the initial set
  10493. if (!spell) {
  10494. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10495. return 0;
  10496. }
  10497. if (!spell->spell || !spell->spell->GetSpellData()) {
  10498. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10499. return 0;
  10500. }
  10501. boost::to_lower(field);
  10502. bool valSet = false;
  10503. spell->spell->SetSpellData(state, field, fieldArg);
  10504. return valSet;
  10505. }
  10506. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10507. if (!lua_interface)
  10508. return 0;
  10509. LuaSpell* spell = lua_interface->GetSpell(state);
  10510. int8 idx = lua_interface->GetInt32Value(state, 2);
  10511. if (!spell) {
  10512. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10513. return 0;
  10514. }
  10515. if (!spell->spell || !spell->spell->GetSpellData()) {
  10516. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10517. return 0;
  10518. }
  10519. if (spell->spell->lua_data.size() <= idx)
  10520. {
  10521. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10522. return 0;
  10523. }
  10524. bool setVal = true;
  10525. LUAData* data = spell->spell->lua_data[idx];
  10526. switch (data->type)
  10527. {
  10528. case 0:
  10529. {
  10530. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10531. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10532. data->int_value = value;
  10533. data->int_value2 = value2;
  10534. break;
  10535. }
  10536. case 1:
  10537. {
  10538. float value = lua_interface->GetFloatValue(state, 3);
  10539. float value2 = lua_interface->GetFloatValue(state, 4);
  10540. data->float_value = value;
  10541. data->float_value2 = value2;
  10542. break;
  10543. }
  10544. case 2:
  10545. {
  10546. bool value = lua_interface->GetBooleanValue(state, 3);
  10547. data->bool_value = value;
  10548. break;
  10549. }
  10550. case 3:
  10551. {
  10552. string value = lua_interface->GetStringValue(state, 3);
  10553. string value2 = lua_interface->GetStringValue(state, 4);
  10554. data->string_value = value;
  10555. data->string_value2 = value2;
  10556. break;
  10557. }
  10558. default:
  10559. setVal = false;
  10560. }
  10561. return setVal;
  10562. }
  10563. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10564. if (!lua_interface)
  10565. return 0;
  10566. LuaSpell* spell = lua_interface->GetSpell(state);
  10567. int8 idx = lua_interface->GetInt32Value(state, 2);
  10568. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10569. if (!spell) {
  10570. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10571. return 0;
  10572. }
  10573. if (!spell->spell || !spell->spell->GetSpellData()) {
  10574. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10575. return 0;
  10576. }
  10577. if (spell->spell->lua_data.size() <= idx)
  10578. {
  10579. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10580. return 0;
  10581. }
  10582. bool setVal = true;
  10583. LUAData* data = spell->spell->lua_data[idx];
  10584. switch (data->type)
  10585. {
  10586. case 0:
  10587. {
  10588. if(!secondfield)
  10589. lua_interface->SetSInt32Value(state, data->int_value);
  10590. else
  10591. lua_interface->SetSInt32Value(state, data->int_value2);
  10592. break;
  10593. }
  10594. case 1:
  10595. {
  10596. if (!secondfield)
  10597. lua_interface->SetFloatValue(state, data->float_value);
  10598. else
  10599. lua_interface->SetFloatValue(state, data->float_value2);
  10600. break;
  10601. }
  10602. case 2:
  10603. {
  10604. lua_interface->SetBooleanValue(state, data->bool_value);
  10605. break;
  10606. }
  10607. case 3:
  10608. {
  10609. if (!secondfield)
  10610. lua_interface->SetStringValue(state, data->string_value.c_str());
  10611. else
  10612. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10613. break;
  10614. }
  10615. default:
  10616. setVal = false;
  10617. }
  10618. return setVal;
  10619. }
  10620. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10621. if (!lua_interface)
  10622. return 0;
  10623. LuaSpell* spell = lua_interface->GetSpell(state);
  10624. int8 idx = lua_interface->GetInt32Value(state, 2);
  10625. string field = lua_interface->GetStringValue(state, 3);
  10626. boost::to_lower(field);
  10627. if (!spell) {
  10628. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10629. return 0;
  10630. }
  10631. if (!spell->spell || !spell->spell->GetSpellData()) {
  10632. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10633. return 0;
  10634. }
  10635. if (spell->spell->effects.size() <= idx)
  10636. {
  10637. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10638. return 0;
  10639. }
  10640. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10641. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10642. if (field == "description")
  10643. effect->description = string(lua_interface->GetStringValue(state, 4));
  10644. else if (field == "bullet")
  10645. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10646. else if (field == "percentage")
  10647. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10648. else // no match
  10649. return 0;
  10650. return 1;
  10651. }
  10652. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10653. if (!lua_interface)
  10654. return 0;
  10655. LuaSpell* spell = lua_interface->GetSpell(state);
  10656. int8 idx = lua_interface->GetInt32Value(state, 2);
  10657. string field = lua_interface->GetStringValue(state, 3);
  10658. boost::to_lower(field);
  10659. if (!spell) {
  10660. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10661. return 0;
  10662. }
  10663. if (!spell->spell || !spell->spell->GetSpellData()) {
  10664. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10665. return 0;
  10666. }
  10667. if (spell->spell->effects.size() <= idx)
  10668. {
  10669. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10670. return 0;
  10671. }
  10672. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10673. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10674. if (field == "description")
  10675. lua_interface->SetStringValue(state, effect->description.c_str());
  10676. else if (field == "bullet")
  10677. lua_interface->SetInt32Value(state, effect->subbullet);
  10678. else if (field == "percentage")
  10679. lua_interface->SetInt32Value(state, effect->percentage);
  10680. else // no match
  10681. return 0;
  10682. return 1;
  10683. }
  10684. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10685. if (!lua_interface)
  10686. return 0;
  10687. LuaSpell* spell = lua_interface->GetSpell(state);
  10688. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10689. Spawn* target = lua_interface->GetSpawn(state, 3);
  10690. if (!target) {
  10691. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10692. return 0;
  10693. }
  10694. if (!target->IsEntity()) {
  10695. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10696. return 0;
  10697. }
  10698. if (!spell) {
  10699. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10700. return 0;
  10701. }
  10702. if (caster && !caster->IsEntity()) {
  10703. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10704. return 0;
  10705. }
  10706. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10707. return 0;
  10708. }
  10709. int EQ2Emu_lua_InWater(lua_State* state) {
  10710. if (!lua_interface)
  10711. return 0;
  10712. Spawn* spawn = lua_interface->GetSpawn(state);
  10713. lua_interface->ResetFunctionStack(state);
  10714. if (spawn) {
  10715. lua_interface->SetBooleanValue(state, spawn->InWater());
  10716. return 1;
  10717. }
  10718. return 0;
  10719. }
  10720. int EQ2Emu_lua_InLava(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. Spawn* spawn = lua_interface->GetSpawn(state);
  10724. lua_interface->ResetFunctionStack(state);
  10725. if (spawn) {
  10726. lua_interface->SetBooleanValue(state, spawn->InLava());
  10727. return 1;
  10728. }
  10729. return 0;
  10730. }
  10731. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10732. if (!lua_interface)
  10733. return 0;
  10734. Spawn* attacker = lua_interface->GetSpawn(state);
  10735. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10736. int8 type = lua_interface->GetInt8Value(state, 3);
  10737. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10738. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10739. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10740. string spell_name = lua_interface->GetStringValue(state, 7);
  10741. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10742. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10743. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10744. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10745. lua_interface->ResetFunctionStack(state);
  10746. if (!attacker) {
  10747. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10748. return 0;
  10749. }
  10750. if (!attacker->IsEntity()) {
  10751. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10752. return 0;
  10753. }
  10754. if (!victim) {
  10755. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10756. return 0;
  10757. }
  10758. if (!victim->IsEntity()) {
  10759. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10760. return 0;
  10761. }
  10762. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10763. return 0;
  10764. }
  10765. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10766. if (!lua_interface)
  10767. return 0;
  10768. Spawn* spawn = lua_interface->GetSpawn(state);
  10769. lua_interface->ResetFunctionStack(state);
  10770. if (spawn) {
  10771. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10772. return 1;
  10773. }
  10774. return 0;
  10775. }
  10776. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10777. if (!lua_interface)
  10778. return 0;
  10779. Spawn* spawn = lua_interface->GetSpawn(state);
  10780. bool invul = lua_interface->GetBooleanValue(state, 2);
  10781. lua_interface->ResetFunctionStack(state);
  10782. if (spawn) {
  10783. spawn->SetInvulnerable(invul);
  10784. }
  10785. return 0;
  10786. }
  10787. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10788. if (!lua_interface)
  10789. return 0;
  10790. string category = lua_interface->GetStringValue(state);
  10791. string name = lua_interface->GetStringValue(state, 2);
  10792. lua_interface->ResetFunctionStack(state);
  10793. Rule *ret = 0;
  10794. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10795. lua_interface->SetBooleanValue(state, ret->GetBool());
  10796. return 1;
  10797. }
  10798. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10799. return 0;
  10800. }
  10801. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10802. if (!lua_interface)
  10803. return 0;
  10804. string category = lua_interface->GetStringValue(state);
  10805. string name = lua_interface->GetStringValue(state, 2);
  10806. lua_interface->ResetFunctionStack(state);
  10807. Rule *ret = 0;
  10808. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10809. lua_interface->SetInt32Value(state, ret->GetInt32());
  10810. return 1;
  10811. }
  10812. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10813. return 0;
  10814. }
  10815. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10816. if (!lua_interface)
  10817. return 0;
  10818. string category = lua_interface->GetStringValue(state);
  10819. string name = lua_interface->GetStringValue(state, 2);
  10820. lua_interface->ResetFunctionStack(state);
  10821. Rule *ret = 0;
  10822. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10823. lua_interface->SetFloatValue(state, ret->GetFloat());
  10824. return 1;
  10825. }
  10826. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10827. return 0;
  10828. }
  10829. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10830. if (!lua_interface)
  10831. return 0;
  10832. Spawn* spawn = lua_interface->GetSpawn(state);
  10833. string type = lua_interface->GetStringValue(state, 2);
  10834. lua_interface->ResetFunctionStack(state);
  10835. if (spawn) {
  10836. int res = 1;
  10837. boost::to_lower(type);
  10838. if(type == "assigned_aa")
  10839. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10840. else if ( type == "unassigned_aa")
  10841. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10842. else if ( type == "assigned_tradeskill_aa")
  10843. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10844. else if ( type == "unassigned_tradeskill_aa")
  10845. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10846. else if ( type == "assigned_prestige_aa")
  10847. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10848. else if ( type == "unassigned_prestige_aa")
  10849. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10850. else if ( type == "assigned_tradeskill_prestige_aa")
  10851. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10852. else if ( type == "unassigned_tradeskill_prestige_aa")
  10853. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10854. else
  10855. res = 0;
  10856. return res;
  10857. }
  10858. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10859. return 0;
  10860. }
  10861. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10862. if (!lua_interface)
  10863. return 0;
  10864. Spawn* spawn = lua_interface->GetSpawn(state);
  10865. string type = lua_interface->GetStringValue(state, 2);
  10866. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10867. lua_interface->ResetFunctionStack(state);
  10868. if (spawn) {
  10869. boost::to_lower(type);
  10870. if(type == "assigned_aa")
  10871. spawn->SetAssignedAA((sint16)value);
  10872. else if ( type == "unassigned_aa")
  10873. spawn->SetUnassignedAA((sint16)value);
  10874. else if ( type == "assigned_tradeskill_aa")
  10875. spawn->SetTradeskillAA((sint16)value);
  10876. else if ( type == "unassigned_tradeskill_aa")
  10877. spawn->SetUnassignedTradeskillAA((sint16)value);
  10878. else if ( type == "assigned_prestige_aa")
  10879. spawn->SetPrestigeAA((sint16)value);
  10880. else if ( type == "unassigned_prestige_aa")
  10881. spawn->SetUnassignedPrestigeAA((sint16)value);
  10882. else if ( type == "assigned_tradeskill_prestige_aa")
  10883. spawn->SetTradeskillPrestigeAA((sint16)value);
  10884. else if ( type == "unassigned_tradeskill_prestige_aa")
  10885. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10886. if(spawn->IsPlayer())
  10887. ((Player*)spawn)->SetCharSheetChanged(true);
  10888. }
  10889. return 0;
  10890. }
  10891. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10892. if (!lua_interface)
  10893. return 0;
  10894. string titleName = lua_interface->GetStringValue(state);
  10895. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10896. lua_interface->ResetFunctionStack(state);
  10897. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10898. lua_interface->SetSInt32Value(state, index);
  10899. return 1;
  10900. }
  10901. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10902. if (!lua_interface)
  10903. return 0;
  10904. Spawn* spawn = lua_interface->GetSpawn(state);
  10905. string titleName = lua_interface->GetStringValue(state, 2);
  10906. lua_interface->ResetFunctionStack(state);
  10907. if(!spawn->IsPlayer())
  10908. {
  10909. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10910. lua_interface->SetSInt32Value(state, -1);
  10911. return 1;
  10912. }
  10913. Player* player = (Player*)spawn;
  10914. // check if player already has the title, don't need to add twice
  10915. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10916. if ( playerHasTitle)
  10917. {
  10918. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10919. return 1;
  10920. }
  10921. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10922. if(!title)
  10923. {
  10924. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10925. lua_interface->SetSInt32Value(state, -1);
  10926. return 1;
  10927. }
  10928. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10929. if(returnIdx < 0)
  10930. {
  10931. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10932. }
  10933. lua_interface->SetSInt32Value(state, returnIdx);
  10934. player->GetClient()->SendTitleUpdate();
  10935. return 1;
  10936. }
  10937. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10938. if (!lua_interface)
  10939. return 0;
  10940. Spawn* spawn = lua_interface->GetSpawn(state);
  10941. string titleName = lua_interface->GetStringValue(state, 2);
  10942. lua_interface->ResetFunctionStack(state);
  10943. if(!spawn->IsPlayer())
  10944. {
  10945. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10946. return 0;
  10947. }
  10948. Player* player = (Player*)spawn;
  10949. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10950. if(!title)
  10951. {
  10952. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10953. return 0;
  10954. }
  10955. if(title->GetPrefix())
  10956. {
  10957. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  10958. return 0;
  10959. }
  10960. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10961. player->GetClient()->SendTitleUpdate();
  10962. return 1;
  10963. }
  10964. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10965. if (!lua_interface)
  10966. return 0;
  10967. Spawn* spawn = lua_interface->GetSpawn(state);
  10968. string titleName = lua_interface->GetStringValue(state, 2);
  10969. lua_interface->ResetFunctionStack(state);
  10970. if(!spawn->IsPlayer())
  10971. {
  10972. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10973. return 0;
  10974. }
  10975. Player* player = (Player*)spawn;
  10976. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10977. if(!title)
  10978. {
  10979. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10980. return 0;
  10981. }
  10982. if(!title->GetPrefix())
  10983. {
  10984. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  10985. return 0;
  10986. }
  10987. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10988. player->GetClient()->SendTitleUpdate();
  10989. return 1;
  10990. }
  10991. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10992. if (!lua_interface)
  10993. return 0;
  10994. Spawn* spawn = lua_interface->GetSpawn(state);
  10995. lua_interface->ResetFunctionStack(state);
  10996. if(!spawn->IsPlayer())
  10997. {
  10998. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10999. return 0;
  11000. }
  11001. Player* player = (Player*)spawn;
  11002. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11003. player->GetClient()->SendTitleUpdate();
  11004. return 1;
  11005. }
  11006. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11007. if (!lua_interface)
  11008. return 0;
  11009. Spawn* spawn = lua_interface->GetSpawn(state);
  11010. lua_interface->ResetFunctionStack(state);
  11011. if(!spawn->IsPlayer())
  11012. {
  11013. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11014. return 0;
  11015. }
  11016. Player* player = (Player*)spawn;
  11017. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11018. player->GetClient()->SendTitleUpdate();
  11019. return 1;
  11020. }
  11021. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11022. if (!lua_interface)
  11023. return 0;
  11024. Spawn* spawn = lua_interface->GetSpawn(state);
  11025. string field = lua_interface->GetStringValue(state, 2);
  11026. lua_interface->ResetFunctionStack(state);
  11027. if(!spawn || !spawn->IsEntity())
  11028. {
  11029. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11030. return 0;
  11031. }
  11032. Entity* ent = (Entity*)spawn;
  11033. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11034. return 1;
  11035. }
  11036. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11037. if (!lua_interface)
  11038. return 0;
  11039. Spawn* spawn = lua_interface->GetSpawn(state);
  11040. string field = lua_interface->GetStringValue(state, 2);
  11041. lua_interface->ResetFunctionStack(state);
  11042. if(!spawn || !spawn->IsEntity())
  11043. {
  11044. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11045. return 0;
  11046. }
  11047. Entity* ent = (Entity*)spawn;
  11048. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11049. return 1;
  11050. }
  11051. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11052. if (!lua_interface)
  11053. return 0;
  11054. Spawn* spawn = lua_interface->GetSpawn(state);
  11055. string field = lua_interface->GetStringValue(state, 2);
  11056. lua_interface->ResetFunctionStack(state);
  11057. if(!spawn || !spawn->IsEntity())
  11058. {
  11059. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11060. return 0;
  11061. }
  11062. Entity* ent = (Entity*)spawn;
  11063. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11064. return 1;
  11065. }
  11066. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11067. if (!lua_interface)
  11068. return 0;
  11069. Spawn* spawn = lua_interface->GetSpawn(state);
  11070. string field = lua_interface->GetStringValue(state, 2);
  11071. lua_interface->ResetFunctionStack(state);
  11072. if(!spawn || !spawn->IsEntity())
  11073. {
  11074. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11075. return 0;
  11076. }
  11077. Entity* ent = (Entity*)spawn;
  11078. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11079. return 1;
  11080. }
  11081. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11082. if (!lua_interface)
  11083. return 0;
  11084. Spawn* spawn = lua_interface->GetSpawn(state);
  11085. string field = lua_interface->GetStringValue(state, 2);
  11086. string value = lua_interface->GetStringValue(state, 3);
  11087. lua_interface->ResetFunctionStack(state);
  11088. if(!spawn || !spawn->IsEntity())
  11089. {
  11090. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11091. return 0;
  11092. }
  11093. Entity* ent = (Entity*)spawn;
  11094. bool set_ = ent->SetInfoStructString(field, value);
  11095. lua_interface->SetBooleanValue(state, set_);
  11096. return 1;
  11097. }
  11098. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11099. if (!lua_interface)
  11100. return 0;
  11101. Spawn* spawn = lua_interface->GetSpawn(state);
  11102. string field = lua_interface->GetStringValue(state, 2);
  11103. int64 value = lua_interface->GetInt64Value(state, 3);
  11104. lua_interface->ResetFunctionStack(state);
  11105. if(!spawn || !spawn->IsEntity())
  11106. {
  11107. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11108. return 0;
  11109. }
  11110. Entity* ent = (Entity*)spawn;
  11111. bool set_ = ent->SetInfoStructUInt(field, value);
  11112. lua_interface->SetBooleanValue(state, set_);
  11113. return 1;
  11114. }
  11115. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11116. if (!lua_interface)
  11117. return 0;
  11118. Spawn* spawn = lua_interface->GetSpawn(state);
  11119. string field = lua_interface->GetStringValue(state, 2);
  11120. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11121. lua_interface->ResetFunctionStack(state);
  11122. if(!spawn || !spawn->IsEntity())
  11123. {
  11124. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11125. return 0;
  11126. }
  11127. Entity* ent = (Entity*)spawn;
  11128. bool set_ = ent->SetInfoStructSInt(field, value);
  11129. lua_interface->SetBooleanValue(state, set_);
  11130. return 1;
  11131. }
  11132. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11133. if (!lua_interface)
  11134. return 0;
  11135. Spawn* spawn = lua_interface->GetSpawn(state);
  11136. string field = lua_interface->GetStringValue(state, 2);
  11137. float value = lua_interface->GetFloatValue(state, 3);
  11138. lua_interface->ResetFunctionStack(state);
  11139. if(!spawn || !spawn->IsEntity())
  11140. {
  11141. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11142. return 0;
  11143. }
  11144. Entity* ent = (Entity*)spawn;
  11145. bool set_ = ent->SetInfoStructFloat(field, value);
  11146. lua_interface->SetBooleanValue(state, set_);
  11147. return 1;
  11148. }
  11149. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11150. if (!lua_interface)
  11151. return 0;
  11152. Spawn* spawn = lua_interface->GetSpawn(state);
  11153. bool value = lua_interface->GetBooleanValue(state, 2);
  11154. lua_interface->ResetFunctionStack(state);
  11155. if(!spawn || !spawn->IsPlayer())
  11156. {
  11157. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11158. return 0;
  11159. }
  11160. ((Player*)spawn)->SetCharSheetChanged(value);
  11161. return 0;
  11162. }
  11163. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11164. if (!lua_interface)
  11165. return 0;
  11166. Spawn* spawn = lua_interface->GetSpawn(state);
  11167. std::string fromName = lua_interface->GetStringValue(state, 2);
  11168. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11169. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11170. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11171. int32 copper = lua_interface->GetInt32Value(state, 6);
  11172. int32 silver = lua_interface->GetInt32Value(state, 7);
  11173. int32 gold = lua_interface->GetInt32Value(state, 8);
  11174. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11175. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11176. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11177. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11178. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11179. lua_interface->ResetFunctionStack(state);
  11180. if(!spawn || !spawn->IsPlayer())
  11181. {
  11182. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11183. lua_interface->SetBooleanValue(state, false);
  11184. return 1;
  11185. }
  11186. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11187. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11188. lua_interface->SetBooleanValue(state, true);
  11189. return 1;
  11190. }
  11191. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11192. if (!lua_interface)
  11193. return 0;
  11194. int32 char_id = lua_interface->GetInt32Value(state);
  11195. std::string fromName = lua_interface->GetStringValue(state, 2);
  11196. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11197. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11198. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11199. int32 copper = lua_interface->GetInt32Value(state, 6);
  11200. int32 silver = lua_interface->GetInt32Value(state, 7);
  11201. int32 gold = lua_interface->GetInt32Value(state, 8);
  11202. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11203. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11204. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11205. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11206. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11207. lua_interface->ResetFunctionStack(state);
  11208. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11209. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11210. lua_interface->SetBooleanValue(state, true);
  11211. return 1;
  11212. }
  11213. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11214. Spawn* widget;
  11215. if (lua_interface) {
  11216. widget = lua_interface->GetSpawn(state);
  11217. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11218. lua_interface->ResetFunctionStack(state);
  11219. if (widget && widget->IsWidget())
  11220. {
  11221. ((Widget*)widget)->OpenDoor();
  11222. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11223. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11224. }
  11225. else
  11226. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11227. }
  11228. return 0;
  11229. }
  11230. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11231. Spawn* widget;
  11232. if (lua_interface) {
  11233. widget = lua_interface->GetSpawn(state);
  11234. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11235. lua_interface->ResetFunctionStack(state);
  11236. if (widget && widget->IsWidget())
  11237. {
  11238. ((Widget*)widget)->CloseDoor();
  11239. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11240. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11241. }
  11242. else
  11243. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11244. }
  11245. return 0;
  11246. }
  11247. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11248. if (!lua_interface)
  11249. return 0;
  11250. Spawn* widget = lua_interface->GetSpawn(state);
  11251. lua_interface->ResetFunctionStack(state);
  11252. if (widget && widget->IsWidget())
  11253. {
  11254. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11255. return 1;
  11256. }
  11257. return 0;
  11258. }
  11259. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11260. if (!lua_interface)
  11261. return 0;
  11262. sint32 min = lua_interface->GetSInt32Value(state);
  11263. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11264. lua_interface->ResetFunctionStack(state);
  11265. sint32 result = MakeRandomInt(min, max);
  11266. lua_interface->SetSInt32Value(state, result);
  11267. return 1;
  11268. }
  11269. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11270. if (!lua_interface)
  11271. return 0;
  11272. float min = lua_interface->GetFloatValue(state);
  11273. float max = lua_interface->GetFloatValue(state, 2);
  11274. lua_interface->ResetFunctionStack(state);
  11275. float result = MakeRandomFloat(min, max);
  11276. lua_interface->SetFloatValue(state, result);
  11277. return 1;
  11278. }
  11279. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11280. if (!lua_interface)
  11281. return 0;
  11282. Spawn* spawn = lua_interface->GetSpawn(state);
  11283. int32 value = lua_interface->GetInt32Value(state, 2);
  11284. lua_interface->ResetFunctionStack(state);
  11285. if(!spawn)
  11286. {
  11287. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11288. lua_interface->SetBooleanValue(state, false);
  11289. return 1;
  11290. }
  11291. spawn->AddIconValue(value);
  11292. lua_interface->SetBooleanValue(state, true);
  11293. return 1;
  11294. }
  11295. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11296. if (!lua_interface)
  11297. return 0;
  11298. Spawn* spawn = lua_interface->GetSpawn(state);
  11299. int32 value = lua_interface->GetInt32Value(state, 2);
  11300. lua_interface->ResetFunctionStack(state);
  11301. if(!spawn)
  11302. {
  11303. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11304. lua_interface->SetBooleanValue(state, false);
  11305. return 1;
  11306. }
  11307. spawn->RemoveIconValue(value);
  11308. lua_interface->SetBooleanValue(state, true);
  11309. return 1;
  11310. }
  11311. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11312. Spawn* npc = lua_interface->GetSpawn(state);
  11313. lua_interface->ResetFunctionStack(state);
  11314. if (npc && npc->IsNPC()) {
  11315. NPC* shard = (NPC*)npc;
  11316. int32 shardid = shard->GetShardID();
  11317. lua_interface->SetInt32Value(state, shardid);
  11318. return 1;
  11319. }
  11320. lua_interface->SetInt32Value(state, 0);
  11321. return 1;
  11322. }
  11323. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11324. Spawn* npc = lua_interface->GetSpawn(state);
  11325. lua_interface->ResetFunctionStack(state);
  11326. if (npc && npc->IsNPC()) {
  11327. NPC* shard = (NPC*)npc;
  11328. int32 charid = shard->GetShardCharID();
  11329. lua_interface->SetInt32Value(state, charid);
  11330. return 1;
  11331. }
  11332. lua_interface->SetInt32Value(state, 0);
  11333. return 1;
  11334. }
  11335. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11336. Spawn* npc = lua_interface->GetSpawn(state);
  11337. lua_interface->ResetFunctionStack(state);
  11338. if (npc && npc->IsNPC()) {
  11339. NPC* shard = (NPC*)npc;
  11340. int64 timestamp = shard->GetShardCreatedTimestamp();
  11341. lua_interface->SetSInt64Value(state, timestamp);
  11342. return 1;
  11343. }
  11344. lua_interface->SetSInt64Value(state, 0);
  11345. return 1;
  11346. }
  11347. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11348. if (!lua_interface)
  11349. return 0;
  11350. int32 shardid = lua_interface->GetInt32Value(state);
  11351. lua_interface->ResetFunctionStack(state);
  11352. if(shardid < 1)
  11353. lua_interface->SetBooleanValue(state, false);
  11354. else
  11355. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11356. return 1;
  11357. }
  11358. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11359. if (!lua_interface)
  11360. return 0;
  11361. Spawn* spawn = lua_interface->GetSpawn(state);
  11362. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11363. if (spawn) {
  11364. spawn->PauseMovement(delay_in_ms);
  11365. }
  11366. lua_interface->ResetFunctionStack(state);
  11367. return 0;
  11368. }
  11369. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11370. if (!lua_interface)
  11371. return 0;
  11372. Spawn* spawn = lua_interface->GetSpawn(state);
  11373. if (spawn) {
  11374. spawn->StopMovement();
  11375. }
  11376. lua_interface->ResetFunctionStack(state);
  11377. return 0;
  11378. }
  11379. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11380. Player* player = (Player*)lua_interface->GetSpawn(state);
  11381. int8 level = lua_interface->GetInt8Value(state, 2);
  11382. lua_interface->ResetFunctionStack(state);
  11383. if (player && player->IsPlayer() && level > 0) {
  11384. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11385. return 1;
  11386. }
  11387. return 0;
  11388. }
  11389. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11390. Player* player = (Player*)lua_interface->GetSpawn(state);
  11391. int8 level = lua_interface->GetInt8Value(state, 2);
  11392. lua_interface->ResetFunctionStack(state);
  11393. if (player && player->IsPlayer() && level > 0) {
  11394. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11395. return 1;
  11396. }
  11397. return 0;
  11398. }
  11399. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11400. ZoneServer* zone = lua_interface->GetZone(state);
  11401. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11402. lua_interface->ResetFunctionStack(state);
  11403. if (zone) {
  11404. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11405. if (spawn) {
  11406. lua_interface->SetSpawnValue(state, spawn);
  11407. return 1;
  11408. }
  11409. }
  11410. return 0;
  11411. }
  11412. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11413. if (!lua_interface)
  11414. return 0;
  11415. Spawn* spawn = lua_interface->GetSpawn(state);
  11416. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11417. lua_interface->ResetFunctionStack(state);
  11418. bool res = false;
  11419. if(spawn && spawn->IsTransportSpawn())
  11420. {
  11421. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11422. spawn->SetRailID(rail_id);
  11423. res = true;
  11424. }
  11425. else if (!spawn) {
  11426. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11427. }
  11428. else if(!spawn->IsTransportSpawn()) {
  11429. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11430. }
  11431. lua_interface->SetBooleanValue(state, res);
  11432. return 1;
  11433. }
  11434. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11435. if (!lua_interface)
  11436. return 0;
  11437. ZoneServer* zone = lua_interface->GetZone(state);
  11438. lua_interface->ResetFunctionStack(state);
  11439. if (zone) {
  11440. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11441. return 1;
  11442. }
  11443. return 0;
  11444. }
  11445. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11446. if (!lua_interface)
  11447. return 0;
  11448. Spawn* spawn = lua_interface->GetSpawn(state);
  11449. lua_interface->ResetFunctionStack(state);
  11450. if (spawn) {
  11451. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11452. return 1;
  11453. }
  11454. return 0;
  11455. }
  11456. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11457. if (!lua_interface)
  11458. return 0;
  11459. Spawn* player = lua_interface->GetSpawn(state);
  11460. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11461. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11462. lua_interface->ResetFunctionStack(state);
  11463. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11464. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11465. }
  11466. else if(!zoneID) {
  11467. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11468. }
  11469. else
  11470. {
  11471. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11472. return 1;
  11473. }
  11474. return 0;
  11475. }
  11476. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11477. if (!lua_interface)
  11478. return 0;
  11479. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11480. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11481. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11482. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11483. lua_interface->ResetFunctionStack(state);
  11484. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11485. world.GetWorldTimeStruct()->year = newYear;
  11486. world.GetWorldTimeStruct()->month = newMonth;
  11487. world.GetWorldTimeStruct()->hour = newHour;
  11488. world.GetWorldTimeStruct()->minute = newMinute;
  11489. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11490. return 0;
  11491. }
  11492. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11493. if (!lua_interface)
  11494. return 0;
  11495. lua_interface->ResetFunctionStack(state);
  11496. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11497. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11498. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11499. return 1;
  11500. }
  11501. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11502. if (!lua_interface)
  11503. return 0;
  11504. lua_interface->ResetFunctionStack(state);
  11505. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11506. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11507. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11508. return 1;
  11509. }
  11510. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11511. if (!lua_interface)
  11512. return 0;
  11513. lua_interface->ResetFunctionStack(state);
  11514. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11515. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11516. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11517. return 1;
  11518. }
  11519. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11520. if (!lua_interface)
  11521. return 0;
  11522. lua_interface->ResetFunctionStack(state);
  11523. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11524. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11525. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11526. return 1;
  11527. }
  11528. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11529. if (!lua_interface)
  11530. return 0;
  11531. lua_interface->ResetFunctionStack(state);
  11532. world.SendTimeUpdate();
  11533. return 0;
  11534. }
  11535. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11536. bool update_result = false;
  11537. Faction* faction = 0;
  11538. Spawn* spawn = lua_interface->GetSpawn(state);
  11539. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11540. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11541. lua_interface->ResetFunctionStack(state);
  11542. if(!spawn || !spawn->IsPlayer()) {
  11543. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11544. return 0;
  11545. }
  11546. Player* player = (Player*)spawn;
  11547. Client* client = player->GetClient();
  11548. if (faction_id > 0) {
  11549. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11550. if(hasfaction == 0) {
  11551. //they do not have the faction. Lets get the default value and feed it in.
  11552. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11553. //add the default faction for the player.
  11554. player->SetFactionValue(faction_id, defaultfaction);
  11555. }
  11556. if(increase >= 0) {
  11557. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11558. faction = master_faction_list.GetFaction(faction_id);
  11559. if(faction && update_result)
  11560. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11561. else if(faction)
  11562. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11563. lua_interface->SetBooleanValue(state, true);
  11564. return 1;
  11565. }
  11566. if(increase < 0){
  11567. //change the negative to a positive, since thats how decreasefaction() likes it.
  11568. increase *= -1;
  11569. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11570. faction = master_faction_list.GetFaction(faction_id);
  11571. if(faction && update_result)
  11572. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11573. else if(faction)
  11574. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11575. lua_interface->SetBooleanValue(state, true);
  11576. return 1;
  11577. }
  11578. }
  11579. lua_interface->SetBooleanValue(state, false);
  11580. return 1;
  11581. }
  11582. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11583. bool hascoin = 0;
  11584. Player* player = (Player*)lua_interface->GetSpawn(state);
  11585. int32 coins = lua_interface->GetInt32Value(state, 2);
  11586. lua_interface->ResetFunctionStack(state);
  11587. if (player && player->IsPlayer()) {
  11588. hascoin = player->HasCoins(coins);
  11589. if(hascoin == 0) {
  11590. lua_interface->SetBooleanValue(state, false);
  11591. return 1;
  11592. }
  11593. if(hascoin == 1) {
  11594. lua_interface->SetBooleanValue(state, true);
  11595. return 1;
  11596. }
  11597. }
  11598. return 0;
  11599. }
  11600. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11601. int32 loot_tier = 0;
  11602. Spawn* spawn = lua_interface->GetSpawn(state);
  11603. lua_interface->ResetFunctionStack(state);
  11604. if (spawn) {
  11605. loot_tier = spawn->GetLootTier();
  11606. lua_interface->SetInt32Value(state, loot_tier);
  11607. return 1;
  11608. }
  11609. return 0;
  11610. }
  11611. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11612. if (!lua_interface)
  11613. return 0;
  11614. Spawn* spawn = lua_interface->GetSpawn(state);
  11615. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11616. lua_interface->ResetFunctionStack(state);
  11617. if (spawn) {
  11618. spawn->SetLootTier(loot_tier);
  11619. lua_interface->SetBooleanValue(state, true);
  11620. return 1;
  11621. }
  11622. lua_interface->SetBooleanValue(state, false);
  11623. return 1;
  11624. }
  11625. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11626. int32 loot_drop_type = 0;
  11627. Spawn* spawn = lua_interface->GetSpawn(state);
  11628. lua_interface->ResetFunctionStack(state);
  11629. if (spawn) {
  11630. loot_drop_type = spawn->GetLootDropType();
  11631. lua_interface->SetInt32Value(state, loot_drop_type);
  11632. return 1;
  11633. }
  11634. return 0;
  11635. }
  11636. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11637. if (!lua_interface)
  11638. return 0;
  11639. Spawn* spawn = lua_interface->GetSpawn(state);
  11640. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11641. lua_interface->ResetFunctionStack(state);
  11642. if (spawn) {
  11643. spawn->SetLootDropType(loot_drop_type);
  11644. lua_interface->SetBooleanValue(state, true);
  11645. return 1;
  11646. }
  11647. lua_interface->SetBooleanValue(state, false);
  11648. return 1;
  11649. }
  11650. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11651. if (!lua_interface)
  11652. return 0;
  11653. Spawn* spawn = lua_interface->GetSpawn(state);
  11654. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11655. if(damage_amount > 100) {
  11656. damage_amount = 100;
  11657. }
  11658. if (!spawn) {
  11659. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11660. lua_interface->ResetFunctionStack(state);
  11661. return 0;
  11662. }
  11663. lua_interface->ResetFunctionStack(state);
  11664. if (spawn->IsPlayer()) {
  11665. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11666. lua_interface->SetBooleanValue(state, true);
  11667. else
  11668. lua_interface->SetBooleanValue(state, false);
  11669. }
  11670. else {
  11671. lua_interface->SetBooleanValue(state, false);
  11672. }
  11673. return 1;
  11674. }
  11675. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11676. ZoneServer* zone = lua_interface->GetZone(state);
  11677. int32 version = lua_interface->GetInt32Value(state, 2);
  11678. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11679. if(region_map == nullptr) {
  11680. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11681. lua_interface->ResetFunctionStack(state);
  11682. return 0;
  11683. }
  11684. string region_name = lua_interface->GetStringValue(state, 3);
  11685. string env_name = lua_interface->GetStringValue(state, 4);
  11686. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11687. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11688. float dist = lua_interface->GetFloatValue(state, 7);
  11689. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11690. lua_interface->ResetFunctionStack(state);
  11691. lua_interface->SetBooleanValue(state, true);
  11692. return 1;
  11693. }
  11694. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11695. ZoneServer* zone = lua_interface->GetZone(state);
  11696. int32 version = lua_interface->GetInt32Value(state, 2);
  11697. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11698. if(region_map == nullptr) {
  11699. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11700. lua_interface->ResetFunctionStack(state);
  11701. return 0;
  11702. }
  11703. string region_name = lua_interface->GetStringValue(state, 3);
  11704. region_map->RemoveRegionNode(region_name);
  11705. lua_interface->ResetFunctionStack(state);
  11706. lua_interface->SetBooleanValue(state, true);
  11707. return 1;
  11708. }
  11709. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11710. Client* client = nullptr;
  11711. Spawn* player = lua_interface->GetSpawn(state);
  11712. if (!player) {
  11713. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11714. lua_interface->SetBooleanValue(state, false);
  11715. lua_interface->ResetFunctionStack(state);
  11716. return 1;
  11717. }
  11718. if (!player->IsPlayer()) {
  11719. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11720. lua_interface->SetBooleanValue(state, false);
  11721. lua_interface->ResetFunctionStack(state);
  11722. return 1;
  11723. }
  11724. client = player->GetClient();
  11725. if (!client) {
  11726. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11727. lua_interface->SetBooleanValue(state, false);
  11728. lua_interface->ResetFunctionStack(state);
  11729. return 1;
  11730. }
  11731. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11732. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11733. lua_interface->ResetFunctionStack(state);
  11734. lua_interface->SetBooleanValue(state, success_sight);
  11735. return 1;
  11736. }
  11737. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11738. if (!lua_interface)
  11739. return 0;
  11740. bool result = false;
  11741. Spawn* spawn = lua_interface->GetSpawn(state);
  11742. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11743. lua_interface->ResetFunctionStack(state);
  11744. if (!spawn)
  11745. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11746. else if (!spawn->IsNPC())
  11747. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11748. else
  11749. {
  11750. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11751. result = true;
  11752. }
  11753. lua_interface->SetBooleanValue(state, result);
  11754. return 1;
  11755. }
  11756. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11757. if (!lua_interface)
  11758. return 0;
  11759. bool result = false;
  11760. Spawn* spawn = lua_interface->GetSpawn(state);
  11761. lua_interface->ResetFunctionStack(state);
  11762. if (!spawn)
  11763. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11764. else if (!spawn->IsNPC())
  11765. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11766. else
  11767. {
  11768. if(((NPC*)spawn)->cast_on_aggro_completed)
  11769. result = true;
  11770. }
  11771. lua_interface->SetBooleanValue(state, result);
  11772. return 1;
  11773. }
  11774. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11775. Client* client = nullptr;
  11776. Spawn* player = lua_interface->GetSpawn(state);
  11777. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11778. lua_interface->ResetFunctionStack(state);
  11779. if (!player) {
  11780. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11781. lua_interface->SetBooleanValue(state, false);
  11782. return 1;
  11783. }
  11784. if (!player->IsPlayer()) {
  11785. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11786. lua_interface->SetBooleanValue(state, false);
  11787. return 1;
  11788. }
  11789. client = player->GetClient();
  11790. if (!client) {
  11791. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11792. lua_interface->SetBooleanValue(state, false);
  11793. return 1;
  11794. }
  11795. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11796. lua_interface->SetBooleanValue(state, result);
  11797. return 1;
  11798. }
  11799. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11800. Client* client = nullptr;
  11801. Spawn* player = lua_interface->GetSpawn(state);
  11802. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11803. lua_interface->ResetFunctionStack(state);
  11804. if (!player) {
  11805. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11806. lua_interface->SetBooleanValue(state, false);
  11807. return 1;
  11808. }
  11809. if (!player->IsPlayer()) {
  11810. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11811. lua_interface->SetBooleanValue(state, false);
  11812. return 1;
  11813. }
  11814. client = player->GetClient();
  11815. if (!client) {
  11816. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11817. lua_interface->SetBooleanValue(state, false);
  11818. return 1;
  11819. }
  11820. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11821. lua_interface->SetBooleanValue(state, result);
  11822. return 1;
  11823. }