LuaFunctions.cpp 417 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631
  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. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str());
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1590. if (send_packet)
  1591. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1592. }
  1593. }
  1594. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1595. }
  1596. else if (npc && npc->IsNPC() && npc->GetZone())
  1597. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1598. }
  1599. lua_interface->ResetFunctionStack(state);
  1600. return 0;
  1601. }
  1602. int EQ2Emu_lua_Zone(lua_State* state) {
  1603. if (!lua_interface)
  1604. return 0;
  1605. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1606. ZoneServer* zone = lua_interface->GetZone(state);
  1607. Spawn* player = lua_interface->GetSpawn(state, 2);
  1608. Client* client = 0;
  1609. if (player && player->IsPlayer())
  1610. client = ((Player*)player)->GetClient();
  1611. float x = lua_interface->GetFloatValue(state, 3);
  1612. float y = lua_interface->GetFloatValue(state, 4);
  1613. float z = lua_interface->GetFloatValue(state, 5);
  1614. float heading = lua_interface->GetFloatValue(state, 6);
  1615. if (zone && client) {
  1616. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1617. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1618. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1619. {
  1620. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1621. return 0;
  1622. }
  1623. if (x != 0 || y != 0 || z != 0) {
  1624. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1625. player->SetX(x);
  1626. player->SetY(y);
  1627. player->SetZ(z);
  1628. player->SetHeading(heading);
  1629. client->Zone(zone->GetZoneName(), false);
  1630. }
  1631. else
  1632. client->Zone(zone->GetZoneName());
  1633. }
  1634. else
  1635. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1636. lua_interface->ResetFunctionStack(state);
  1637. return 0;
  1638. }
  1639. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1640. if (!lua_interface)
  1641. return 0;
  1642. Spawn* spawn = lua_interface->GetSpawn(state);
  1643. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1644. if (spawn && spawn2)
  1645. spawn->AddAllowAccessSpawn(spawn2);
  1646. lua_interface->ResetFunctionStack(state);
  1647. return 0;
  1648. }
  1649. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1650. if (!lua_interface)
  1651. return 0;
  1652. Spawn* target = lua_interface->GetSpawn(state);
  1653. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1654. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1655. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1656. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1657. lua_interface->ResetFunctionStack(state);
  1658. if (!target) {
  1659. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1660. return 0;
  1661. }
  1662. if (!target->IsEntity()) {
  1663. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1664. return 0;
  1665. }
  1666. if (spell_id <= 0) {
  1667. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1668. return 0;
  1669. }
  1670. if (caster && !caster->IsEntity()) {
  1671. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1672. return 0;
  1673. }
  1674. if (spell_tier == 0)
  1675. spell_tier = 1;
  1676. if (!caster)
  1677. caster = target;
  1678. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1679. return 0;
  1680. }
  1681. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1682. if (!lua_interface)
  1683. return 0;
  1684. Spawn* target = lua_interface->GetSpawn(state);
  1685. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1686. if(!luaspell || luaspell->resisted) {
  1687. lua_interface->ResetFunctionStack(state);
  1688. return 0;
  1689. }
  1690. Spawn* caster = luaspell->caster;
  1691. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1692. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1693. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1694. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1695. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1696. //lua_interface->ResetFunctionStack(state);
  1697. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1698. vector<int16> faction_req;
  1699. vector<int16> race_req;
  1700. int32 class_req = 0;
  1701. int32 i = 0;
  1702. int8 f = 0;
  1703. int8 r = 0;
  1704. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1705. if (class_id < 100) {
  1706. class_req += pow(2.0, double(class_id - 1));
  1707. }
  1708. else if (class_id > 100 && class_id < 1000) {
  1709. race_req.push_back(class_id);
  1710. r++;
  1711. }
  1712. else {
  1713. faction_req.push_back(class_id);
  1714. f++;
  1715. }
  1716. i++;
  1717. }
  1718. lua_interface->ResetFunctionStack(state);
  1719. if (caster && caster->IsEntity()) {
  1720. bool race_match = false;
  1721. bool success = false;
  1722. luaspell->resisted = false;
  1723. if (luaspell->targets.size() > 0) {
  1724. ZoneServer* zone = luaspell->caster->GetZone();
  1725. Spawn* target = 0;
  1726. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1727. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1728. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1729. if (race_req.size() > 0) {
  1730. for (int8 i = 0; i < race_req.size(); i++) {
  1731. if(race_req[i] == target->GetRace() ||
  1732. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1733. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1734. race_match = true;
  1735. }
  1736. }
  1737. }
  1738. else
  1739. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1740. if (race_match == true) {
  1741. float distance = caster->GetDistance(target, true);
  1742. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1743. }
  1744. }
  1745. }
  1746. success = true;
  1747. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1748. }
  1749. else if (target) {
  1750. //check class and race/faction here
  1751. if (race_req.size() > 0) {
  1752. for (int8 i = 0; i < race_req.size(); i++) {
  1753. if(race_req[i] == target->GetRace() ||
  1754. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1755. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1756. race_match = true;
  1757. }
  1758. }
  1759. }
  1760. else
  1761. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1762. if (race_match == true) {
  1763. float distance = caster->GetDistance(target, true);
  1764. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1765. success = true;
  1766. }
  1767. }
  1768. if (success) {
  1769. Spell* spell = luaspell->spell;
  1770. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1771. ((Player*)caster)->InCombat(true);
  1772. if (caster->GetZone())
  1773. caster->GetZone()->TriggerCharSheetTimer();
  1774. }
  1775. }
  1776. }
  1777. return 0;
  1778. }
  1779. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1780. if (!lua_interface)
  1781. return 0;
  1782. Spawn* spawn = lua_interface->GetSpawn(state);
  1783. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1784. lua_interface->ResetFunctionStack(state);
  1785. if (spawn && value != 0) {
  1786. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1787. spawn->SetPower(spawn->GetTotalPower());
  1788. else
  1789. spawn->SetPower(spawn->GetPower() + value);
  1790. }
  1791. return 0;
  1792. }
  1793. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1794. if (!lua_interface)
  1795. return 0;
  1796. Spawn* spawn = lua_interface->GetSpawn(state);
  1797. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1798. lua_interface->ResetFunctionStack(state);
  1799. if (spawn && value != 0) {
  1800. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1801. spawn->SetHP(spawn->GetTotalHP());
  1802. else
  1803. spawn->SetHP(spawn->GetHP() + value);
  1804. }
  1805. return 0;
  1806. }
  1807. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1808. if (!lua_interface)
  1809. return 0;
  1810. Spawn* spawn = lua_interface->GetSpawn(state);
  1811. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1812. lua_interface->ResetFunctionStack(state);
  1813. if (spawn && value != 0) {
  1814. spawn->SetPower(spawn->GetPower() + value);
  1815. if (value > spawn->GetTotalHPBase())
  1816. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1817. }
  1818. return 0;
  1819. }
  1820. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1821. if (!lua_interface)
  1822. return 0;
  1823. Spawn* spawn = lua_interface->GetSpawn(state);
  1824. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1825. lua_interface->ResetFunctionStack(state);
  1826. if (spawn && value != 0) {
  1827. spawn->SetHP(spawn->GetHP() + value);
  1828. if (value > spawn->GetTotalHPBase())
  1829. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1830. }
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1838. lua_interface->ResetFunctionStack(state);
  1839. if (spawn) {
  1840. spawn->SetHP(value);
  1841. if (value > spawn->GetTotalHPBase())
  1842. spawn->SetTotalHP(value);
  1843. }
  1844. return 0;
  1845. }
  1846. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1847. if (!lua_interface)
  1848. return 0;
  1849. Spawn* spawn = lua_interface->GetSpawn(state);
  1850. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1851. float value = lua_interface->GetFloatValue(state, 2);
  1852. lua_interface->ResetFunctionStack(state);
  1853. if (spawn && spawn->IsEntity() && value > 0)
  1854. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1855. if (spawn && spawn->IsPlayer())
  1856. ((Player*)spawn)->SetCharSheetChanged(true);
  1857. return 0;
  1858. }
  1859. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1860. if (!lua_interface)
  1861. return 0;
  1862. Spawn* spawn = lua_interface->GetSpawn(state);
  1863. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1864. lua_interface->ResetFunctionStack(state);
  1865. if (spawn && spawn->IsEntity() && value > 0)
  1866. ((Entity*)spawn)->SetTotalHPBase(value);
  1867. return 0;
  1868. }
  1869. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1870. if (!lua_interface)
  1871. return 0;
  1872. Spawn* spawn = lua_interface->GetSpawn(state);
  1873. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1874. lua_interface->ResetFunctionStack(state);
  1875. if (spawn && value > 0) {
  1876. spawn->SetPower(value);
  1877. if (value > spawn->GetTotalPowerBase())
  1878. spawn->SetTotalPower(value);
  1879. }
  1880. return 0;
  1881. }
  1882. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1883. if (!lua_interface)
  1884. return 0;
  1885. Spawn* spawn = lua_interface->GetSpawn(state);
  1886. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1887. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1888. lua_interface->ResetFunctionStack(state);
  1889. if (spawn && spawn->IsEntity() && value > 0)
  1890. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1891. return 0;
  1892. }
  1893. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1894. if (!lua_interface)
  1895. return 0;
  1896. Spawn* spawn = lua_interface->GetSpawn(state);
  1897. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1898. lua_interface->ResetFunctionStack(state);
  1899. if (spawn && spawn->IsEntity() && value > 0)
  1900. ((Entity*)spawn)->SetTotalPowerBase(value);
  1901. return 0;
  1902. }
  1903. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1904. if (!lua_interface)
  1905. return 0;
  1906. Spawn* spawn = lua_interface->GetSpawn(state);
  1907. float x = lua_interface->GetFloatValue(state, 2);
  1908. float y = lua_interface->GetFloatValue(state, 3);
  1909. float z = lua_interface->GetFloatValue(state, 4);
  1910. float heading = lua_interface->GetFloatValue(state, 5);
  1911. lua_interface->ResetFunctionStack(state);
  1912. if (spawn) {
  1913. spawn->SetX(x);
  1914. spawn->SetY(y);
  1915. spawn->SetZ(z);
  1916. if (heading != 0)
  1917. spawn->SetHeading(heading);
  1918. spawn->SetSpawnOrigX(spawn->GetX());
  1919. spawn->SetSpawnOrigY(spawn->GetY());
  1920. spawn->SetSpawnOrigZ(spawn->GetZ());
  1921. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1922. if (spawn->IsPlayer()) {
  1923. Client* client = ((Player*)spawn)->GetClient();
  1924. if (client) {
  1925. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1926. client->QueuePacket(packet);
  1927. }
  1928. }
  1929. }
  1930. return 0;
  1931. }
  1932. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1933. if (!lua_interface)
  1934. return 0;
  1935. Spawn* spawn = lua_interface->GetSpawn(state);
  1936. float value = lua_interface->GetFloatValue(state, 2);
  1937. lua_interface->ResetFunctionStack(state);
  1938. if (spawn) {
  1939. spawn->SetHeading(value);
  1940. if (spawn->IsPlayer()) {
  1941. Client* client = ((Player*)spawn)->GetClient();
  1942. if (client) {
  1943. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1944. client->QueuePacket(packet);
  1945. }
  1946. }
  1947. }
  1948. return 0;
  1949. }
  1950. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1951. if (!lua_interface)
  1952. return 0;
  1953. Spawn* spawn = lua_interface->GetSpawn(state);
  1954. int16 value = lua_interface->GetInt16Value(state, 2);
  1955. lua_interface->ResetFunctionStack(state);
  1956. if (spawn)
  1957. spawn->SetModelType(value);
  1958. return 0;
  1959. }
  1960. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1961. if (!lua_interface)
  1962. return 0;
  1963. Spawn* spawn = lua_interface->GetSpawn(state);
  1964. int8 value = lua_interface->GetInt8Value(state, 2);
  1965. lua_interface->ResetFunctionStack(state);
  1966. if (spawn) {
  1967. if (spawn->IsPlayer())
  1968. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1969. else
  1970. spawn->SetAdventureClass(value);
  1971. }
  1972. return 0;
  1973. }
  1974. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1975. if (!lua_interface)
  1976. return 0;
  1977. Spawn* spawn = lua_interface->GetSpawn(state);
  1978. int8 value = lua_interface->GetInt8Value(state, 2);
  1979. lua_interface->ResetFunctionStack(state);
  1980. if (spawn) {
  1981. spawn->SetTradeskillClass(value);
  1982. if (spawn->IsEntity()) {
  1983. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1984. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1985. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1986. }
  1987. if (spawn->IsPlayer())
  1988. ((Player*)spawn)->SetCharSheetChanged(true);
  1989. }
  1990. return 0;
  1991. }
  1992. int EQ2Emu_lua_SetMount(lua_State* state) {
  1993. if (!lua_interface)
  1994. return 0;
  1995. Spawn* spawn = lua_interface->GetSpawn(state);
  1996. int16 value = lua_interface->GetInt16Value(state, 2);
  1997. if (spawn && spawn->IsEntity()) {
  1998. ((Entity*)spawn)->SetMount(value);
  1999. EQ2_Color color;
  2000. color.red = 255;
  2001. color.green = 255;
  2002. color.blue = 255;
  2003. ((Entity*)spawn)->SetMountColor(&color);
  2004. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2005. }
  2006. return 0;
  2007. }
  2008. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2009. if (!lua_interface)
  2010. return 0;
  2011. Spawn* spawn = lua_interface->GetSpawn(state);
  2012. EQ2_Color mount_color;
  2013. EQ2_Color saddle_color;
  2014. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2015. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2016. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2017. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2018. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2019. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2020. if (spawn && spawn->IsEntity()) {
  2021. ((Entity*)spawn)->SetMountColor(&mount_color);
  2022. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2023. }
  2024. return 0;
  2025. }
  2026. int EQ2Emu_lua_GetMount(lua_State* state) {
  2027. if (!lua_interface)
  2028. return 0;
  2029. Spawn* spawn = lua_interface->GetSpawn(state);
  2030. if (spawn && spawn->IsEntity()) {
  2031. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2032. return 1;
  2033. }
  2034. return 0;
  2035. }
  2036. int EQ2Emu_lua_GetRace(lua_State* state) {
  2037. if (!lua_interface)
  2038. return 0;
  2039. Spawn* spawn = lua_interface->GetSpawn(state);
  2040. if (spawn)
  2041. {
  2042. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2043. lua_interface->SetInt32Value(state, spawn->GetRace());
  2044. return 1;
  2045. }
  2046. return 0;
  2047. }
  2048. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2049. if (!lua_interface)
  2050. return 0;
  2051. Spawn* spawn = lua_interface->GetSpawn(state);
  2052. if (spawn) {
  2053. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2054. return 1;
  2055. }
  2056. return 0;
  2057. }
  2058. int EQ2Emu_lua_GetClass(lua_State* state) {
  2059. Spawn* spawn = lua_interface->GetSpawn(state);
  2060. if (spawn) {
  2061. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2062. return 1;
  2063. }
  2064. return 0;
  2065. }
  2066. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2067. Spawn* spawn = lua_interface->GetSpawn(state);
  2068. if (spawn) {
  2069. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2070. return 1;
  2071. }
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. float value = lua_interface->GetFloatValue(state, 2);
  2079. lua_interface->ResetFunctionStack(state);
  2080. if (spawn) {
  2081. spawn->SetSpeed(value);
  2082. if(spawn->IsEntity())
  2083. ((Entity*)spawn)->SetSpeed(value);
  2084. if (spawn->IsPlayer()) {
  2085. Client* client = ((Player*)spawn)->GetClient();
  2086. if (client) {
  2087. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2088. if (packet) {
  2089. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2090. packet->setDataByName("speed", value);
  2091. packet->setDataByName("size", 0.51);
  2092. EQ2Packet* app = packet->serialize();
  2093. client->QueuePacket(app);
  2094. safe_delete(packet);
  2095. }
  2096. }
  2097. }
  2098. }
  2099. return 0;
  2100. }
  2101. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2102. if (!lua_interface)
  2103. return 0;
  2104. Spawn* spawn = lua_interface->GetSpawn(state);
  2105. const int16 type = lua_interface->GetInt16Value(state, 2);
  2106. const float value = lua_interface->GetFloatValue(state, 3);
  2107. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2108. if(!luaspell || luaspell->resisted) {
  2109. lua_interface->ResetFunctionStack(state);
  2110. return 0;
  2111. }
  2112. int64 class_req = 0;
  2113. int32 class_id = 0;
  2114. vector<int16> faction_req;
  2115. vector<int16> race_req;
  2116. int32 i = 0;
  2117. int8 f = 0;
  2118. int8 r = 0;
  2119. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2120. if (class_id < 100) {
  2121. class_req += pow(2.0, double(class_id - 1));
  2122. }
  2123. else if (class_id > 100 && class_id < 1000) {
  2124. race_req.push_back(class_id);
  2125. r++;
  2126. }
  2127. else {
  2128. faction_req.push_back(class_id);
  2129. f++;
  2130. }
  2131. i++;
  2132. }
  2133. if (value != 0 && type >= 0) {
  2134. if (luaspell && luaspell->spell && luaspell->caster) {
  2135. ZoneServer* zone = luaspell->caster->GetZone();
  2136. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2137. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2138. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2139. if (target) {
  2140. if (target->IsPlayer()) {
  2141. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2142. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2143. if (((Player*)target)->GetGroupMemberInfo())
  2144. ((Player*)target)->UpdateGroupMemberInfo();
  2145. ((Player*)target)->SetCharSheetChanged(true);
  2146. }
  2147. else if (target->IsNPC())
  2148. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2149. else
  2150. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2151. }
  2152. }
  2153. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2154. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2155. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2156. }
  2157. else if (spawn && spawn->IsEntity()) {
  2158. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2159. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2160. if (spawn->IsPlayer())
  2161. ((Player*)spawn)->SetCharSheetChanged(true);
  2162. }
  2163. else
  2164. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2171. if (!lua_interface)
  2172. return 0;
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. int16 type = lua_interface->GetInt16Value(state, 2);
  2175. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2176. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2177. if (!spawn) {
  2178. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2179. return 0;
  2180. }
  2181. if (!spawn->IsEntity()) {
  2182. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2183. return 0;
  2184. }
  2185. if (value == 0) {
  2186. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2187. return 0;
  2188. }
  2189. if (!luaspell || !luaspell->spell) {
  2190. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2191. return 0;
  2192. }
  2193. if(luaspell->resisted) {
  2194. lua_interface->ResetFunctionStack(state);
  2195. return 0;
  2196. }
  2197. int32 class_req = 0;
  2198. vector<int16> faction_req;
  2199. vector<int16> race_req;
  2200. int32 class_id = 0;
  2201. int32 i = 0;
  2202. int8 f = 0;
  2203. int8 r = 0;
  2204. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2205. if (class_id < 100) {
  2206. class_req += pow(2.0, double(class_id - 1));
  2207. }
  2208. else if (class_id > 100 && class_id < 1000) {
  2209. race_req.push_back(class_id);
  2210. r++;
  2211. }
  2212. else {
  2213. faction_req.push_back(class_id);
  2214. f++;
  2215. }
  2216. i++;
  2217. }
  2218. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2219. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2220. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2221. if (spawn->IsPlayer())
  2222. ((Player*)spawn)->SetCharSheetChanged(true);
  2223. return 0;
  2224. }
  2225. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2226. if (!lua_interface)
  2227. return 0;
  2228. Spawn* spawn = lua_interface->GetSpawn(state);
  2229. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2230. if (!spawn) {
  2231. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2232. return 0;
  2233. }
  2234. if (!spawn->IsEntity()) {
  2235. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2236. return 0;
  2237. }
  2238. if (!luaspell || !luaspell->spell) {
  2239. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2240. return 0;
  2241. }
  2242. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2243. if (spawn->IsPlayer())
  2244. ((Player*)spawn)->SetCharSheetChanged(true);
  2245. return 0;
  2246. }
  2247. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2248. if (!lua_interface)
  2249. return 0;
  2250. Spawn* spawn = lua_interface->GetSpawn(state);
  2251. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2252. if (luaspell && luaspell->spell) {
  2253. ZoneServer* zone = luaspell->caster->GetZone();
  2254. Spawn* target = 0;
  2255. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2256. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2257. target = zone->GetSpawnByID(luaspell->targets[i]);
  2258. if (target && target->IsEntity()) {
  2259. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2260. if (target->IsPlayer())
  2261. ((Player*)target)->SetCharSheetChanged(true);
  2262. }
  2263. }
  2264. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2265. }
  2266. else if (spawn && spawn->IsEntity()) {
  2267. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2268. if (spawn->IsPlayer())
  2269. ((Player*)spawn)->SetCharSheetChanged(true);
  2270. }
  2271. return 0;
  2272. }
  2273. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2274. if (!lua_interface)
  2275. return 0;
  2276. Spawn* spawn = lua_interface->GetSpawn(state);
  2277. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2278. float value = lua_interface->GetFloatValue(state, 3);
  2279. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2280. if (value != 0) {
  2281. int32 spell_id = 0;
  2282. if (luaspell && luaspell->spell && luaspell->caster) {
  2283. if(luaspell->resisted) {
  2284. lua_interface->ResetFunctionStack(state);
  2285. return 0;
  2286. }
  2287. spell_id = luaspell->spell->GetSpellID();
  2288. ZoneServer* zone = luaspell->caster->GetZone();
  2289. Spawn* target = 0;
  2290. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2291. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2292. target = zone->GetSpawnByID(luaspell->targets[i]);
  2293. if (target && target->Alive()) {
  2294. if (target->IsPlayer()) {
  2295. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2296. Client* client = ((Player*)target)->GetClient();
  2297. if (client) {
  2298. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2299. if (packet)
  2300. client->QueuePacket(packet);
  2301. }
  2302. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2303. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2304. }
  2305. else if (target->IsNPC()) {
  2306. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2307. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2308. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2309. }
  2310. else
  2311. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2312. }
  2313. }
  2314. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2315. }
  2316. else if (spawn) {
  2317. if (spawn->IsPlayer()) {
  2318. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2319. Client* client = ((Player*)spawn)->GetClient();
  2320. if (client) {
  2321. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2322. if (packet)
  2323. client->QueuePacket(packet);
  2324. }
  2325. }
  2326. else if (spawn->IsNPC())
  2327. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2328. else
  2329. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2330. }
  2331. }
  2332. else
  2333. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2334. return 0;
  2335. }
  2336. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2337. if (!lua_interface)
  2338. return 0;
  2339. Spawn* spawn = lua_interface->GetSpawn(state);
  2340. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2341. if (spawn && spawn->IsPlayer()) {
  2342. int32 spell_id = 0;
  2343. if (luaspell && luaspell->spell) {
  2344. if(luaspell->resisted) {
  2345. lua_interface->ResetFunctionStack(state);
  2346. return 0;
  2347. }
  2348. spell_id = luaspell->spell->GetSpellID();
  2349. ZoneServer* zone = luaspell->caster->GetZone();
  2350. Spawn* target = 0;
  2351. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2352. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2353. target = zone->GetSpawnByID(luaspell->targets[i]);
  2354. if (target) {
  2355. if (target->IsPlayer()) {
  2356. ((Player*)target)->RemoveSkillBonus(spell_id);
  2357. Client* client = ((Player*)target)->GetClient();
  2358. if (client) {
  2359. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2360. if (packet)
  2361. client->QueuePacket(packet);
  2362. }
  2363. }
  2364. else if (target->IsNPC())
  2365. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2366. else
  2367. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2368. }
  2369. }
  2370. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2371. }
  2372. else if (spawn) {
  2373. if (spawn->IsPlayer()) {
  2374. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2375. Client* client = ((Player*)spawn)->GetClient();
  2376. if (client) {
  2377. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2378. if (packet)
  2379. client->QueuePacket(packet);
  2380. }
  2381. }
  2382. else if (spawn->IsNPC())
  2383. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2384. else
  2385. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2386. }
  2387. }
  2388. return 0;
  2389. }
  2390. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2391. if (!lua_interface)
  2392. return 0;
  2393. Spawn* spawn = lua_interface->GetSpawn(state);
  2394. int8 type = lua_interface->GetInt32Value(state, 2);
  2395. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2396. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2397. if(luaspell && luaspell->resisted) {
  2398. lua_interface->ResetFunctionStack(state);
  2399. return 0;
  2400. }
  2401. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2402. ZoneServer* zone = luaspell->caster->GetZone();
  2403. Spawn* target = 0;
  2404. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2405. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2406. target = zone->GetSpawnByID(luaspell->targets[i]);
  2407. if (target && target->IsEntity()) {
  2408. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2409. ((Entity*)target)->AddMezSpell(luaspell);
  2410. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2411. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2412. if (target->IsNPC())
  2413. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2414. }
  2415. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2416. ((Entity*)target)->AddStifleSpell(luaspell);
  2417. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2418. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2419. if (target->IsNPC())
  2420. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2421. }
  2422. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2423. ((Entity*)target)->AddDazeSpell(luaspell);
  2424. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2425. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2426. if (target->IsNPC())
  2427. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2428. }
  2429. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2430. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2431. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2432. ((Entity*)target)->AddStunSpell(luaspell);
  2433. if (target->IsNPC())
  2434. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2435. }
  2436. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2437. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2438. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2439. ((Entity*)target)->AddRootSpell(luaspell);
  2440. if (target->IsNPC())
  2441. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2442. }
  2443. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2444. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2445. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2446. ((Entity*)target)->AddFearSpell(luaspell);
  2447. if (target->IsNPC())
  2448. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2449. }
  2450. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2451. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2452. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2453. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2454. }
  2455. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2456. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2457. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2458. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2459. }
  2460. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2461. ((Entity*)target)->AddSnareSpell(luaspell);
  2462. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2463. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2464. if (target->IsNPC())
  2465. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2466. }
  2467. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2468. ((Entity*)target)->AddFlightSpell(luaspell);
  2469. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2470. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2471. }
  2472. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2473. ((Entity*)target)->AddGlideSpell(luaspell);
  2474. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2475. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2476. }
  2477. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2478. ((Entity*)target)->AddSafefallSpell(luaspell);
  2479. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2480. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2481. }
  2482. else
  2483. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2484. }
  2485. else
  2486. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2487. }
  2488. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2489. }
  2490. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2491. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2492. ((Entity*)spawn)->AddMezSpell(luaspell);
  2493. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2494. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2495. }
  2496. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2497. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2498. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2499. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2500. }
  2501. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2502. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2503. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2504. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2505. }
  2506. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2507. ((Entity*)spawn)->AddStunSpell(luaspell);
  2508. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2509. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2510. }
  2511. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2512. ((Entity*)spawn)->AddRootSpell(luaspell);
  2513. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2514. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2515. }
  2516. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2517. ((Entity*)spawn)->AddFearSpell(luaspell);
  2518. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2519. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2520. }
  2521. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2522. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2523. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2524. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2525. }
  2526. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2527. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2528. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2529. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2530. }
  2531. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2532. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2533. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2534. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2535. }
  2536. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2537. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2538. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2539. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2540. }
  2541. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2542. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2543. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2544. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2547. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2550. }
  2551. else
  2552. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2553. }
  2554. else
  2555. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2556. return 0;
  2557. }
  2558. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2559. if (!lua_interface)
  2560. return 0;
  2561. Spawn* spawn = lua_interface->GetSpawn(state);
  2562. int8 type = lua_interface->GetInt8Value(state, 2);
  2563. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2564. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2565. if (spawn && spawn->IsEntity()) {
  2566. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2567. ZoneServer* zone = luaspell->caster->GetZone();
  2568. Spawn* target = 0;
  2569. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2570. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2571. target = zone->GetSpawnByID(luaspell->targets[i]);
  2572. if (target) {
  2573. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2574. ((Entity*)target)->RemoveMezSpell(luaspell);
  2575. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2576. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2577. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2578. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2579. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2580. ((Entity*)target)->RemoveStunSpell(luaspell);
  2581. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2582. ((Entity*)target)->RemoveRootSpell(luaspell);
  2583. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2584. ((Entity*)target)->RemoveFearSpell(luaspell);
  2585. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2586. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2587. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2588. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2589. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2590. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2591. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2592. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2593. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2594. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2595. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2596. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2597. else
  2598. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2599. }
  2600. }
  2601. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2602. }
  2603. else if (only_remove_spawn) {
  2604. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2605. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2606. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2607. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2608. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2609. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2610. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2611. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2612. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2613. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2614. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2615. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2616. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2617. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2618. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2619. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2620. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2621. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2622. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2623. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2624. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2625. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2626. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2627. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2628. else
  2629. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2630. }
  2631. }
  2632. return 0;
  2633. }
  2634. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2635. if (!lua_interface)
  2636. return 0;
  2637. Spawn* spawn = lua_interface->GetSpawn(state);
  2638. int8 type = lua_interface->GetInt8Value(state, 2);
  2639. bool hasEffect = false;
  2640. if (!spawn)
  2641. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2642. else if (!spawn->IsEntity())
  2643. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2644. else if (type < CONTROL_MAX_EFFECTS)
  2645. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2646. else
  2647. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2648. lua_interface->SetBooleanValue(state, hasEffect);
  2649. return 1;
  2650. }
  2651. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2652. if (!lua_interface)
  2653. return 0;
  2654. Spawn* spawn = lua_interface->GetSpawn(state);
  2655. float distance = 0.0f;
  2656. if (!spawn)
  2657. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2658. else if (!spawn->IsNPC())
  2659. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2660. else
  2661. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2662. lua_interface->SetFloatValue(state, distance);
  2663. return 1;
  2664. }
  2665. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Spawn* spawn = lua_interface->GetSpawn(state);
  2669. float distance = 0.0f;
  2670. if (!spawn)
  2671. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2672. else if (!spawn->IsNPC())
  2673. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2674. else
  2675. distance = ((NPC*)spawn)->GetAggroRadius();
  2676. lua_interface->SetFloatValue(state, distance);
  2677. return 1;
  2678. }
  2679. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Spawn* spawn = lua_interface->GetSpawn(state);
  2683. float distance = lua_interface->GetFloatValue(state, 2);
  2684. bool override = lua_interface->GetBooleanValue(state, 3);
  2685. bool result = false;
  2686. lua_interface->ResetFunctionStack(state);
  2687. if (!spawn)
  2688. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2689. else if (!spawn->IsNPC())
  2690. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2691. else
  2692. {
  2693. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2694. result = true;
  2695. }
  2696. lua_interface->SetBooleanValue(state, result);
  2697. return 1;
  2698. }
  2699. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2700. if (!lua_interface)
  2701. return 0;
  2702. Spawn* spawn = lua_interface->GetSpawn(state);
  2703. int16 value = lua_interface->GetInt16Value(state, 2);
  2704. if (spawn && spawn->IsEntity()) {
  2705. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2706. if (spawn->IsPlayer())
  2707. ((Player*)spawn)->SetCharSheetChanged(true);
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Spawn* spawn = lua_interface->GetSpawn(state);
  2715. int16 value = lua_interface->GetInt16Value(state, 2);
  2716. if (spawn && spawn->IsEntity()) {
  2717. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2718. if (spawn->IsPlayer())
  2719. ((Player*)spawn)->SetCharSheetChanged(true);
  2720. }
  2721. return 0;
  2722. }
  2723. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2724. if (!lua_interface)
  2725. return 0;
  2726. Spawn* spawn = lua_interface->GetSpawn(state);
  2727. int16 value = lua_interface->GetInt16Value(state, 2);
  2728. if (spawn && spawn->IsEntity()) {
  2729. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2730. if (spawn->IsPlayer())
  2731. ((Player*)spawn)->SetCharSheetChanged(true);
  2732. }
  2733. return 0;
  2734. }
  2735. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2736. if (!lua_interface)
  2737. return 0;
  2738. Spawn* spawn = lua_interface->GetSpawn(state);
  2739. int16 value = lua_interface->GetInt16Value(state, 2);
  2740. if (spawn && spawn->IsEntity()) {
  2741. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2742. if (spawn->IsPlayer())
  2743. ((Player*)spawn)->SetCharSheetChanged(true);
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2748. if (!lua_interface)
  2749. return 0;
  2750. Spawn* spawn = lua_interface->GetSpawn(state);
  2751. int16 value = lua_interface->GetInt16Value(state, 2);
  2752. if (spawn && spawn->IsEntity()) {
  2753. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2754. if (spawn->IsPlayer())
  2755. ((Player*)spawn)->SetCharSheetChanged(true);
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* spawn = lua_interface->GetSpawn(state);
  2763. int8 value = lua_interface->GetInt8Value(state, 2);
  2764. if (spawn && spawn->IsEntity()) {
  2765. ((Entity*)spawn)->SetDeity(value);
  2766. if (spawn->IsPlayer())
  2767. ((Player*)spawn)->SetCharSheetChanged(true);
  2768. }
  2769. lua_interface->ResetFunctionStack(state);
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. if (spawn && spawn->IsEntity()) {
  2777. int8 deity = ((Entity*)spawn)->GetDeity();
  2778. lua_interface->SetInt32Value(state, deity);
  2779. return 1;
  2780. }
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_SetInt(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* spawn = lua_interface->GetSpawn(state);
  2787. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2788. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2789. if (spawn && spawn->IsEntity()) {
  2790. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2791. if (spawn->IsPlayer())
  2792. ((Player*)spawn)->SetCharSheetChanged(true);
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_SetWis(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2800. Spawn* spawn = lua_interface->GetSpawn(state);
  2801. float value = lua_interface->GetFloatValue(state, 2);
  2802. if (spawn && spawn->IsEntity()) {
  2803. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2804. if (spawn->IsPlayer())
  2805. ((Player*)spawn)->SetCharSheetChanged(true);
  2806. }
  2807. return 0;
  2808. }
  2809. int EQ2Emu_lua_SetSta(lua_State* state) {
  2810. if (!lua_interface)
  2811. return 0;
  2812. Spawn* spawn = lua_interface->GetSpawn(state);
  2813. float value = lua_interface->GetFloatValue(state, 2);
  2814. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2815. if (spawn && spawn->IsEntity()) {
  2816. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2817. if (spawn->IsPlayer())
  2818. ((Player*)spawn)->SetCharSheetChanged(true);
  2819. }
  2820. return 0;
  2821. }
  2822. int EQ2Emu_lua_SetStr(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2827. float value = lua_interface->GetFloatValue(state, 2);
  2828. if (spawn && spawn->IsEntity()) {
  2829. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2830. if (spawn->IsPlayer())
  2831. ((Player*)spawn)->SetCharSheetChanged(true);
  2832. }
  2833. return 0;
  2834. }
  2835. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2840. float value = lua_interface->GetFloatValue(state, 2);
  2841. if (spawn && spawn->IsEntity()) {
  2842. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2843. if (spawn->IsPlayer())
  2844. ((Player*)spawn)->SetCharSheetChanged(true);
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetInt32Value(state, spawn->GetHP());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn) {
  2863. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. if (spawn) {
  2873. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2874. return 1;
  2875. }
  2876. return 0;
  2877. }
  2878. int EQ2Emu_lua_GetName(lua_State* state) {
  2879. if (!lua_interface)
  2880. return 0;
  2881. Spawn* spawn = lua_interface->GetSpawn(state);
  2882. if (spawn) {
  2883. lua_interface->SetStringValue(state, spawn->GetName());
  2884. return 1;
  2885. }
  2886. return 0;
  2887. }
  2888. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2889. Spawn* spawn = lua_interface->GetSpawn(state);
  2890. if (spawn) {
  2891. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2892. return 1;
  2893. }
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn) {
  2901. lua_interface->SetInt32Value(state, spawn->GetPower());
  2902. return 1;
  2903. }
  2904. return 0;
  2905. }
  2906. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2907. if (!lua_interface)
  2908. return 0;
  2909. Spawn* spawn = lua_interface->GetSpawn(state);
  2910. if (spawn) {
  2911. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2912. return 1;
  2913. }
  2914. return 0;
  2915. }
  2916. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2917. if (!lua_interface)
  2918. return 0;
  2919. Spawn* spawn = lua_interface->GetSpawn(state);
  2920. if (spawn) {
  2921. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2922. return 1;
  2923. }
  2924. return 0;
  2925. }
  2926. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2927. if (!lua_interface)
  2928. return 0;
  2929. Spawn* spawn = lua_interface->GetSpawn(state);
  2930. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2931. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2932. if (spawn && spawn2) {
  2933. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2934. lua_interface->SetFloatValue(state, distance);
  2935. return 1;
  2936. }
  2937. return 0;
  2938. }
  2939. int EQ2Emu_lua_GetX(lua_State* state) {
  2940. if (!lua_interface)
  2941. return 0;
  2942. Spawn* spawn = lua_interface->GetSpawn(state);
  2943. if (spawn) {
  2944. lua_interface->SetFloatValue(state, spawn->GetX());
  2945. return 1;
  2946. }
  2947. return 0;
  2948. }
  2949. int EQ2Emu_lua_GetY(lua_State* state) {
  2950. if (!lua_interface)
  2951. return 0;
  2952. Spawn* spawn = lua_interface->GetSpawn(state);
  2953. if (spawn) {
  2954. lua_interface->SetFloatValue(state, spawn->GetY());
  2955. return 1;
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_GetZ(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* spawn = lua_interface->GetSpawn(state);
  2963. if (spawn) {
  2964. lua_interface->SetFloatValue(state, spawn->GetZ());
  2965. return 1;
  2966. }
  2967. return 0;
  2968. }
  2969. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2970. if (!lua_interface)
  2971. return 0;
  2972. Spawn* spawn = lua_interface->GetSpawn(state);
  2973. if (spawn) {
  2974. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2975. return 1;
  2976. }
  2977. return 0;
  2978. }
  2979. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2980. if (!lua_interface)
  2981. return 0;
  2982. Spawn* spawn = lua_interface->GetSpawn(state);
  2983. if (spawn) {
  2984. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2985. return 1;
  2986. }
  2987. return 0;
  2988. }
  2989. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2990. if (!lua_interface)
  2991. return 0;
  2992. Spawn* spawn = lua_interface->GetSpawn(state);
  2993. if (spawn) {
  2994. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2995. return 1;
  2996. }
  2997. return 0;
  2998. }
  2999. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3000. if (!lua_interface)
  3001. return 0;
  3002. Spawn* spawn = lua_interface->GetSpawn(state);
  3003. if (spawn && spawn->IsEntity()) {
  3004. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3005. return 1;
  3006. }
  3007. return 0;
  3008. }
  3009. int EQ2Emu_lua_GetInt(lua_State* state) {
  3010. if (!lua_interface)
  3011. return 0;
  3012. Spawn* spawn = lua_interface->GetSpawn(state);
  3013. if (spawn && spawn->IsEntity()) {
  3014. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3015. return 1;
  3016. }
  3017. return 0;
  3018. }
  3019. int EQ2Emu_lua_GetWis(lua_State* state) {
  3020. if (!lua_interface)
  3021. return 0;
  3022. Spawn* spawn = lua_interface->GetSpawn(state);
  3023. if (spawn && spawn->IsEntity()) {
  3024. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3025. return 1;
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_GetSta(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Spawn* spawn = lua_interface->GetSpawn(state);
  3033. if (spawn && spawn->IsEntity()) {
  3034. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3035. return 1;
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_GetStr(lua_State* state) {
  3040. if (!lua_interface)
  3041. return 0;
  3042. Spawn* spawn = lua_interface->GetSpawn(state);
  3043. if (spawn && spawn->IsEntity()) {
  3044. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3045. return 1;
  3046. }
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3050. if (!lua_interface)
  3051. return 0;
  3052. Spawn* spawn = lua_interface->GetSpawn(state);
  3053. if (spawn && spawn->IsEntity()) {
  3054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3055. return 1;
  3056. }
  3057. return 0;
  3058. }
  3059. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3060. if (!lua_interface)
  3061. return 0;
  3062. Spawn* spawn = lua_interface->GetSpawn(state);
  3063. if (spawn && spawn->IsEntity()) {
  3064. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3065. return 1;
  3066. }
  3067. return 0;
  3068. }
  3069. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3070. if (!lua_interface)
  3071. return 0;
  3072. Spawn* spawn = lua_interface->GetSpawn(state);
  3073. if (spawn && spawn->IsEntity()) {
  3074. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3075. return 1;
  3076. }
  3077. return 0;
  3078. }
  3079. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3080. if (!lua_interface)
  3081. return 0;
  3082. Spawn* spawn = lua_interface->GetSpawn(state);
  3083. if (spawn && spawn->IsEntity()) {
  3084. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3085. return 1;
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* spawn = lua_interface->GetSpawn(state);
  3093. if (spawn && spawn->IsEntity()) {
  3094. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3095. return 1;
  3096. }
  3097. return 0;
  3098. }
  3099. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3100. if (!lua_interface)
  3101. return 0;
  3102. Spawn* spawn = lua_interface->GetSpawn(state);
  3103. if (spawn && spawn->IsEntity()) {
  3104. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3105. return 1;
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Spawn* player = lua_interface->GetSpawn(state);
  3113. if (!player || !player->IsPlayer()) {
  3114. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3115. return 0;
  3116. }
  3117. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3118. if (quest_id <= 0) {
  3119. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3120. return 0;
  3121. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3122. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3123. return 0;
  3124. }
  3125. int32 step = lua_interface->GetInt32Value(state, 3);
  3126. if (step > 0) {
  3127. Client* client = ((Player*)player)->GetClient();
  3128. if (client)
  3129. client->AddPendingQuestUpdate(quest_id, step);
  3130. } else {
  3131. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3132. }
  3133. return 0;
  3134. }
  3135. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3136. Spawn* player = lua_interface->GetSpawn(state);
  3137. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3138. int32 step = lua_interface->GetInt32Value(state, 3);
  3139. int32 progress = lua_interface->GetInt32Value(state, 4);
  3140. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3141. Client* client = ((Player*)player)->GetClient();
  3142. if (client)
  3143. client->AddPendingQuestUpdate(quest_id, step, progress);
  3144. }
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3148. if (!lua_interface)
  3149. return 0;
  3150. Spawn* player = lua_interface->GetSpawn(state);
  3151. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3152. if (player && player->IsPlayer() && quest_id > 0) {
  3153. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3154. return 1;
  3155. }
  3156. return 0;
  3157. }
  3158. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3159. if (!lua_interface)
  3160. return 0;
  3161. Spawn* player = lua_interface->GetSpawn(state);
  3162. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3163. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3164. if (player && player->IsPlayer() && quest_id > 0) {
  3165. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3166. return 1;
  3167. }
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Spawn* player = lua_interface->GetSpawn(state);
  3174. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3175. if (player && player->IsPlayer() && quest_id > 0) {
  3176. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Quest* quest = lua_interface->GetQuest(state);
  3185. string name = lua_interface->GetStringValue(state, 2);
  3186. string type = lua_interface->GetStringValue(state, 3);
  3187. string zone = lua_interface->GetStringValue(state, 4);
  3188. int16 level = lua_interface->GetInt16Value(state, 5);
  3189. string description = lua_interface->GetStringValue(state, 6);
  3190. bool load = true;
  3191. if (!quest) {
  3192. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3193. load = false;
  3194. }
  3195. if (load && name.length() == 0) {
  3196. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3197. load = false;
  3198. }
  3199. if (load && type.length() == 0) {
  3200. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3201. load = false;
  3202. }
  3203. if (load && zone.length() == 0) {
  3204. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3205. load = false;
  3206. }
  3207. if (load && description.length() == 0) {
  3208. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3209. load = false;
  3210. }
  3211. if (load && level == 0) {
  3212. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3213. load = false;
  3214. }
  3215. if (load)
  3216. quest->RegisterQuest(name, type, zone, level, description);
  3217. return 0;
  3218. }
  3219. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3220. if (!lua_interface)
  3221. return 0;
  3222. Quest* quest = lua_interface->GetQuest(state);
  3223. if (quest) {
  3224. int8 level = lua_interface->GetInt16Value(state, 2);
  3225. quest->SetPrereqLevel(level);
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Quest* quest = lua_interface->GetQuest(state);
  3233. if (quest) {
  3234. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3235. quest->AddPrereqQuest(quest_id);
  3236. }
  3237. return 0;
  3238. }
  3239. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3240. if (!lua_interface)
  3241. return 0;
  3242. Quest* quest = lua_interface->GetQuest(state);
  3243. if (quest) {
  3244. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3245. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3246. if (quantity == 0)
  3247. quantity = 1;
  3248. Item* master_item = master_item_list.GetItem(item_id);
  3249. if (master_item) {
  3250. Item* item = new Item(master_item);
  3251. item->details.count = quantity;
  3252. quest->AddPrereqItem(item);
  3253. }
  3254. }
  3255. return 0;
  3256. }
  3257. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3258. if (!lua_interface)
  3259. return 0;
  3260. Spawn* player = lua_interface->GetSpawn(state);
  3261. if(!player || !player->IsPlayer()) {
  3262. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3263. return 0;
  3264. }
  3265. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3266. if (quest_id > 0) {
  3267. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3268. return 1;
  3269. } else {
  3270. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3271. }
  3272. return 0;
  3273. }
  3274. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3275. if (!lua_interface)
  3276. return 0;
  3277. Quest* quest = lua_interface->GetQuest(state);
  3278. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3279. lua_interface->ResetFunctionStack(state);
  3280. if (quest && spawn_id > 0)
  3281. quest->SetQuestReturnNPC(spawn_id);
  3282. return 0;
  3283. }
  3284. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3285. if (!lua_interface)
  3286. return 0;
  3287. Spawn* spawn = lua_interface->GetSpawn(state);
  3288. int32 time = lua_interface->GetInt32Value(state, 2);
  3289. string function = lua_interface->GetStringValue(state, 3);
  3290. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3291. Spawn* player = lua_interface->GetSpawn(state, 5);
  3292. lua_interface->ResetFunctionStack(state);
  3293. if (!spawn) {
  3294. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3295. return 0;
  3296. }
  3297. if (time <= 0) {
  3298. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3299. return 0;
  3300. }
  3301. if (function.length() == 0) {
  3302. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3303. return 0;
  3304. }
  3305. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3306. if ( time < 10)
  3307. time = 10;
  3308. timer->timer = Timer::GetCurrentTime2() + time;
  3309. timer->function = function;
  3310. timer->spawn = spawn->GetID();
  3311. timer->player = player ? player->GetID() : 0;
  3312. if (max_count == 0)
  3313. max_count = 1;
  3314. timer->max_count = max_count;
  3315. timer->current_count = 0;
  3316. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3317. return 0;
  3318. }
  3319. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3320. if (!lua_interface)
  3321. return 0;
  3322. Spawn* spawn = lua_interface->GetSpawn(state);
  3323. string function = lua_interface->GetStringValue(state, 2);
  3324. lua_interface->ResetFunctionStack(state);
  3325. if (!spawn) {
  3326. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3327. return 0;
  3328. }
  3329. if(!spawn->GetZone()) {
  3330. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3331. return 0;
  3332. }
  3333. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3334. return 0;
  3335. }
  3336. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3337. if (!lua_interface)
  3338. return 0;
  3339. Spawn* player = lua_interface->GetSpawn(state);
  3340. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3341. lua_interface->ResetFunctionStack(state);
  3342. if (player && player->IsPlayer() && quest_id > 0) {
  3343. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3344. return 1;
  3345. }
  3346. return 0;
  3347. }
  3348. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3349. if (!lua_interface)
  3350. return 0;
  3351. Spawn* player = lua_interface->GetSpawn(state);
  3352. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3353. lua_interface->ResetFunctionStack(state);
  3354. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3355. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3356. if (quest)
  3357. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3358. return 1;
  3359. }
  3360. return 0;
  3361. }
  3362. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3363. if (!lua_interface)
  3364. return 0;
  3365. Spawn* player = lua_interface->GetSpawn(state);
  3366. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3367. lua_interface->ResetFunctionStack(state);
  3368. if (player && player->IsPlayer() && quest_id > 0) {
  3369. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3370. return 1;
  3371. }
  3372. return 0;
  3373. }
  3374. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3375. if (!lua_interface)
  3376. return 0;
  3377. Spawn* npc = lua_interface->GetSpawn(state);
  3378. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3379. lua_interface->ResetFunctionStack(state);
  3380. if (npc && !npc->IsPlayer() && quest_id > 0)
  3381. npc->AddProvidedQuest(quest_id);
  3382. return 0;
  3383. }
  3384. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3385. if (!lua_interface)
  3386. return 0;
  3387. Spawn* npc = lua_interface->GetSpawn(state);
  3388. Spawn* player = lua_interface->GetSpawn(state, 2);
  3389. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3390. bool forced = lua_interface->GetBooleanValue(state, 4);
  3391. lua_interface->ResetFunctionStack(state);
  3392. /* NPC is allowed to be null */
  3393. if (player && player->IsPlayer() && quest_id > 0) {
  3394. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3395. if (master_quest) {
  3396. Client* client = ((Player*)player)->GetClient();
  3397. if (!client) {
  3398. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3399. }
  3400. Quest* quest = new Quest(master_quest);
  3401. if (!quest) {
  3402. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3403. }
  3404. if (client && quest) {
  3405. if (npc)
  3406. quest->SetQuestGiver(npc->GetDatabaseID());
  3407. else
  3408. quest->SetQuestGiver(0);
  3409. client->AddPendingQuest(quest, forced);
  3410. }
  3411. }
  3412. else {
  3413. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3414. }
  3415. }
  3416. else {
  3417. 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);
  3418. }
  3419. return 0;
  3420. }
  3421. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3422. if (!lua_interface)
  3423. return 0;
  3424. Quest* quest = lua_interface->GetQuest(state);
  3425. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3426. lua_interface->ResetFunctionStack(state);
  3427. if (quest) {
  3428. quest->AddPrereqClass(class_id);
  3429. }
  3430. return 0;
  3431. }
  3432. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3433. if (!lua_interface)
  3434. return 0;
  3435. Quest* quest = lua_interface->GetQuest(state);
  3436. int8 race = lua_interface->GetInt8Value(state, 2);
  3437. lua_interface->ResetFunctionStack(state);
  3438. if (quest) {
  3439. quest->AddPrereqRace(race);
  3440. }
  3441. return 0;
  3442. }
  3443. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3444. if (!lua_interface)
  3445. return 0;
  3446. Quest* quest = lua_interface->GetQuest(state);
  3447. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3448. lua_interface->ResetFunctionStack(state);
  3449. if (quest) {
  3450. quest->AddPrereqModelType(model_type);
  3451. }
  3452. return 0;
  3453. }
  3454. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3455. if (!lua_interface)
  3456. return 0;
  3457. Quest* quest = lua_interface->GetQuest(state);
  3458. int8 level = lua_interface->GetInt8Value(state, 2);
  3459. lua_interface->ResetFunctionStack(state);
  3460. if (!quest) {
  3461. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3462. return 0;
  3463. }
  3464. quest->SetPrereqTSLevel(level);
  3465. return 0;
  3466. }
  3467. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3468. if (!lua_interface)
  3469. return 0;
  3470. Quest* quest = lua_interface->GetQuest(state);
  3471. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3472. lua_interface->ResetFunctionStack(state);
  3473. if (!quest) {
  3474. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3475. return 0;
  3476. }
  3477. quest->AddPrereqTradeskillClass(class_id);
  3478. return 0;
  3479. }
  3480. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3481. if (!lua_interface)
  3482. return 0;
  3483. Quest* quest = lua_interface->GetQuest(state);
  3484. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3485. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3486. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3487. lua_interface->ResetFunctionStack(state);
  3488. if (quest) {
  3489. quest->AddPrereqFaction(faction_id, min, max);
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3498. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (quest) {
  3501. if (quantity == 0)
  3502. quantity = 1;
  3503. Item* master_item = master_item_list.GetItem(item_id);
  3504. if (master_item) {
  3505. Item* item = new Item(master_item);
  3506. item->details.count = quantity;
  3507. quest->AddSelectableRewardItem(item);
  3508. }
  3509. }
  3510. return 0;
  3511. }
  3512. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3513. if (!lua_interface)
  3514. return 0;
  3515. Quest* quest = lua_interface->GetQuest(state);
  3516. if (quest) {
  3517. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3518. vector<Item*>* items = quest->GetRewardItems();
  3519. if (items) {
  3520. vector<Item*>::iterator itr;
  3521. for (itr = items->begin(); itr != items->end(); itr++) {
  3522. if (*itr && (*itr)->details.item_id == item_id) {
  3523. lua_interface->SetBooleanValue(state, true);
  3524. return 1;
  3525. }
  3526. }
  3527. }
  3528. }
  3529. lua_interface->SetBooleanValue(state, false);
  3530. return 1;
  3531. }
  3532. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3533. if (!lua_interface)
  3534. return 0;
  3535. Quest* quest = lua_interface->GetQuest(state);
  3536. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3537. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3538. lua_interface->ResetFunctionStack(state);
  3539. if (quest) {
  3540. if (quantity == 0)
  3541. quantity = 1;
  3542. Item* master_item = master_item_list.GetItem(item_id);
  3543. if (master_item) {
  3544. Item* item = new Item(master_item);
  3545. item->details.count = quantity;
  3546. quest->AddRewardItem(item);
  3547. }
  3548. }
  3549. return 0;
  3550. }
  3551. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. int32 copper = lua_interface->GetInt32Value(state, 2);
  3556. int32 silver = lua_interface->GetInt32Value(state, 3);
  3557. int32 gold = lua_interface->GetInt32Value(state, 4);
  3558. int32 plat = lua_interface->GetInt32Value(state, 5);
  3559. lua_interface->ResetFunctionStack(state);
  3560. if (quest) {
  3561. quest->AddRewardCoins(copper, silver, gold, plat);
  3562. }
  3563. return 0;
  3564. }
  3565. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3566. if (!lua_interface)
  3567. return 0;
  3568. Quest* quest = lua_interface->GetQuest(state);
  3569. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3570. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3571. lua_interface->ResetFunctionStack(state);
  3572. if (quest && faction_id > 0 && amount != 0)
  3573. quest->AddRewardFaction(faction_id, amount);
  3574. return 0;
  3575. }
  3576. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3577. if (!lua_interface)
  3578. return 0;
  3579. Quest* quest = lua_interface->GetQuest(state);
  3580. int32 status = lua_interface->GetInt32Value(state, 2);
  3581. lua_interface->ResetFunctionStack(state);
  3582. if (quest) {
  3583. quest->SetRewardStatus(status);
  3584. }
  3585. return 0;
  3586. }
  3587. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3588. if (!lua_interface)
  3589. return 0;
  3590. Quest* quest = lua_interface->GetQuest(state);
  3591. int32 status = lua_interface->GetInt32Value(state, 2);
  3592. lua_interface->ResetFunctionStack(state);
  3593. if (quest) {
  3594. quest->SetStatusTmpReward(status);
  3595. }
  3596. return 0;
  3597. }
  3598. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3599. if (!lua_interface)
  3600. return 0;
  3601. Quest* quest = lua_interface->GetQuest(state);
  3602. int64 coins = lua_interface->GetInt64Value(state, 2);
  3603. lua_interface->ResetFunctionStack(state);
  3604. if (quest) {
  3605. quest->SetCoinTmpReward(coins);
  3606. }
  3607. return 0;
  3608. }
  3609. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3610. if (!lua_interface)
  3611. return 0;
  3612. Quest* quest = lua_interface->GetQuest(state);
  3613. string comment = lua_interface->GetStringValue(state, 2);
  3614. lua_interface->ResetFunctionStack(state);
  3615. if (quest) {
  3616. quest->SetRewardComment(comment);
  3617. }
  3618. return 0;
  3619. }
  3620. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3621. if (!lua_interface)
  3622. return 0;
  3623. Quest* quest = lua_interface->GetQuest(state);
  3624. int32 exp = lua_interface->GetInt32Value(state, 2);
  3625. lua_interface->ResetFunctionStack(state);
  3626. if (quest) {
  3627. quest->SetRewardXP(exp);
  3628. }
  3629. return 0;
  3630. }
  3631. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3632. Quest* quest = lua_interface->GetQuest(state);
  3633. int32 step = lua_interface->GetInt32Value(state, 2);
  3634. string description = lua_interface->GetStringValue(state, 3);
  3635. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3636. float percentage = lua_interface->GetFloatValue(state, 5);
  3637. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3638. int16 icon = lua_interface->GetInt16Value(state, 7);
  3639. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3640. if (quest) {
  3641. const char* taskgroup = 0;
  3642. if (str_taskgroup.length() > 0)
  3643. taskgroup = str_taskgroup.c_str();
  3644. int32 id = 0;
  3645. vector<int32>* ids = 0;
  3646. int i = 0;
  3647. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3648. if (ids == 0)
  3649. ids = new vector<int32>;
  3650. ids->push_back(id);
  3651. i++;
  3652. }
  3653. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3654. if (quest_step && icon && quantity > 0)
  3655. quest_step->SetIcon(icon);
  3656. if (quest->GetPlayer()) {
  3657. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3658. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3659. }
  3660. }
  3661. lua_interface->ResetFunctionStack(state);
  3662. return 0;
  3663. }
  3664. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3665. {
  3666. if (!lua_interface)
  3667. return 0;
  3668. Quest* quest = lua_interface->GetQuest(state);
  3669. int32 step = lua_interface->GetInt32Value(state, 2);
  3670. string description = lua_interface->GetStringValue(state, 3);
  3671. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3672. float percentage = lua_interface->GetFloatValue(state, 5);
  3673. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3674. int16 icon = lua_interface->GetInt16Value(state, 7);
  3675. if (quest) {
  3676. const char* taskgroup = 0;
  3677. if (str_taskgroup.length() > 0)
  3678. taskgroup = str_taskgroup.c_str();
  3679. int32 id = 0;
  3680. vector<int32>* ids = 0;
  3681. int i = 0;
  3682. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3683. if (ids == 0)
  3684. ids = new vector<int32>;
  3685. ids->push_back(id);
  3686. i++;
  3687. }
  3688. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3689. if (quest_step && icon > 0 && quantity > 0)
  3690. quest_step->SetIcon(icon);
  3691. if (quest->GetPlayer()) {
  3692. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3693. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3694. }
  3695. safe_delete(ids);
  3696. }
  3697. lua_interface->ResetFunctionStack(state);
  3698. return 0;
  3699. }
  3700. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3701. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3702. }
  3703. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3704. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3705. }
  3706. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3707. if (!lua_interface)
  3708. return 0;
  3709. Quest* quest = lua_interface->GetQuest(state);
  3710. int32 step = lua_interface->GetInt32Value(state, 2);
  3711. string description = lua_interface->GetStringValue(state, 3);
  3712. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3713. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3714. int16 icon = lua_interface->GetInt16Value(state, 6);
  3715. if (quest) {
  3716. const char* taskgroup = 0;
  3717. if (str_taskgroup.length() > 0)
  3718. taskgroup = str_taskgroup.c_str();
  3719. int32 npc_id = 0;
  3720. vector<int32>* ids = 0;
  3721. int i = 0;
  3722. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3723. if (ids == 0)
  3724. ids = new vector<int32>;
  3725. ids->push_back(npc_id);
  3726. i++;
  3727. }
  3728. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3729. if (quest_step && icon > 0)
  3730. quest_step->SetIcon(icon);
  3731. if (quest->GetPlayer()) {
  3732. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3733. if(client)
  3734. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3735. }
  3736. safe_delete(ids);
  3737. }
  3738. lua_interface->ResetFunctionStack(state);
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. int32 step = lua_interface->GetInt32Value(state, 2);
  3746. string description = lua_interface->GetStringValue(state, 3);
  3747. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3748. float percentage = lua_interface->GetFloatValue(state, 5);
  3749. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3750. int16 icon = lua_interface->GetInt16Value(state, 7);
  3751. if (quest) {
  3752. const char* taskgroup = 0;
  3753. if (str_taskgroup.length() > 0)
  3754. taskgroup = str_taskgroup.c_str();
  3755. int32 item_id = 0;
  3756. vector<int32>* ids = 0;
  3757. int i = 0;
  3758. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3759. if (ids == 0)
  3760. ids = new vector<int32>;
  3761. ids->push_back(item_id);
  3762. i++;
  3763. }
  3764. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3765. if (quest_step && icon > 0 && quantity > 0)
  3766. quest_step->SetIcon(icon);
  3767. if (quest->GetPlayer()) {
  3768. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3769. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3770. }
  3771. safe_delete(ids);
  3772. }
  3773. lua_interface->ResetFunctionStack(state);
  3774. return 0;
  3775. }
  3776. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3777. if (!lua_interface)
  3778. return 0;
  3779. Quest* quest = lua_interface->GetQuest(state);
  3780. int32 step = lua_interface->GetInt32Value(state, 2);
  3781. string description = lua_interface->GetStringValue(state, 3);
  3782. float max_variation = lua_interface->GetFloatValue(state, 4);
  3783. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3784. int16 icon = lua_interface->GetInt16Value(state, 6);
  3785. if (quest) {
  3786. const char* taskgroup = 0;
  3787. if (str_taskgroup.length() > 0)
  3788. taskgroup = str_taskgroup.c_str();
  3789. vector<Location>* locations = 0;
  3790. int8 i = 7;
  3791. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3792. while (true) {
  3793. Location loc;
  3794. loc.x = lua_interface->GetFloatValue(state, i);
  3795. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3796. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3797. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3798. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3799. break;
  3800. if (locations == 0)
  3801. locations = new vector<Location>;
  3802. locations->push_back(loc);
  3803. i += 4;
  3804. }
  3805. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3806. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3807. if (quest_step && icon > 0)
  3808. quest_step->SetIcon(icon);
  3809. if (quest->GetPlayer()) {
  3810. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3811. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3812. }
  3813. }
  3814. lua_interface->ResetFunctionStack(state);
  3815. return 0;
  3816. }
  3817. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3818. if (!lua_interface)
  3819. return 0;
  3820. Quest* quest = lua_interface->GetQuest(state);
  3821. int32 step = lua_interface->GetInt32Value(state, 2);
  3822. string description = lua_interface->GetStringValue(state, 3);
  3823. float max_variation = lua_interface->GetFloatValue(state, 4);
  3824. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3825. int16 icon = lua_interface->GetInt16Value(state, 6);
  3826. if (quest) {
  3827. const char* taskgroup = 0;
  3828. if (str_taskgroup.length() > 0)
  3829. taskgroup = str_taskgroup.c_str();
  3830. vector<Location>* locations = 0;
  3831. int8 i = 7;
  3832. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3833. while (true) {
  3834. Location loc;
  3835. loc.x = lua_interface->GetFloatValue(state, i);
  3836. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3837. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3838. loc.zone_id = 0;
  3839. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3840. break;
  3841. if (locations == 0)
  3842. locations = new vector<Location>;
  3843. locations->push_back(loc);
  3844. i += 3;
  3845. }
  3846. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3847. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3848. if (quest_step && icon > 0)
  3849. quest_step->SetIcon(icon);
  3850. if (quest->GetPlayer()) {
  3851. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3852. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3853. }
  3854. }
  3855. lua_interface->ResetFunctionStack(state);
  3856. return 0;
  3857. }
  3858. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3859. if (!lua_interface)
  3860. return 0;
  3861. Quest* quest = lua_interface->GetQuest(state);
  3862. int32 step = lua_interface->GetInt32Value(state, 2);
  3863. string description = lua_interface->GetStringValue(state, 3);
  3864. float max_variation = lua_interface->GetFloatValue(state, 4);
  3865. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3866. int16 icon = lua_interface->GetInt16Value(state, 6);
  3867. if (quest) {
  3868. const char* taskgroup = 0;
  3869. if (str_taskgroup.length() > 0)
  3870. taskgroup = str_taskgroup.c_str();
  3871. vector<Location>* locations = 0;
  3872. int i = 7;
  3873. while (true) {
  3874. Location loc;
  3875. loc.x = lua_interface->GetFloatValue(state, i);
  3876. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3877. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3878. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3879. break;
  3880. if (locations == 0)
  3881. locations = new vector<Location>;
  3882. locations->push_back(loc);
  3883. i += 3;
  3884. }
  3885. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3886. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3887. if (quest_step && icon > 0)
  3888. quest_step->SetIcon(icon);
  3889. if (quest->GetPlayer()) {
  3890. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3891. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3892. }
  3893. }
  3894. lua_interface->ResetFunctionStack(state);
  3895. return 0;
  3896. }
  3897. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3898. Quest* quest = lua_interface->GetQuest(state);
  3899. int32 step = lua_interface->GetInt32Value(state, 2);
  3900. string description = lua_interface->GetStringValue(state, 3);
  3901. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3902. float percentage = lua_interface->GetFloatValue(state, 5);
  3903. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3904. int16 icon = lua_interface->GetInt16Value(state, 7);
  3905. if (quest) {
  3906. const char* taskgroup = 0;
  3907. if (str_taskgroup.length() > 0)
  3908. taskgroup = str_taskgroup.c_str();
  3909. int32 spell_id = 0;
  3910. vector<int32>* ids = 0;
  3911. int i = 0;
  3912. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3913. if (ids == 0)
  3914. ids = new vector<int32>;
  3915. ids->push_back(spell_id);
  3916. i++;
  3917. }
  3918. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3919. if (quest_step && icon > 0 && quantity > 0)
  3920. quest_step->SetIcon(icon);
  3921. if (quest->GetPlayer()) {
  3922. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3923. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3924. }
  3925. safe_delete(ids);
  3926. }
  3927. lua_interface->ResetFunctionStack(state);
  3928. return 0;
  3929. }
  3930. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3931. if (!lua_interface)
  3932. return 0;
  3933. Quest* quest = lua_interface->GetQuest(state);
  3934. int32 step = lua_interface->GetInt32Value(state, 2);
  3935. string description = lua_interface->GetStringValue(state, 3);
  3936. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3937. float percentage = lua_interface->GetFloatValue(state, 5);
  3938. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3939. int16 icon = lua_interface->GetInt16Value(state, 7);
  3940. if (quest) {
  3941. const char* taskgroup = 0;
  3942. if (str_taskgroup.length() > 0)
  3943. taskgroup = str_taskgroup.c_str();
  3944. int32 item_id = 0;
  3945. vector<int32>* ids = 0;
  3946. int i = 0;
  3947. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3948. if (ids == 0)
  3949. ids = new vector<int32>;
  3950. ids->push_back(item_id);
  3951. i++;
  3952. }
  3953. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3954. if (quest_step && icon > 0 && quantity > 0)
  3955. quest_step->SetIcon(icon);
  3956. if (quest->GetPlayer()) {
  3957. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3958. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3959. }
  3960. safe_delete(ids);
  3961. }
  3962. lua_interface->ResetFunctionStack(state);
  3963. return 0;
  3964. }
  3965. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3966. if (!lua_interface)
  3967. return 0;
  3968. Quest* quest = lua_interface->GetQuest(state);
  3969. int32 step = lua_interface->GetInt32Value(state, 2);
  3970. string description = lua_interface->GetStringValue(state, 3);
  3971. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3972. float percentage = lua_interface->GetFloatValue(state, 5);
  3973. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3974. int16 icon = lua_interface->GetInt16Value(state, 7);
  3975. if (quest) {
  3976. const char* taskgroup = 0;
  3977. if (str_taskgroup.length() > 0)
  3978. taskgroup = str_taskgroup.c_str();
  3979. int32 item_id = 0;
  3980. vector<int32>* ids = 0;
  3981. int i = 0;
  3982. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3983. if (ids == 0)
  3984. ids = new vector<int32>;
  3985. ids->push_back(item_id);
  3986. i++;
  3987. }
  3988. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3989. if (quest_step && icon > 0 && quantity > 0)
  3990. quest_step->SetIcon(icon);
  3991. if (quest->GetPlayer()) {
  3992. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3993. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3994. }
  3995. safe_delete(ids);
  3996. }
  3997. lua_interface->ResetFunctionStack(state);
  3998. return 0;
  3999. }
  4000. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4001. if (!lua_interface)
  4002. return 0;
  4003. Quest* quest = lua_interface->GetQuest(state);
  4004. string action = lua_interface->GetStringValue(state, 2);
  4005. lua_interface->ResetFunctionStack(state);
  4006. if (quest) {
  4007. if (action.length() > 0)
  4008. quest->SetCompleteAction(action);
  4009. }
  4010. return 0;
  4011. }
  4012. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4013. if (!lua_interface)
  4014. return 0;
  4015. Quest* quest = lua_interface->GetQuest(state);
  4016. int32 step = lua_interface->GetInt32Value(state, 2);
  4017. string action = lua_interface->GetStringValue(state, 3);
  4018. lua_interface->ResetFunctionStack(state);
  4019. if (quest) {
  4020. if (step > 0 && action.length() > 0)
  4021. quest->AddCompleteAction(step, action);
  4022. }
  4023. return 0;
  4024. }
  4025. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4026. if (!lua_interface)
  4027. return 0;
  4028. Quest* quest = lua_interface->GetQuest(state);
  4029. int32 step = lua_interface->GetInt32Value(state, 2);
  4030. string action = lua_interface->GetStringValue(state, 3);
  4031. lua_interface->ResetFunctionStack(state);
  4032. if (quest) {
  4033. if (step > 0 && action.length() > 0)
  4034. quest->AddProgressAction(step, action);
  4035. }
  4036. return 0;
  4037. }
  4038. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4039. if (!lua_interface)
  4040. return 0;
  4041. Quest* quest = lua_interface->GetQuest(state);
  4042. string description = lua_interface->GetStringValue(state, 2);
  4043. lua_interface->ResetFunctionStack(state);
  4044. if (quest && description.length() > 0)
  4045. quest->SetDescription(description);
  4046. return 0;
  4047. }
  4048. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4049. if (!lua_interface)
  4050. return 0;
  4051. Quest* quest = lua_interface->GetQuest(state);
  4052. string description = lua_interface->GetStringValue(state, 2);
  4053. lua_interface->ResetFunctionStack(state);
  4054. if (quest && description.length() > 0)
  4055. quest->SetCompletedDescription(description);
  4056. return 0;
  4057. }
  4058. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4059. if (!lua_interface)
  4060. return 0;
  4061. Quest* quest = lua_interface->GetQuest(state);
  4062. int32 step = lua_interface->GetInt32Value(state, 2);
  4063. string description = lua_interface->GetStringValue(state, 3);
  4064. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4065. lua_interface->ResetFunctionStack(state);
  4066. if (quest && step > 0 && description.length() > 0) {
  4067. quest->SetTaskGroupDescription(step, description, display_bullets);
  4068. /* if (quest->GetPlayer()) {
  4069. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4070. if (client)
  4071. client->SendQuestUpdateStep(quest, step, false);
  4072. }*/
  4073. }
  4074. return 0;
  4075. }
  4076. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4077. if (!lua_interface)
  4078. return 0;
  4079. Quest* quest = lua_interface->GetQuest(state);
  4080. int32 step = lua_interface->GetInt32Value(state, 2);
  4081. string description = lua_interface->GetStringValue(state, 3);
  4082. lua_interface->ResetFunctionStack(state);
  4083. if (quest && step > 0 && description.length() > 0) {
  4084. quest->SetStepDescription(step, description);
  4085. /*if (quest->GetPlayer()) {
  4086. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4087. if (client)
  4088. client->SendQuestUpdateStepImmediately(quest, step);
  4089. }*/
  4090. }
  4091. return 0;
  4092. }
  4093. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4094. Quest* quest = lua_interface->GetQuest(state);
  4095. string zone = lua_interface->GetStringValue(state, 2);
  4096. lua_interface->ResetFunctionStack(state);
  4097. if (quest && zone.length() > 0)
  4098. quest->SetZone(zone);
  4099. return 0;
  4100. }
  4101. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4102. if (!lua_interface)
  4103. return 0;
  4104. Quest* quest = lua_interface->GetQuest(state);
  4105. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4106. lua_interface->ResetFunctionStack(state);
  4107. if (quest && spawn) {
  4108. if (spawn->IsPlayer()) {
  4109. Client* client = ((Player*)spawn)->GetClient();
  4110. if (client) {
  4111. client->AddPendingQuestReward(quest);
  4112. }
  4113. }
  4114. }
  4115. return 0;
  4116. }
  4117. int EQ2Emu_lua_Harvest(lua_State* state) {
  4118. if (!lua_interface)
  4119. return 0;
  4120. Spawn* player = lua_interface->GetSpawn(state);
  4121. Spawn* node = lua_interface->GetSpawn(state, 2);
  4122. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4123. Client* client = ((Player*)player)->GetClient();
  4124. if (client) {
  4125. ((GroundSpawn*)node)->ProcessHarvest(client);
  4126. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4127. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4128. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4129. }
  4130. }
  4131. }
  4132. else if (player && player->IsPlayer()) {
  4133. Client* client = ((Player*)player)->GetClient();
  4134. if (client)
  4135. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4136. }
  4137. lua_interface->ResetFunctionStack(state);
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_Bind(lua_State* state) {
  4141. if (!lua_interface)
  4142. return 0;
  4143. Spawn* spawn = lua_interface->GetSpawn(state);
  4144. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4145. float x = lua_interface->GetFloatValue(state, 3);
  4146. float y = lua_interface->GetFloatValue(state, 4);
  4147. float z = lua_interface->GetFloatValue(state, 5);
  4148. float h = lua_interface->GetFloatValue(state, 6);
  4149. lua_interface->ResetFunctionStack(state);
  4150. if (!spawn) {
  4151. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4152. return 0;
  4153. }
  4154. if (!spawn->IsPlayer()) {
  4155. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4156. return 0;
  4157. }
  4158. if (zone_id == 0) {
  4159. Client* client = ((Player*)spawn)->GetClient();
  4160. if (!client) {
  4161. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4162. return 0;
  4163. }
  4164. if (!client->Bind())
  4165. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4166. }
  4167. else {
  4168. Player* player = (Player*)spawn;
  4169. player->GetPlayerInfo()->SetBindZone(zone_id);
  4170. player->GetPlayerInfo()->SetBindX(x);
  4171. player->GetPlayerInfo()->SetBindY(y);
  4172. player->GetPlayerInfo()->SetBindZ(z);
  4173. player->GetPlayerInfo()->SetBindHeading(h);
  4174. }
  4175. return 0;
  4176. }
  4177. int EQ2Emu_lua_Gate(lua_State* state) {
  4178. if (!lua_interface)
  4179. return 0;
  4180. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4181. Spawn* spawn = lua_interface->GetSpawn(state);
  4182. lua_interface->ResetFunctionStack(state);
  4183. if (spawn) {
  4184. if (spawn->IsPlayer()) {
  4185. Client* client = ((Player*)spawn)->GetClient();
  4186. if (client) {
  4187. if (!client->Gate((spell != nullptr) ? true : false))
  4188. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4189. }
  4190. }
  4191. }
  4192. return 0;
  4193. }
  4194. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4195. if (!lua_interface)
  4196. return 0;
  4197. bool ret = false;
  4198. Spawn* spawn = lua_interface->GetSpawn(state);
  4199. lua_interface->ResetFunctionStack(state);
  4200. if (spawn) {
  4201. if (spawn->IsPlayer()) {
  4202. Client* client = ((Player*)spawn)->GetClient();
  4203. if (client)
  4204. ret = client->BindAllowed();
  4205. }
  4206. }
  4207. lua_interface->SetBooleanValue(state, ret);
  4208. return 1;
  4209. }
  4210. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4211. if (!lua_interface)
  4212. return 0;
  4213. bool ret = false;
  4214. Spawn* spawn = lua_interface->GetSpawn(state);
  4215. lua_interface->ResetFunctionStack(state);
  4216. if (spawn) {
  4217. if (spawn->IsPlayer()) {
  4218. Client* client = ((Player*)spawn)->GetClient();
  4219. ZoneServer* zone = lua_interface->GetZone(state);
  4220. if (client && zone){
  4221. ret = zone->GetCanGate();
  4222. }
  4223. }
  4224. }
  4225. lua_interface->SetBooleanValue(state, ret);
  4226. return 1;
  4227. }
  4228. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4229. Spawn* spawn = lua_interface->GetSpawn(state);
  4230. lua_interface->ResetFunctionStack(state);
  4231. if (spawn) {
  4232. lua_interface->SetBooleanValue(state, spawn->Alive());
  4233. return 1;
  4234. }
  4235. return 0;
  4236. }
  4237. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4238. if (!lua_interface)
  4239. return 0;
  4240. Spawn* spawn = lua_interface->GetSpawn(state);
  4241. lua_interface->ResetFunctionStack(state);
  4242. if (spawn && spawn->IsEntity()) {
  4243. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4244. return 1;
  4245. }
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4249. Spawn* spawn = lua_interface->GetSpawn(state);
  4250. string message = lua_interface->GetStringValue(state, 2);
  4251. string color_str = lua_interface->GetStringValue(state, 3);
  4252. lua_interface->ResetFunctionStack(state);
  4253. int8 color = CHANNEL_NARRATIVE;
  4254. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4255. Client* client = ((Player*)spawn)->GetClient();
  4256. if (client) {
  4257. if (color_str.length() > 0) {
  4258. // leave for backwards compat, but all future should just use the number
  4259. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4260. color = CHANNEL_COLOR_RED;
  4261. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4262. color = CHANNEL_COLOR_YELLOW;
  4263. else
  4264. {
  4265. // use a number to specify the channel as per Commands/Commands.h defines
  4266. color = (int8)atoul(color_str.c_str());
  4267. }
  4268. }
  4269. client->SimpleMessage(color, message.c_str());
  4270. }
  4271. }
  4272. return 0;
  4273. }
  4274. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4275. Spawn* spawn = lua_interface->GetSpawn(state);
  4276. string message = lua_interface->GetStringValue(state, 2);
  4277. int8 red = lua_interface->GetInt8Value(state, 3);
  4278. int8 green = lua_interface->GetInt8Value(state, 4);
  4279. int8 blue = lua_interface->GetInt8Value(state, 5);
  4280. lua_interface->ResetFunctionStack(state);
  4281. if (!spawn) {
  4282. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4283. return 0;
  4284. }
  4285. if (!spawn->IsPlayer()) {
  4286. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4287. return 0;
  4288. }
  4289. int32 words = ::CountWordsInString(message.c_str());
  4290. if (words < 5)
  4291. words = 5;
  4292. Client* client = ((Player*)spawn)->GetClient();
  4293. if (client)
  4294. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4295. return 0;
  4296. }
  4297. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4298. Spawn* spawn = lua_interface->GetSpawn(state);
  4299. int8 param = lua_interface->GetInt8Value(state, 2);
  4300. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4301. int8 value = lua_interface->GetInt8Value(state, 4);
  4302. lua_interface->ResetFunctionStack(state);
  4303. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4304. Client* client = ((Player*)spawn)->GetClient();
  4305. if (client) {
  4306. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4307. switch (param) {
  4308. case 1: {
  4309. packet->setDataByName("parameter1", param_value);
  4310. break;
  4311. }
  4312. case 2: {
  4313. packet->setDataByName("parameter2", param_value);
  4314. break;
  4315. }
  4316. case 3: {
  4317. packet->setDataByName("parameter3", param_value);
  4318. break;
  4319. }
  4320. case 4: {
  4321. packet->setDataByName("parameter4", param_value);
  4322. break;
  4323. }
  4324. case 5: {
  4325. packet->setDataByName("parameter5", param_value);
  4326. break;
  4327. }
  4328. }
  4329. packet->setDataByName("value", value);
  4330. client->QueuePacket(packet->serialize());
  4331. safe_delete(packet);
  4332. }
  4333. }
  4334. return 0;
  4335. }
  4336. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4337. Spawn* spawn = lua_interface->GetSpawn(state);
  4338. lua_interface->ResetFunctionStack(state);
  4339. if (spawn && spawn->IsPlayer()) {
  4340. if (((Player*)spawn)->GetIsTracking())
  4341. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4342. else
  4343. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4344. }
  4345. return 0;
  4346. }
  4347. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4348. Spawn* player = lua_interface->GetSpawn(state);
  4349. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4350. string name = lua_interface->GetStringValue(state, 3);
  4351. float distance = lua_interface->GetFloatValue(state, 4);
  4352. string command = lua_interface->GetStringValue(state, 5);
  4353. string error_text = lua_interface->GetStringValue(state, 6);
  4354. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4355. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4356. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4357. lua_interface->ResetFunctionStack(state);
  4358. if (spawn) {
  4359. if (distance == 0)
  4360. distance = 10.0f;
  4361. if (command.length() == 0)
  4362. command = name;
  4363. if (command.length() < 1 && name.length() < 1)
  4364. {
  4365. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4366. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4367. spawn->RemovePrimaryCommands();
  4368. }
  4369. else
  4370. {
  4371. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4372. }
  4373. }
  4374. return 0;
  4375. }
  4376. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4377. if (!lua_interface)
  4378. return 0;
  4379. Spawn* player = lua_interface->GetSpawn(state);
  4380. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4381. int16 tier = lua_interface->GetInt16Value(state, 3);
  4382. lua_interface->ResetFunctionStack(state);
  4383. if (player && player->IsPlayer()) {
  4384. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4385. return 1;
  4386. }
  4387. return 0;
  4388. }
  4389. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4390. if (!lua_interface)
  4391. return 0;
  4392. Spawn* player = lua_interface->GetSpawn(state);
  4393. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4394. int16 tier = lua_interface->GetInt16Value(state, 3);
  4395. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4396. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4397. bool add_to_hotbar = true;
  4398. if (num_args > 4) {
  4399. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4400. }
  4401. lua_interface->ResetFunctionStack(state);
  4402. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4403. if (player && spell && player->IsPlayer()) {
  4404. Client* client = player->GetClient();
  4405. if (client) {
  4406. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4407. {
  4408. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4409. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), 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. else
  4414. {
  4415. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4416. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4417. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4418. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4419. client->GetPlayer()->UnlockSpell(spell);
  4420. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4421. }
  4422. //if (client ) {
  4423. // ((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);
  4424. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4425. if (outapp)
  4426. client->QueuePacket(outapp);
  4427. }
  4428. }
  4429. return 0;
  4430. }
  4431. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4432. if (!lua_interface)
  4433. return 0;
  4434. Spawn* player = lua_interface->GetSpawn(state);
  4435. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4436. lua_interface->ResetFunctionStack(state);
  4437. if (player && player->IsPlayer()) {
  4438. Client* client = player->GetClient();
  4439. if (client) {
  4440. ((Player*)player)->DeleteSpellBook(type_selection);
  4441. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4442. if (outapp)
  4443. client->QueuePacket(outapp);
  4444. }
  4445. }
  4446. return 0;
  4447. }
  4448. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4449. if (!lua_interface)
  4450. return 0;
  4451. Spawn* player = lua_interface->GetSpawn(state);
  4452. lua_interface->ResetFunctionStack(state);
  4453. if (player && player->IsPlayer()) {
  4454. Client* client = player->GetClient();
  4455. if (client) {
  4456. client->SendNewAdventureSpells();
  4457. }
  4458. }
  4459. return 0;
  4460. }
  4461. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4462. if (!lua_interface)
  4463. return 0;
  4464. Spawn* player = lua_interface->GetSpawn(state);
  4465. lua_interface->ResetFunctionStack(state);
  4466. if (player && player->IsPlayer()) {
  4467. Client* client = player->GetClient();
  4468. if (client) {
  4469. client->SendNewTradeskillSpells();
  4470. }
  4471. }
  4472. return 0;
  4473. }
  4474. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4475. if (!lua_interface)
  4476. return 0;
  4477. Spawn* player = lua_interface->GetSpawn(state);
  4478. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4479. lua_interface->ResetFunctionStack(state);
  4480. if (player && player->IsPlayer()) {
  4481. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4482. Client* client = player->GetClient();
  4483. if (sbe && client) {
  4484. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4485. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4486. if (outapp)
  4487. client->QueuePacket(outapp);
  4488. }
  4489. }
  4490. return 0;
  4491. }
  4492. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4493. if (!lua_interface)
  4494. return 0;
  4495. Spawn* player = lua_interface->GetSpawn(state);
  4496. lua_interface->ResetFunctionStack(state);
  4497. if (player && player->IsPlayer()) {
  4498. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4499. return 1;
  4500. }
  4501. return 0;
  4502. }
  4503. int EQ2Emu_lua_Attack(lua_State* state) {
  4504. if (lua_interface) {
  4505. Spawn* npc = lua_interface->GetSpawn(state);
  4506. Spawn* player = lua_interface->GetSpawn(state, 2);
  4507. lua_interface->ResetFunctionStack(state);
  4508. if (npc && player && npc->IsNPC() && player->IsEntity())
  4509. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4510. }
  4511. return 0;
  4512. }
  4513. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4514. if (lua_interface) {
  4515. Spawn* target = lua_interface->GetSpawn(state);
  4516. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4517. lua_interface->ResetFunctionStack(state);
  4518. if (target && target->GetZone())
  4519. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4520. }
  4521. return 0;
  4522. }
  4523. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4524. Spawn* player;
  4525. if (lua_interface) {
  4526. player = lua_interface->GetSpawn(state);
  4527. lua_interface->ResetFunctionStack(state);
  4528. if (player && player->IsPlayer()) {
  4529. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4530. return 1;
  4531. }
  4532. }
  4533. return 0;
  4534. }
  4535. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4536. Spawn* player;
  4537. Client* client;
  4538. if (lua_interface) {
  4539. player = lua_interface->GetSpawn(state);
  4540. lua_interface->ResetFunctionStack(state);
  4541. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4542. if ((client = ((Player*)player)->GetClient()))
  4543. client->HandInCollections();
  4544. }
  4545. return 0;
  4546. }
  4547. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4548. Spawn* widget;
  4549. if (lua_interface) {
  4550. widget = lua_interface->GetSpawn(state);
  4551. lua_interface->ResetFunctionStack(state);
  4552. if (widget && widget->IsWidget())
  4553. ((Widget*)widget)->HandleUse(nullptr, "");
  4554. }
  4555. return 0;
  4556. }
  4557. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4558. Spawn* spawn = 0;
  4559. int32 primary_list = 0;
  4560. int32 secondary_list = 0;
  4561. if (lua_interface) {
  4562. spawn = lua_interface->GetSpawn(state);
  4563. primary_list = lua_interface->GetInt32Value(state, 2);
  4564. secondary_list = lua_interface->GetInt32Value(state, 3);
  4565. lua_interface->ResetFunctionStack(state);
  4566. if (!spawn->IsNPC()) {
  4567. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4568. return 0;
  4569. }
  4570. NPC* npc = (NPC*)spawn;
  4571. npc->SetPrimarySpellList(primary_list);
  4572. npc->SetSecondarySpellList(secondary_list);
  4573. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4574. }
  4575. return 0;
  4576. }
  4577. int EQ2Emu_lua_GetPet(lua_State* state) {
  4578. if (!lua_interface)
  4579. return 0;
  4580. Spawn* spawn = lua_interface->GetSpawn(state);
  4581. lua_interface->ResetFunctionStack(state);
  4582. if (spawn) {
  4583. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4584. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4585. return 1;
  4586. }
  4587. }
  4588. return 0;
  4589. }
  4590. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4591. if (!lua_interface)
  4592. return 0;
  4593. Spawn* spawn = lua_interface->GetSpawn(state);
  4594. lua_interface->ResetFunctionStack(state);
  4595. if (spawn) {
  4596. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4597. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4598. return 1;
  4599. }
  4600. }
  4601. return 0;
  4602. }
  4603. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4604. if (!lua_interface)
  4605. return 0;
  4606. Spawn* spawn = lua_interface->GetSpawn(state);
  4607. lua_interface->ResetFunctionStack(state);
  4608. if (spawn) {
  4609. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4610. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4611. return 1;
  4612. }
  4613. }
  4614. return 0;
  4615. }
  4616. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4617. if (!lua_interface)
  4618. return 0;
  4619. Spawn* spawn = lua_interface->GetSpawn(state);
  4620. lua_interface->ResetFunctionStack(state);
  4621. if (spawn) {
  4622. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4623. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4624. return 1;
  4625. }
  4626. }
  4627. return 0;
  4628. }
  4629. int EQ2Emu_lua_Charm(lua_State* state) {
  4630. if (!lua_interface)
  4631. return 0;
  4632. Spawn* owner = lua_interface->GetSpawn(state);
  4633. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4634. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4635. lua_interface->ResetFunctionStack(state);
  4636. if (!luaspell) {
  4637. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4638. return 0;
  4639. }
  4640. if(luaspell->resisted) {
  4641. return 0;
  4642. }
  4643. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4644. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4645. pet->SetPet(true);
  4646. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4647. ((NPC*)pet)->SetOwner((Entity*)owner);
  4648. // If owner is player and player does not have a summoned pet set the players charsheet
  4649. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4650. Player* player = (Player*)owner;
  4651. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4652. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4653. player->GetInfoStruct()->set_pet_movement(2);
  4654. player->GetInfoStruct()->set_pet_behavior(3);
  4655. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4656. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4657. // Make sure the values get sent to the client
  4658. player->SetCharSheetChanged(true);
  4659. }
  4660. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4661. pet->SetSpawnScript("");
  4662. // Set faction to the same as the owner
  4663. pet->SetFactionID(owner->GetFactionID());
  4664. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4665. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4666. // Clear hate list
  4667. ((NPC*)pet)->Brain()->ClearHate();
  4668. // Set the brain to a pet brain
  4669. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4670. }
  4671. return 0;
  4672. }
  4673. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4674. if (!lua_interface)
  4675. return 0;
  4676. Spawn* spawn = lua_interface->GetSpawn(state);
  4677. lua_interface->ResetFunctionStack(state);
  4678. if (!spawn) {
  4679. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4680. return 0;
  4681. }
  4682. vector<Spawn*> groupMembers;
  4683. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4684. groupMembers = *spawn->GetSpawnGroup();
  4685. }
  4686. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4687. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4688. deque<GroupMemberInfo*>::iterator itr;
  4689. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4690. if (group)
  4691. {
  4692. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4693. deque<GroupMemberInfo*>* members = group->GetMembers();
  4694. GroupMemberInfo* info = 0;
  4695. for (itr = members->begin(); itr != members->end(); itr++) {
  4696. info = *itr;
  4697. if (info->client)
  4698. groupMembers.push_back(info->client->GetPlayer());
  4699. }
  4700. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4701. }
  4702. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4703. }
  4704. else
  4705. return 0;
  4706. lua_createtable(state, groupMembers.size(), 0);
  4707. int newTable = lua_gettop(state);
  4708. for (int32 i = 0; i < groupMembers.size(); i++) {
  4709. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4710. lua_rawseti(state, newTable, i + 1);
  4711. }
  4712. return 1;
  4713. }
  4714. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4715. if (!lua_interface)
  4716. return 0;
  4717. lua_interface->ResetFunctionStack(state);
  4718. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4719. lua_interface->SetOptionWindowValue(state, option_window);
  4720. return 1;
  4721. }
  4722. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4723. if (!lua_interface)
  4724. return 0;
  4725. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4726. if (option_window) {
  4727. OptionWindowOption option_window_option;
  4728. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4729. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4730. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4731. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4732. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4733. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4734. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4735. option_window->push_back(option_window_option);
  4736. }
  4737. lua_interface->ResetFunctionStack(state);
  4738. return 0;
  4739. }
  4740. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4741. if (!lua_interface)
  4742. return 0;
  4743. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4744. Spawn* player = lua_interface->GetSpawn(state, 2);
  4745. string window_title = lua_interface->GetStringValue(state, 3);
  4746. string cancel_command = lua_interface->GetStringValue(state, 4);
  4747. lua_interface->ResetFunctionStack(state);
  4748. if (!player->IsPlayer()) {
  4749. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4750. return 0;
  4751. }
  4752. Client* client = ((Player*)player)->GetClient();
  4753. if (option_window && window_title.length() > 0 && client) {
  4754. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4755. if (!packet)
  4756. return 0;
  4757. packet->setDataByName("title_text", window_title.c_str());
  4758. if (cancel_command.length() > 0)
  4759. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4760. packet->setArrayLengthByName("num_selections", option_window->size());
  4761. vector<OptionWindowOption>::iterator itr;
  4762. int8 i = 0;
  4763. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4764. OptionWindowOption opt = *itr;
  4765. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4766. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4767. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4768. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4769. if (opt.optionCommand.length() > 0)
  4770. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4771. if (opt.optionConfirmTitle.length() > 0)
  4772. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4773. i++;
  4774. }
  4775. client->QueuePacket(packet->serialize());
  4776. lua_interface->SetLuaUserDataStale(option_window);
  4777. safe_delete(option_window);
  4778. safe_delete(packet);
  4779. }
  4780. return 0;
  4781. }
  4782. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4783. if (!lua_interface)
  4784. return 0;
  4785. Spawn* spawn = lua_interface->GetSpawn(state);
  4786. lua_interface->ResetFunctionStack(state);
  4787. if (spawn) {
  4788. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4789. return 1;
  4790. }
  4791. else
  4792. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4793. return 0;
  4794. }
  4795. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4796. if (!lua_interface)
  4797. return 0;
  4798. Spawn* spawn = lua_interface->GetSpawn(state);
  4799. lua_interface->ResetFunctionStack(state);
  4800. if (spawn) {
  4801. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4802. return 1;
  4803. }
  4804. else
  4805. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4806. return 0;
  4807. }
  4808. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4809. if (!lua_interface)
  4810. return 0;
  4811. Spawn* spawn = lua_interface->GetSpawn(state);
  4812. lua_interface->ResetFunctionStack(state);
  4813. if (spawn) {
  4814. int8 class_id = spawn->GetTradeskillClass();
  4815. // Need to add 42 for the offset in the array
  4816. class_id += 44;
  4817. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4818. return 1;
  4819. }
  4820. else
  4821. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4822. return 0;
  4823. }
  4824. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4825. if (!lua_interface)
  4826. return 0;
  4827. Spawn* spawn = lua_interface->GetSpawn(state);
  4828. int16 level = lua_interface->GetInt8Value(state, 2);
  4829. lua_interface->ResetFunctionStack(state);
  4830. if (spawn) {
  4831. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4832. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4833. else
  4834. spawn->SetTSLevel(level);
  4835. }
  4836. else
  4837. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4838. return 0;
  4839. }
  4840. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4841. if (!lua_interface)
  4842. return 0;
  4843. Spawn* spawn = lua_interface->GetSpawn(state);
  4844. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4845. lua_interface->ResetFunctionStack(state);
  4846. if (spawn) {
  4847. spawn->SetAttackable(attackable);
  4848. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4849. }
  4850. return 0;
  4851. }
  4852. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4853. // Check to see if we have a valid lua_interface
  4854. if (!lua_interface)
  4855. return 0;
  4856. // Get the spawn that is getting the pet
  4857. Spawn* spawn = lua_interface->GetSpawn(state);
  4858. // Get the DB ID of the pet
  4859. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4860. // The max level the pet can gain
  4861. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4862. // Get the spell that this command was called from
  4863. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4864. lua_interface->ResetFunctionStack(state);
  4865. // Check to make sure the spawn pointer is valid
  4866. if (!spawn) {
  4867. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4868. return 0;
  4869. }
  4870. // Check to make sure the spawn is an entity
  4871. if (!spawn->IsEntity()) {
  4872. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4873. return 0;
  4874. }
  4875. // Check to make sure the spawn doesn't already have a pet of this type
  4876. if (((Entity*)spawn)->GetPet()) {
  4877. if (spawn->IsPlayer()) {
  4878. Client* client = ((Player*)spawn)->GetClient();
  4879. if (client)
  4880. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4881. }
  4882. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4883. return 0;
  4884. }
  4885. // Check to see if the DB ID for the pet is set
  4886. if (pet_id == 0) {
  4887. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4888. return 0;
  4889. }
  4890. // Check to see if the pointer to the spell is valid
  4891. if (!luaspell) {
  4892. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4893. return 0;
  4894. }
  4895. if(luaspell->resisted) {
  4896. return 0;
  4897. }
  4898. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4899. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4900. if (!pet) {
  4901. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4902. return 0;
  4903. }
  4904. // Check to make sure the pet is an npc
  4905. if (!pet->IsNPC()) {
  4906. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4907. return 0;
  4908. }
  4909. // Spawn the pet at the same location as the owner
  4910. pet->SetX(spawn->GetX());
  4911. pet->SetY(spawn->GetY());
  4912. pet->SetZ(spawn->GetZ());
  4913. pet->SetLocation(spawn->GetLocation());
  4914. pet->SetHeading(spawn->GetHeading());
  4915. std::string petName = std::string("");
  4916. if(spawn->IsEntity()) {
  4917. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4918. }
  4919. if(petName.size() < 1) {
  4920. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4921. petName = spawn->GetZone()->pet_names.at(rand_index);
  4922. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4923. }
  4924. // If player set various values for the char sheet (pet window)
  4925. if (spawn->IsPlayer()) {
  4926. Player* player = (Player*)spawn;
  4927. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4928. player->GetInfoStruct()->set_pet_name(petName);
  4929. player->GetInfoStruct()->set_pet_movement(2);
  4930. player->GetInfoStruct()->set_pet_behavior(3);
  4931. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4932. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4933. // Make sure the values get sent to the client
  4934. player->SetCharSheetChanged(true);
  4935. }
  4936. // Set the pets name
  4937. pet->SetName(petName.c_str());
  4938. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4939. if (max_level > 0)
  4940. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4941. else
  4942. pet->SetLevel(spawn->GetLevel());
  4943. // Set the max level this pet can reach
  4944. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4945. ((NPC*)pet)->UpdateWeapons();
  4946. // Set the faction of the pet to the same faction as the owner
  4947. pet->SetFactionID(spawn->GetFactionID());
  4948. // Set the spawn as a pet
  4949. pet->SetPet(true);
  4950. // Give a pointer of the owner to the pet
  4951. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4952. // Give a pointer of the pet to the owner
  4953. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4954. // Set the pet type
  4955. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4956. // Set the spell id used to create this pet
  4957. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4958. // Set the spell tier used to create this pet
  4959. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4960. // Set the pets spawn type to 6
  4961. pet->SetSpawnType(6);
  4962. // Set the pets brain
  4963. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4964. // Check to see if the pet has a subtitle
  4965. if (strlen(pet->GetSubTitle()) > 0) {
  4966. // Add the players name to the front of the sub title
  4967. string pet_subtitle;
  4968. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4969. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4970. // Set the pets subtitle to the new one
  4971. pet->SetSubTitle(pet_subtitle.c_str());
  4972. }
  4973. // Add the "Pet Options" entity command to the pet
  4974. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4975. const char* spawn_script = world.GetSpawnScript(pet_id);
  4976. bool runScript = false;
  4977. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4978. runScript = true;
  4979. pet->SetSpawnScript(string(spawn_script));
  4980. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  4981. }
  4982. spawn->GetZone()->AddSpawn(pet);
  4983. if(runScript){
  4984. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  4985. }
  4986. // Set the pet as the return value for this function
  4987. lua_interface->SetSpawnValue(state, pet);
  4988. return 1;
  4989. }
  4990. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4991. if (!lua_interface)
  4992. return 0;
  4993. Spawn* spawn = lua_interface->GetSpawn(state);
  4994. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4995. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4996. lua_interface->ResetFunctionStack(state);
  4997. if (!spawn) {
  4998. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4999. return 0;
  5000. }
  5001. if (!spawn->IsEntity()) {
  5002. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5003. return 0;
  5004. }
  5005. if (((Entity*)spawn)->GetDeityPet()) {
  5006. if (spawn->IsPlayer()) {
  5007. Client* client = ((Player*)spawn)->GetClient();
  5008. if (client)
  5009. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5010. }
  5011. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. if (pet_id == 0) {
  5015. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5016. return 0;
  5017. }
  5018. if (!luaspell) {
  5019. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5020. return 0;
  5021. }
  5022. if(luaspell->resisted) {
  5023. return 0;
  5024. }
  5025. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5026. if (!pet) {
  5027. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5028. return 0;
  5029. }
  5030. if (!pet->IsNPC()) {
  5031. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5032. return 0;
  5033. }
  5034. pet->SetX(spawn->GetX());
  5035. pet->SetY(spawn->GetY());
  5036. pet->SetZ(spawn->GetZ());
  5037. pet->SetLocation(spawn->GetLocation());
  5038. pet->SetHeading(spawn->GetHeading());
  5039. spawn->GetZone()->AddSpawn(pet);
  5040. string random_pet_name;
  5041. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5042. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5043. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5044. pet->SetName(random_pet_name.c_str());
  5045. pet->SetLevel(spawn->GetLevel());
  5046. pet->SetFactionID(spawn->GetFactionID());
  5047. pet->SetPet(true);
  5048. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5049. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5050. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5051. pet->SetSpawnType(6);
  5052. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5053. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5054. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5055. if (strlen(pet->GetSubTitle()) > 0) {
  5056. string pet_subtitle;
  5057. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5058. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5059. pet->SetSubTitle(pet_subtitle.c_str());
  5060. }
  5061. // deity and cosmetic pets are not attackable
  5062. pet->SetAttackable(false);
  5063. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5064. lua_interface->SetSpawnValue(state, pet);
  5065. return 1;
  5066. }
  5067. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5068. if (!lua_interface)
  5069. return 0;
  5070. Spawn* spawn = lua_interface->GetSpawn(state);
  5071. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5072. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5073. lua_interface->ResetFunctionStack(state);
  5074. if (!spawn) {
  5075. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5076. return 0;
  5077. }
  5078. if (!spawn->IsEntity()) {
  5079. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5080. return 0;
  5081. }
  5082. if (((Entity*)spawn)->GetCosmeticPet()) {
  5083. if (spawn->IsPlayer()) {
  5084. Client* client = ((Player*)spawn)->GetClient();
  5085. if (client)
  5086. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5087. }
  5088. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5089. return 0;
  5090. }
  5091. if (pet_id == 0) {
  5092. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5093. return 0;
  5094. }
  5095. if (!luaspell) {
  5096. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5097. return 0;
  5098. }
  5099. if(luaspell->resisted) {
  5100. return 0;
  5101. }
  5102. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5103. if (!pet) {
  5104. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5105. return 0;
  5106. }
  5107. if (!pet->IsNPC()) {
  5108. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5109. return 0;
  5110. }
  5111. pet->SetX(spawn->GetX());
  5112. pet->SetY(spawn->GetY());
  5113. pet->SetZ(spawn->GetZ());
  5114. pet->SetLocation(spawn->GetLocation());
  5115. pet->SetHeading(spawn->GetHeading());
  5116. spawn->GetZone()->AddSpawn(pet);
  5117. string random_pet_name;
  5118. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5119. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5120. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5121. pet->SetName(random_pet_name.c_str());
  5122. pet->SetLevel(spawn->GetLevel());
  5123. pet->SetFactionID(spawn->GetFactionID());
  5124. pet->SetPet(true);
  5125. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5126. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5127. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5128. pet->SetSpawnType(6);
  5129. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5130. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5131. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5132. if (strlen(pet->GetSubTitle()) > 0) {
  5133. string pet_subtitle;
  5134. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5135. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5136. pet->SetSubTitle(pet_subtitle.c_str());
  5137. }
  5138. pet->SetAttackable(false);
  5139. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5140. lua_interface->SetSpawnValue(state, pet);
  5141. return 1;
  5142. }
  5143. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5144. if (!lua_interface)
  5145. return 0;
  5146. Spawn* spawn = lua_interface->GetSpawn(state);
  5147. lua_interface->ResetFunctionStack(state);
  5148. if (!spawn) {
  5149. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5150. return 0;
  5151. }
  5152. if (!spawn->IsPet()) {
  5153. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5154. return 0;
  5155. }
  5156. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5157. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Quest* quest = lua_interface->GetQuest(state);
  5164. if (!quest) {
  5165. 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));
  5166. lua_interface->ResetFunctionStack(state);
  5167. return 0;
  5168. }
  5169. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5170. lua_interface->ResetFunctionStack(state);
  5171. if (feather_color > 0)
  5172. quest->SetFeatherColor(feather_color);
  5173. return 0;
  5174. }
  5175. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5176. if (!lua_interface)
  5177. return 0;
  5178. Spawn* spawn = lua_interface->GetSpawn(state);
  5179. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5180. lua_interface->ResetFunctionStack(state);
  5181. if (!spawn) {
  5182. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5183. return 0;
  5184. }
  5185. if (!spawn2) {
  5186. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5187. return 0;
  5188. }
  5189. spawn->RemoveSpawnAccess(spawn2);
  5190. return 0;
  5191. }
  5192. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5193. if (!lua_interface)
  5194. return 0;
  5195. ZoneServer* zone = lua_interface->GetZone(state);
  5196. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5197. lua_interface->ResetFunctionStack(state);
  5198. if (!zone) {
  5199. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5200. return 0;
  5201. }
  5202. if (location_id == 0) {
  5203. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5204. return 0;
  5205. }
  5206. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5207. if (!location) {
  5208. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5209. return 0;
  5210. }
  5211. Spawn* spawn = 0;
  5212. if (location->entities[0]) {
  5213. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5214. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5215. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5216. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5217. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5218. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5219. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5220. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5221. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5222. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5223. if(spawn && spawn->IsOmittedByDBFlag())
  5224. {
  5225. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5226. safe_delete(spawn);
  5227. spawn = 0;
  5228. return 0;
  5229. }
  5230. if (spawn) {
  5231. const char* script = 0;
  5232. for (int x = 0; x < 3; x++) {
  5233. switch (x) {
  5234. case 0:
  5235. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5236. break;
  5237. case 1:
  5238. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5239. break;
  5240. case 2:
  5241. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5242. break;
  5243. }
  5244. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5245. spawn->SetSpawnScript(string(script));
  5246. break;
  5247. }
  5248. }
  5249. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5250. lua_interface->SetSpawnValue(state, spawn);
  5251. return 1;
  5252. }
  5253. else {
  5254. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5255. safe_delete(spawn);
  5256. }
  5257. }
  5258. return 0;
  5259. }
  5260. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5261. if (!lua_interface)
  5262. return 0;
  5263. Spawn* caster = lua_interface->GetSpawn(state);
  5264. Spawn* target = lua_interface->GetSpawn(state, 2);
  5265. int32 id = lua_interface->GetInt32Value(state, 3);
  5266. string command = lua_interface->GetStringValue(state, 4);
  5267. lua_interface->ResetFunctionStack(state);
  5268. if (!caster) {
  5269. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5270. return 0;
  5271. }
  5272. if (!target) {
  5273. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5274. return 0;
  5275. }
  5276. if (!caster->IsPlayer()) {
  5277. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5278. return 0;
  5279. }
  5280. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5281. if (!entity_command) {
  5282. 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());
  5283. return 0;
  5284. }
  5285. Client* client = ((Player*)caster)->GetClient();
  5286. if (!client) {
  5287. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5288. return 0;
  5289. }
  5290. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5291. return 0;
  5292. }
  5293. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5294. if (!lua_interface)
  5295. return 0;
  5296. Spawn* spawn = lua_interface->GetSpawn(state);
  5297. lua_interface->ResetFunctionStack(state);
  5298. if (!spawn) {
  5299. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5300. return 0;
  5301. }
  5302. if (!spawn->IsNPC()) {
  5303. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5304. return 0;
  5305. }
  5306. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5307. return 0;
  5308. }
  5309. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5310. if (!lua_interface)
  5311. return 0;
  5312. Spawn* spawn = lua_interface->GetSpawn(state);
  5313. int16 tick = lua_interface->GetInt16Value(state, 2);
  5314. lua_interface->ResetFunctionStack(state);
  5315. if (!spawn) {
  5316. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5317. return 0;
  5318. }
  5319. if (!spawn->IsNPC()) {
  5320. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5321. return 0;
  5322. }
  5323. if (tick < 20) {
  5324. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5325. return 0;
  5326. }
  5327. ((NPC*)spawn)->Brain()->SetTick(tick);
  5328. return 0;
  5329. }
  5330. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5331. if (!lua_interface)
  5332. return 0;
  5333. Spawn* spawn = lua_interface->GetSpawn(state);
  5334. Spawn* target = lua_interface->GetSpawn(state, 2);
  5335. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5336. lua_interface->ResetFunctionStack(state);
  5337. if (!spawn) {
  5338. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5339. return 0;
  5340. }
  5341. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5342. spawn->SetFollowTarget(target, follow_distance);
  5343. return 0;
  5344. }
  5345. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5346. if (!lua_interface)
  5347. return 0;
  5348. Spawn* spawn = lua_interface->GetSpawn(state);
  5349. lua_interface->ResetFunctionStack(state);
  5350. if (!spawn) {
  5351. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5352. return 0;
  5353. }
  5354. Spawn* target = spawn->GetFollowTarget();
  5355. if (target) {
  5356. lua_interface->SetSpawnValue(state, target);
  5357. return 1;
  5358. }
  5359. return 0;
  5360. }
  5361. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5362. if (!lua_interface)
  5363. return 0;
  5364. Spawn* spawn = lua_interface->GetSpawn(state);
  5365. lua_interface->ResetFunctionStack(state);
  5366. if (!spawn) {
  5367. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. if (spawn->following)
  5371. spawn->following = false;
  5372. else
  5373. spawn->following = true;
  5374. return 0;
  5375. }
  5376. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5377. if (!lua_interface)
  5378. return 0;
  5379. Spawn* spawn = lua_interface->GetSpawn(state);
  5380. lua_interface->ResetFunctionStack(state);
  5381. if (!spawn) {
  5382. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5383. return 0;
  5384. }
  5385. lua_interface->SetBooleanValue(state, spawn->following);
  5386. return 1;
  5387. }
  5388. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5389. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5390. // I will attempt to explain how this function works for future refrence
  5391. // Fist lets make sure lua_interface is valid, if not return out
  5392. if (!lua_interface)
  5393. return 0;
  5394. // Next we grab the first 2 params same as we usually would
  5395. Spawn* spawn = lua_interface->GetSpawn(state);
  5396. string var = lua_interface->GetStringValue(state, 2);
  5397. // 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
  5398. // 1 = Spawn
  5399. // 2 = Zone
  5400. // 3 = Item
  5401. // 4 = Quest
  5402. // 5 = String
  5403. // 6 = nil (null)
  5404. int8 dataType = 0;
  5405. // Define pointers for each potential type
  5406. Spawn* spawnVal = 0;
  5407. ZoneServer* zone = 0;
  5408. Item* item = 0;
  5409. Quest* quest = 0;
  5410. string val;
  5411. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5412. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5413. // options window are also light user data be we do not handle those.
  5414. // We check with lua_islightuserdata(lua_State*, index)
  5415. if (lua_islightuserdata(state, 3)) {
  5416. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5417. // and convert it to LUAUserData*
  5418. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5419. // Check to make sure the data we got is valid, if not give an error
  5420. if (!data || !data->IsCorrectlyInitialized()) {
  5421. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5422. }
  5423. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5424. else if (data->IsSpawn()) {
  5425. spawnVal = data->spawn;
  5426. dataType = 1;
  5427. }
  5428. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5429. else if (data->IsZone()) {
  5430. zone = data->zone;
  5431. dataType = 2;
  5432. }
  5433. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5434. else if (data->IsItem()) {
  5435. item = data->item;
  5436. dataType = 3;
  5437. }
  5438. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5439. else if (data->IsQuest()) {
  5440. quest = data->quest;
  5441. dataType = 4;
  5442. }
  5443. }
  5444. // Wasn't light user data, check if it is nil(null)
  5445. else if (lua_isnil(state, 3)) {
  5446. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5447. dataType = 6;
  5448. }
  5449. // Wasn't light user data or nil (null), must be a string
  5450. else {
  5451. // Set the string and dataType variable
  5452. val = lua_interface->GetStringValue(state, 3);
  5453. dataType = 5;
  5454. }
  5455. lua_interface->ResetFunctionStack(state);
  5456. // We now have all the params, lets check to make sure they are valid
  5457. if (!spawn) {
  5458. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5459. return 0;
  5460. }
  5461. if (var.length() == 0) {
  5462. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5463. return 0;
  5464. }
  5465. if (dataType == 0) {
  5466. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5467. return 0;
  5468. }
  5469. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5470. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5471. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5472. switch (dataType) {
  5473. case 1:
  5474. // 1 = Spawn
  5475. spawn->AddTempVariable(var, spawnVal);
  5476. break;
  5477. case 2:
  5478. // 2 = Zone
  5479. spawn->AddTempVariable(var, zone);
  5480. break;
  5481. case 3:
  5482. // 3 = Item
  5483. spawn->AddTempVariable(var, item);
  5484. break;
  5485. case 4:
  5486. // 4 = Quest
  5487. spawn->AddTempVariable(var, quest);
  5488. break;
  5489. case 5:
  5490. // 5 = String
  5491. spawn->AddTempVariable(var, val);
  5492. break;
  5493. case 6:
  5494. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5495. spawn->DeleteTempVariable(var);
  5496. break;
  5497. }
  5498. // And we are done so return out
  5499. return 0;
  5500. }
  5501. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5502. if (!lua_interface)
  5503. return 0;
  5504. Spawn* spawn = lua_interface->GetSpawn(state);
  5505. string var = lua_interface->GetStringValue(state, 2);
  5506. lua_interface->ResetFunctionStack(state);
  5507. if (!spawn) {
  5508. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5509. return 0;
  5510. }
  5511. if (var.length() == 0) {
  5512. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5513. return 0;
  5514. }
  5515. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5516. int8 type = spawn->GetTempVariableType(var);
  5517. Spawn* spawn2 = 0;
  5518. ZoneServer* zone = 0;
  5519. Item* item = 0;
  5520. Quest* quest = 0;
  5521. // Set the lua function return value based on the type of data the variable contains
  5522. switch (type) {
  5523. case 1:
  5524. spawn2 = spawn->GetTempVariableSpawn(var);
  5525. if (!spawn2)
  5526. return 0;
  5527. lua_interface->SetSpawnValue(state, spawn2);
  5528. break;
  5529. case 2:
  5530. zone = spawn->GetTempVariableZone(var);
  5531. if (!zone)
  5532. return 0;
  5533. lua_interface->SetZoneValue(state, zone);
  5534. break;
  5535. case 3:
  5536. item = spawn->GetTempVariableItem(var);
  5537. if (!item)
  5538. return 0;
  5539. lua_interface->SetItemValue(state, item);
  5540. break;
  5541. case 4:
  5542. quest = spawn->GetTempVariableQuest(var);
  5543. if (!quest)
  5544. return 0;
  5545. lua_interface->SetQuestValue(state, quest);
  5546. break;
  5547. case 5:
  5548. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5549. break;
  5550. default:
  5551. // Not a valid type then the variable was not set so return out
  5552. return 0;
  5553. }
  5554. // Return value was set so return out
  5555. return 1;
  5556. }
  5557. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5558. {
  5559. if (!lua_interface)
  5560. return 0;
  5561. Quest* quest = lua_interface->GetQuest(state);
  5562. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5563. string description = lua_interface->GetStringValue(state, 3);
  5564. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5565. if (!quest) {
  5566. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5567. lua_interface->ResetFunctionStack(state);
  5568. lua_interface->SetBooleanValue(state, false);
  5569. return 1;
  5570. }
  5571. if (!spawn) {
  5572. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5573. lua_interface->ResetFunctionStack(state);
  5574. lua_interface->SetBooleanValue(state, false);
  5575. return 1;
  5576. }
  5577. if (!spawn->IsPlayer()) {
  5578. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5579. lua_interface->ResetFunctionStack(state);
  5580. lua_interface->SetBooleanValue(state, false);
  5581. return 1;
  5582. }
  5583. if (item_id == 0) {
  5584. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5585. lua_interface->ResetFunctionStack(state);
  5586. lua_interface->SetBooleanValue(state, false);
  5587. return 1;
  5588. }
  5589. Client* client = ((Player*)spawn)->GetClient();
  5590. if (!client) {
  5591. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5592. lua_interface->ResetFunctionStack(state);
  5593. lua_interface->SetBooleanValue(state, false);
  5594. return 1;
  5595. }
  5596. Item* item = master_item_list.GetItem(item_id);
  5597. if (!item) {
  5598. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5599. lua_interface->ResetFunctionStack(state);
  5600. lua_interface->SetBooleanValue(state, false);
  5601. return 1;
  5602. }
  5603. Item* firstItem = new Item(item);
  5604. quest->AddTmpRewardItem(firstItem);
  5605. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5606. bool itemsAddedSuccessfully = true;
  5607. if(num_args > 4)
  5608. {
  5609. for(int8 n=5;n<num_args+1;n++)
  5610. {
  5611. int32 new_item = lua_interface->GetInt32Value(state, n);
  5612. Item* tmpItem = master_item_list.GetItem(new_item);
  5613. if(tmpItem)
  5614. {
  5615. Item* newTmpItem = new Item(tmpItem);
  5616. quest->AddTmpRewardItem(newTmpItem);
  5617. }
  5618. else
  5619. itemsAddedSuccessfully = false;
  5620. }
  5621. }
  5622. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5623. lua_interface->ResetFunctionStack(state);
  5624. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5625. return 1;
  5626. }
  5627. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5628. if (!lua_interface)
  5629. return 0;
  5630. Quest* quest = lua_interface->GetQuest(state);
  5631. lua_interface->ResetFunctionStack(state);
  5632. if (!quest) {
  5633. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. quest->SetRepeatable(true);
  5637. return 0;
  5638. }
  5639. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5640. if (!lua_interface)
  5641. return 0;
  5642. Spawn* spawn = lua_interface->GetSpawn(state);
  5643. lua_interface->ResetFunctionStack(state);
  5644. if (!spawn) {
  5645. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5649. string ret = classes.GetClassNameCase(base_class);
  5650. if (ret.length() > 0) {
  5651. lua_interface->SetStringValue(state, ret.c_str());
  5652. return 1;
  5653. }
  5654. return 0;
  5655. }
  5656. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5657. if (!lua_interface)
  5658. return 0;
  5659. Spawn* player = lua_interface->GetSpawn(state);
  5660. lua_interface->ResetFunctionStack(state);
  5661. if (player && player->IsPlayer()) {
  5662. Client* client = player->GetClient();
  5663. if (client)
  5664. client->SendWaypoints();
  5665. }
  5666. return 0;
  5667. }
  5668. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5669. if (!lua_interface)
  5670. return 0;
  5671. Spawn* player = lua_interface->GetSpawn(state);
  5672. string name = lua_interface->GetStringValue(state, 2);
  5673. int32 type = lua_interface->GetInt32Value(state, 3);
  5674. lua_interface->ResetFunctionStack(state);
  5675. if (type == 0)
  5676. type = 2;
  5677. if (name.length() > 0) {
  5678. if (player && player->IsPlayer()) {
  5679. Client* client = player->GetClient();
  5680. if (client)
  5681. client->AddWaypoint(name, type);
  5682. }
  5683. }
  5684. return 0;
  5685. }
  5686. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5687. if (!lua_interface)
  5688. return 0;
  5689. Spawn* player = lua_interface->GetSpawn(state);
  5690. string name = lua_interface->GetStringValue(state, 2);
  5691. lua_interface->ResetFunctionStack(state);
  5692. if (name.length() > 0) {
  5693. if (player && player->IsPlayer()) {
  5694. Client* client = player->GetClient();
  5695. if (client)
  5696. client->RemoveWaypoint(name);
  5697. }
  5698. }
  5699. return 0;
  5700. }
  5701. int EQ2Emu_lua_AddWard(lua_State* state) {
  5702. if (!lua_interface)
  5703. return 0;
  5704. int32 damage = lua_interface->GetInt32Value(state);
  5705. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5706. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5707. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5708. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5709. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5710. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5711. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5712. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5713. lua_interface->ResetFunctionStack(state);
  5714. if(!spell || spell->resisted) {
  5715. return 0;
  5716. }
  5717. bool ward_was_added = false;
  5718. ZoneServer* zone = spell->caster->GetZone();
  5719. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5720. for (int32 i = 0; i < spell->targets.size(); i++) {
  5721. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5722. if (!target)
  5723. continue;
  5724. if (target->IsEntity()) {
  5725. // If the ward is already active remove it
  5726. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5727. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5728. // Create new ward info
  5729. WardInfo* ward = new WardInfo;
  5730. ward->Spell = spell;
  5731. ward->BaseDamage = damage;
  5732. ward->DamageLeft = damage;
  5733. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5734. ward->keepWard = keepWard;
  5735. ward->WardType = wardType;
  5736. if (damageAbsorptionPercent > 100)
  5737. damageAbsorptionPercent = 100;
  5738. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5739. if (damageAbsorptionMaxHealthPercent > 100)
  5740. damageAbsorptionMaxHealthPercent = 100;
  5741. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5742. ward->RedirectDamagePercent = redirectDamagePercent;
  5743. ward->LastRedirectDamage = 0;
  5744. ward->LastAbsorbedDamage = 0;
  5745. ward->HitCount = 0;
  5746. spell->num_triggers = maxHitCount;
  5747. spell->had_triggers = true;
  5748. spell->cancel_after_all_triggers = false;
  5749. ward->MaxHitCount = maxHitCount;
  5750. ward->RoundTriggered = false;
  5751. if (wardType == WARD_TYPE_MAGICAL)
  5752. ward->DamageType = damageTypes;
  5753. // Add the ward to the entity
  5754. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5755. ward_was_added = true;
  5756. }
  5757. }
  5758. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5759. if (ward_was_added && spell->caster->IsPlayer()) {
  5760. spell->had_dmg_remaining = true;
  5761. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5762. }
  5763. return 0;
  5764. }
  5765. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5766. if (!lua_interface)
  5767. return 0;
  5768. int32 amount = lua_interface->GetInt32Value(state);
  5769. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5770. lua_interface->ResetFunctionStack(state);
  5771. WardInfo* ward = 0;
  5772. if(!spell || spell->resisted) {
  5773. return 0;
  5774. }
  5775. ZoneServer* zone = spell->caster->GetZone();
  5776. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5777. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5778. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5779. ward = target->GetWard(spell->spell->GetSpellID());
  5780. if (target && ward) {
  5781. ward->DamageLeft += amount;
  5782. if (ward->DamageLeft > ward->BaseDamage)
  5783. ward->DamageLeft = ward->BaseDamage;
  5784. for (int32 i = 0; i < spell->targets.size(); i++) {
  5785. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5786. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5787. }
  5788. }
  5789. }
  5790. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5791. if (ward && spell->caster->IsPlayer())
  5792. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5793. return 0;
  5794. }
  5795. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5796. if (!lua_interface)
  5797. return 0;
  5798. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5799. lua_interface->ResetFunctionStack(state);
  5800. if (!spell) {
  5801. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5802. return 0;
  5803. }
  5804. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5805. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5806. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5807. if (ward) {
  5808. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5809. return 1;
  5810. }
  5811. }
  5812. return 0;
  5813. }
  5814. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5815. if (!lua_interface)
  5816. return 0;
  5817. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5818. if (!spell) {
  5819. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5820. lua_interface->ResetFunctionStack(state);
  5821. return 0;
  5822. }
  5823. string type = lua_interface->GetStringValue(state, 2);
  5824. lua_interface->ResetFunctionStack(state);
  5825. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5826. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5827. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5828. if (ward) {
  5829. if (boost::iequals(type, "damageleft"))
  5830. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5831. else if (boost::iequals(type, "basedamage"))
  5832. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5833. else if (boost::iequals(type, "keepward"))
  5834. lua_interface->SetBooleanValue(state, ward->keepWard);
  5835. else if (boost::iequals(type, "wardtype"))
  5836. lua_interface->SetInt32Value(state, ward->WardType);
  5837. else if (boost::iequals(type, "dmgabsorptionpct"))
  5838. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5839. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5840. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5841. else if (boost::iequals(type, "redirectdamagepercent"))
  5842. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5843. else if (boost::iequals(type, "lastredirectdamage"))
  5844. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5845. else if (boost::iequals(type, "lastabsorbeddamage"))
  5846. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5847. else if (boost::iequals(type, "hitcount"))
  5848. lua_interface->SetInt32Value(state, ward->HitCount);
  5849. else if (boost::iequals(type, "maxhitcount"))
  5850. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5851. else
  5852. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5853. return 1;
  5854. }
  5855. }
  5856. return 0;
  5857. }
  5858. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5859. if (!lua_interface)
  5860. return 0;
  5861. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5862. lua_interface->ResetFunctionStack(state);
  5863. if(!spell) {
  5864. return 0;
  5865. }
  5866. ZoneServer* zone = spell->caster->GetZone();
  5867. Spawn* target = 0;
  5868. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5869. for (int32 i = 0; i < spell->targets.size(); i++) {
  5870. target = zone->GetSpawnByID(spell->targets.at(i));
  5871. if (target && target->IsEntity()) {
  5872. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5873. }
  5874. }
  5875. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5876. return 0;
  5877. }
  5878. int EQ2Emu_lua_Interrupt(lua_State* state)
  5879. {
  5880. if (!lua_interface)
  5881. return 0;
  5882. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5883. Spawn* target = lua_interface->GetSpawn(state, 2);
  5884. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5885. lua_interface->ResetFunctionStack(state);
  5886. if (!caster)
  5887. {
  5888. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. if (!target)
  5892. {
  5893. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. if (!spell) {
  5897. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. if (!target->IsEntity() && !spell)
  5901. {
  5902. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5903. return 0;
  5904. }
  5905. if (!target && spell) {
  5906. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5907. for (int8 i = 0; i < spell->targets.size(); i++) {
  5908. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5909. if (!target || !target->IsEntity())
  5910. continue;
  5911. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5912. }
  5913. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5914. }
  5915. else
  5916. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5917. return 0;
  5918. }
  5919. int EQ2Emu_lua_Stealth(lua_State* state) {
  5920. if (!lua_interface)
  5921. return 0;
  5922. int8 type = lua_interface->GetInt8Value(state);
  5923. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5924. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5925. lua_interface->ResetFunctionStack(state);
  5926. if (!spell) {
  5927. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. ZoneServer* zone = spell->caster->GetZone();
  5931. if (spawn) {
  5932. if (spawn->IsEntity()) {
  5933. if (type == 1) {
  5934. ((Entity*)spawn)->AddStealthSpell(spell);
  5935. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5936. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5937. }
  5938. else if (type == 2) {
  5939. ((Entity*)spawn)->AddInvisSpell(spell);
  5940. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5941. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5942. }
  5943. return 0;
  5944. }
  5945. else {
  5946. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5947. return 0;
  5948. }
  5949. }
  5950. else {
  5951. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5952. for (int32 i = 0; i < spell->targets.size(); i++) {
  5953. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5954. if (!spawn || !spawn->IsEntity())
  5955. continue;
  5956. if (type == 1) {
  5957. ((Entity*)spawn)->AddStealthSpell(spell);
  5958. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5959. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5960. }
  5961. else if (type == 2) {
  5962. ((Entity*)spawn)->AddInvisSpell(spell);
  5963. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5964. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5965. }
  5966. else {
  5967. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5968. break;
  5969. }
  5970. }
  5971. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5972. }
  5973. return 0;
  5974. }
  5975. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5976. if (!lua_interface)
  5977. return 0;
  5978. Spawn* spawn = lua_interface->GetSpawn(state);
  5979. lua_interface->ResetFunctionStack(state);
  5980. if (!spawn) {
  5981. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5982. return 0;
  5983. }
  5984. if (spawn->IsEntity()) {
  5985. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5986. return 1;
  5987. }
  5988. else
  5989. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5990. return 0;
  5991. }
  5992. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. lua_interface->ResetFunctionStack(state);
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (spawn->IsEntity()) {
  6002. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6003. return 1;
  6004. }
  6005. else
  6006. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6010. if (!lua_interface)
  6011. return 0;
  6012. Spawn* player = lua_interface->GetSpawn(state);
  6013. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6014. lua_interface->ResetFunctionStack(state);
  6015. if (!player->IsPlayer()) {
  6016. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6017. return 0;
  6018. }
  6019. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6020. return 1;
  6021. }
  6022. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6023. if (!lua_interface)
  6024. return 0;
  6025. Spawn* spawn = lua_interface->GetSpawn(state);
  6026. int8 slot = lua_interface->GetInt8Value(state, 2);
  6027. lua_interface->ResetFunctionStack(state);
  6028. if (!spawn) {
  6029. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6030. return 0;
  6031. }
  6032. if (!spawn->IsEntity()) {
  6033. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6037. if (!item) {
  6038. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6039. return 0;
  6040. }
  6041. lua_interface->SetItemValue(state, item);
  6042. return 1;
  6043. }
  6044. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6045. if (!lua_interface)
  6046. return 0;
  6047. Spawn* player = lua_interface->GetSpawn(state);
  6048. int32 id = lua_interface->GetInt32Value(state, 2);
  6049. lua_interface->ResetFunctionStack(state);
  6050. if (!player) {
  6051. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6052. return 0;
  6053. }
  6054. if (!player->IsPlayer()) {
  6055. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6056. return 0;
  6057. }
  6058. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6059. if (!item) {
  6060. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6061. return 0;
  6062. }
  6063. lua_interface->SetItemValue(state, item);
  6064. return 1;
  6065. }
  6066. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6067. if (!lua_interface)
  6068. return 0;
  6069. Spawn* spawn = lua_interface->GetSpawn(state);
  6070. int8 slot = lua_interface->GetInt8Value(state, 2);
  6071. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6072. lua_interface->ResetFunctionStack(state);
  6073. if (!spawn) {
  6074. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. if (!spawn->IsEntity()) {
  6078. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6079. return 0;
  6080. }
  6081. Item* item = master_item_list.GetItem(item_id);
  6082. if (!item) {
  6083. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. Item* copy = new Item(item);
  6087. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6088. if(result)
  6089. {
  6090. ((Entity*)spawn)->SetEquipment(copy, slot);
  6091. spawn->vis_changed = true;
  6092. if(spawn->IsPlayer())
  6093. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6094. }
  6095. else
  6096. {
  6097. safe_delete(copy);
  6098. }
  6099. lua_interface->SetBooleanValue(state, result);
  6100. return 1;
  6101. }
  6102. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6103. if (!lua_interface)
  6104. return 0;
  6105. Spawn* spawn = lua_interface->GetSpawn(state);
  6106. int8 slot = lua_interface->GetInt8Value(state, 2);
  6107. Item* item = lua_interface->GetItem(state, 3);
  6108. lua_interface->ResetFunctionStack(state);
  6109. if (!spawn) {
  6110. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6111. return 0;
  6112. }
  6113. if (!spawn->IsEntity()) {
  6114. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6115. return 0;
  6116. }
  6117. if (!item) {
  6118. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6119. return 0;
  6120. }
  6121. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6122. if(result)
  6123. {
  6124. ((Entity*)spawn)->SetEquipment(item, slot);
  6125. spawn->vis_changed = true;
  6126. if(spawn->IsPlayer())
  6127. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6128. }
  6129. lua_interface->SetBooleanValue(state, result);
  6130. return 1;
  6131. }
  6132. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6133. if (!lua_interface)
  6134. return 0;
  6135. Spawn* spawn = lua_interface->GetSpawn(state);
  6136. int8 slot = lua_interface->GetInt8Value(state, 2);
  6137. 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
  6138. lua_interface->ResetFunctionStack(state);
  6139. if (!spawn) {
  6140. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6141. return 0;
  6142. }
  6143. if (!spawn->IsEntity()) {
  6144. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. if(slot >= NUM_SLOTS) {
  6148. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6149. return 0;
  6150. }
  6151. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6152. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6153. if(item) {
  6154. item->save_needed = true;
  6155. if(no_delete_item) {
  6156. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6157. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6158. }
  6159. else{
  6160. Client* client = ((Player*)spawn)->GetClient();
  6161. client->UnequipItem(item->details.index);
  6162. }
  6163. }
  6164. }
  6165. else
  6166. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6167. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6168. spawn->vis_changed = true;
  6169. if(spawn->IsPlayer())
  6170. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6171. lua_interface->SetBooleanValue(state, true);
  6172. return 1;
  6173. }
  6174. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6175. if (!lua_interface)
  6176. return 0;
  6177. Spawn* spawn = lua_interface->GetSpawn(state);
  6178. int8 slot = lua_interface->GetInt8Value(state, 2);
  6179. int16 type = lua_interface->GetInt16Value(state, 3);
  6180. int8 r = lua_interface->GetInt8Value(state, 4);
  6181. int8 g = lua_interface->GetInt8Value(state, 5);
  6182. int8 b = lua_interface->GetInt8Value(state, 6);
  6183. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6184. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6185. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6186. lua_interface->ResetFunctionStack(state);
  6187. if (!spawn) {
  6188. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. if (!spawn->IsEntity()) {
  6192. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6193. return 0;
  6194. }
  6195. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6196. spawn->vis_changed = true;
  6197. lua_interface->SetBooleanValue(state, true);
  6198. return 1;
  6199. }
  6200. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6201. if (!lua_interface)
  6202. return 0;
  6203. Spawn* player = lua_interface->GetSpawn(state);
  6204. int32 id = lua_interface->GetInt32Value(state, 2);
  6205. int8 count = lua_interface->GetInt8Value(state, 3);
  6206. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6207. lua_interface->ResetFunctionStack(state);
  6208. if (!player) {
  6209. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. if (!player->IsPlayer()) {
  6213. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. if (!count)
  6217. count = 1;
  6218. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6219. if (!item) {
  6220. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6221. return 0;
  6222. }
  6223. lua_interface->SetItemValue(state, item);
  6224. return 1;
  6225. }
  6226. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6227. if (!lua_interface)
  6228. return 0;
  6229. Spawn* spawn = lua_interface->GetSpawn(state);
  6230. int32 anim = lua_interface->GetInt32Value(state, 2);
  6231. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6232. int8 type = lua_interface->GetInt8Value(state, 4);
  6233. lua_interface->ResetFunctionStack(state);
  6234. if (!spawn) {
  6235. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (spawn2) {
  6239. if (spawn2->IsPlayer()) {
  6240. if (type != 1 && type != 2)
  6241. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6242. else
  6243. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6244. return 0;
  6245. }
  6246. else {
  6247. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6248. return 0;
  6249. }
  6250. }
  6251. else
  6252. spawn->GetZone()->PlayAnimation(spawn, anim);
  6253. return 0;
  6254. }
  6255. int EQ2Emu_lua_IsPet(lua_State* state) {
  6256. if (!lua_interface)
  6257. return 0;
  6258. Spawn* spawn = lua_interface->GetSpawn(state);
  6259. lua_interface->ResetFunctionStack(state);
  6260. if (!spawn) {
  6261. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6262. return 0;
  6263. }
  6264. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6265. return 1;
  6266. }
  6267. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6268. if (!lua_interface)
  6269. return 0;
  6270. Spawn* spawn = lua_interface->GetSpawn(state);
  6271. lua_interface->ResetFunctionStack(state);
  6272. if (!spawn) {
  6273. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. if (!spawn->IsNPC()) {
  6277. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6278. return 0;
  6279. }
  6280. if (((NPC*)spawn)->GetOwner()) {
  6281. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6282. return 1;
  6283. }
  6284. return 0;
  6285. }
  6286. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6287. if (!lua_interface)
  6288. return 0;
  6289. Spawn* spawn = lua_interface->GetSpawn(state);
  6290. Spawn* target = lua_interface->GetSpawn(state, 2);
  6291. lua_interface->ResetFunctionStack(state);
  6292. if (!spawn) {
  6293. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6294. return 0;
  6295. }
  6296. if (!spawn) {
  6297. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6298. return 0;
  6299. }
  6300. spawn->SetTarget(target);
  6301. return 0;
  6302. }
  6303. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6304. if (!lua_interface)
  6305. return 0;
  6306. Spawn* spawn = lua_interface->GetSpawn(state);
  6307. bool val = lua_interface->GetBooleanValue(state, 2);
  6308. lua_interface->ResetFunctionStack(state);
  6309. if (!spawn) {
  6310. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6311. return 0;
  6312. }
  6313. if (!spawn->IsEntity()) {
  6314. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6315. return 0;
  6316. }
  6317. ((Entity*)spawn)->InCombat(val);
  6318. if (val) {
  6319. spawn->ClearRunningLocations();
  6320. spawn->CalculateRunningLocation(true);
  6321. }
  6322. return 0;
  6323. }
  6324. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6325. if (!lua_interface)
  6326. return 0;
  6327. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6328. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6329. lua_interface->ResetFunctionStack(state);
  6330. if (!spawn1) {
  6331. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6332. return 0;
  6333. }
  6334. if (!spawn2) {
  6335. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6339. return 1;
  6340. }
  6341. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6342. if (!lua_interface)
  6343. return 0;
  6344. Spawn* spawn = lua_interface->GetSpawn(state);
  6345. lua_interface->ResetFunctionStack(state);
  6346. if (!spawn) {
  6347. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6348. return 0;
  6349. }
  6350. if (!spawn->IsNPC()) {
  6351. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6352. return 0;
  6353. }
  6354. ((NPC*)spawn)->ClearRunback();
  6355. return 0;
  6356. }
  6357. int EQ2Emu_lua_Runback(lua_State* state) {
  6358. if (!lua_interface)
  6359. return 0;
  6360. Spawn* spawn = lua_interface->GetSpawn(state);
  6361. lua_interface->ResetFunctionStack(state);
  6362. if (!spawn) {
  6363. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (!spawn->IsNPC()) {
  6367. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6368. return 0;
  6369. }
  6370. ((NPC*)spawn)->Runback();
  6371. return 0;
  6372. }
  6373. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6374. if (!lua_interface)
  6375. return 0;
  6376. Spawn* spawn = lua_interface->GetSpawn(state);
  6377. lua_interface->ResetFunctionStack(state);
  6378. if (!spawn) {
  6379. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6380. return 0;
  6381. }
  6382. if (!spawn->IsNPC()) {
  6383. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6384. return 0;
  6385. }
  6386. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6387. return 1;
  6388. }
  6389. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6390. if (!lua_interface)
  6391. return 0;
  6392. Spawn* spawn = lua_interface->GetSpawn(state);
  6393. lua_interface->ResetFunctionStack(state);
  6394. if (!spawn) {
  6395. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6396. return 0;
  6397. }
  6398. if (!spawn->IsEntity()) {
  6399. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6400. return 0;
  6401. }
  6402. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6403. return 1;
  6404. }
  6405. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6406. if (!lua_interface)
  6407. return 0;
  6408. Spawn* spawn = lua_interface->GetSpawn(state);
  6409. lua_interface->ResetFunctionStack(state);
  6410. if (!spawn) {
  6411. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6412. return 0;
  6413. }
  6414. if (!spawn->IsEntity()) {
  6415. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6416. return 0;
  6417. }
  6418. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6419. return 1;
  6420. }
  6421. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6422. if (!lua_interface)
  6423. return 0;
  6424. Spawn* spawn = lua_interface->GetSpawn(state);
  6425. lua_interface->ResetFunctionStack(state);
  6426. if (!spawn) {
  6427. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6428. return 0;
  6429. }
  6430. if (!spawn->IsEntity()) {
  6431. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6432. return 0;
  6433. }
  6434. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6435. return 1;
  6436. }
  6437. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6438. if (!lua_interface)
  6439. return 0;
  6440. Spawn* spawn = lua_interface->GetSpawn(state);
  6441. lua_interface->ResetFunctionStack(state);
  6442. if (!spawn) {
  6443. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. if (!spawn->IsEntity()) {
  6447. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6448. return 0;
  6449. }
  6450. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6451. return 1;
  6452. }
  6453. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6454. if (!lua_interface)
  6455. return 0;
  6456. Spawn* spawn = lua_interface->GetSpawn(state);
  6457. Spawn* target = lua_interface->GetSpawn(state, 2);
  6458. float distance = lua_interface->GetFloatValue(state, 3);
  6459. lua_interface->ResetFunctionStack(state);
  6460. if (!spawn) {
  6461. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. if (!target) {
  6465. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6466. return 0;
  6467. }
  6468. if (!spawn->IsNPC()) {
  6469. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. if (!target->IsEntity()) {
  6473. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6477. return 1;
  6478. }
  6479. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6480. if (!lua_interface)
  6481. return 0;
  6482. Spawn* spawn = lua_interface->GetSpawn(state);
  6483. Spawn* target = lua_interface->GetSpawn(state, 2);
  6484. float distance = lua_interface->GetFloatValue(state, 3);
  6485. lua_interface->ResetFunctionStack(state);
  6486. if (!spawn) {
  6487. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6488. return 0;
  6489. }
  6490. if (!target) {
  6491. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6492. return 0;
  6493. }
  6494. if (!spawn->IsNPC()) {
  6495. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6496. return 0;
  6497. }
  6498. if (!target->IsEntity()) {
  6499. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6500. return 0;
  6501. }
  6502. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6503. return 0;
  6504. }
  6505. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6506. if (!lua_interface)
  6507. return 0;
  6508. Spawn* spawn = lua_interface->GetSpawn(state);
  6509. lua_interface->ResetFunctionStack(state);
  6510. if (!spawn) {
  6511. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. if (!spawn->IsNPC()) {
  6515. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6516. return 0;
  6517. }
  6518. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6519. return 1;
  6520. }
  6521. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6522. if (!lua_interface)
  6523. return 0;
  6524. Spawn* spawn = lua_interface->GetSpawn(state);
  6525. lua_interface->ResetFunctionStack(state);
  6526. if (!spawn) {
  6527. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. if (!spawn->IsNPC()) {
  6531. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6532. return 0;
  6533. }
  6534. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6535. return 1;
  6536. }
  6537. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6538. if (!lua_interface)
  6539. return 0;
  6540. Spawn* spawn = lua_interface->GetSpawn(state);
  6541. lua_interface->ResetFunctionStack(state);
  6542. if (!spawn) {
  6543. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. if (!spawn->IsNPC()) {
  6547. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6548. return 0;
  6549. }
  6550. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6551. if (hated) {
  6552. lua_interface->SetSpawnValue(state, hated);
  6553. return 1;
  6554. }
  6555. return 0;
  6556. }
  6557. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6558. if (!lua_interface)
  6559. return 0;
  6560. Spawn* spawn = lua_interface->GetSpawn(state);
  6561. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6562. lua_interface->ResetFunctionStack(state);
  6563. if (!spawn) {
  6564. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. if (!spawn->IsNPC()) {
  6568. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6569. return 0;
  6570. }
  6571. if (!hated) {
  6572. ((NPC*)spawn)->Brain()->ClearHate();
  6573. return 0;
  6574. }
  6575. else
  6576. {
  6577. if (!hated->IsEntity()) {
  6578. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6579. return 0;
  6580. }
  6581. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6582. return 0;
  6583. }
  6584. return 0;
  6585. }
  6586. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6587. if (!lua_interface)
  6588. return 0;
  6589. Spawn* spawn = lua_interface->GetSpawn(state);
  6590. lua_interface->ResetFunctionStack(state);
  6591. if (!spawn) {
  6592. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6593. return 0;
  6594. }
  6595. if (!spawn->IsNPC()) {
  6596. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6597. return 0;
  6598. }
  6599. ((NPC*)spawn)->Brain()->ClearEncounter();
  6600. return 0;
  6601. }
  6602. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6603. if (!lua_interface)
  6604. return 0;
  6605. Spawn* spawn = lua_interface->GetSpawn(state);
  6606. lua_interface->ResetFunctionStack(state);
  6607. if (!spawn) {
  6608. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. if (!spawn->IsNPC()) {
  6612. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. // Temp list to store hate list
  6616. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6617. if (encounterList->size() == 0) {
  6618. safe_delete(encounterList);
  6619. return 0;
  6620. }
  6621. lua_createtable(state, encounterList->size(), 0);
  6622. int newTable = lua_gettop(state);
  6623. for (int32 i = 0; i < encounterList->size(); i++) {
  6624. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6625. if (temp)
  6626. lua_interface->SetSpawnValue(state, temp);
  6627. lua_rawseti(state, newTable, i + 1);
  6628. }
  6629. safe_delete(encounterList);
  6630. return 1;
  6631. }
  6632. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6633. if (!lua_interface)
  6634. return 0;
  6635. Spawn* spawn = lua_interface->GetSpawn(state);
  6636. lua_interface->ResetFunctionStack(state);
  6637. if (!spawn) {
  6638. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. if (!spawn->IsNPC()) {
  6642. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6643. return 0;
  6644. }
  6645. // Temp list to store hate list
  6646. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6647. if (hateList->size() == 0) {
  6648. safe_delete(hateList);
  6649. return 0;
  6650. }
  6651. lua_createtable(state, hateList->size(), 0);
  6652. int newTable = lua_gettop(state);
  6653. for (int32 i = 0; i < hateList->size(); i++) {
  6654. lua_interface->SetSpawnValue(state, hateList->at(i));
  6655. lua_rawseti(state, newTable, i + 1);
  6656. }
  6657. safe_delete(hateList);
  6658. return 1;
  6659. }
  6660. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6661. if (!lua_interface)
  6662. return 0;
  6663. Spawn* spawn = lua_interface->GetSpawn(state);
  6664. lua_interface->ResetFunctionStack(state);
  6665. if (!spawn) {
  6666. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. if (spawn->IsPlayer()) {
  6670. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6671. lua_interface->SetBooleanValue(state, true);
  6672. else
  6673. lua_interface->SetBooleanValue(state, false);
  6674. return 1;
  6675. }
  6676. else {
  6677. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6678. return 1;
  6679. }
  6680. }
  6681. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6682. if (!lua_interface)
  6683. return 0;
  6684. Quest* quest = lua_interface->GetQuest(state);
  6685. lua_interface->ResetFunctionStack(state);
  6686. if (!quest) {
  6687. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6688. return 0;
  6689. }
  6690. quest->SetCompletedFlag(true);
  6691. return 0;
  6692. }
  6693. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6694. if (!lua_interface)
  6695. return 0;
  6696. Spawn* spawn = lua_interface->GetSpawn(state);
  6697. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6698. int8 tier = lua_interface->GetInt8Value(state, 3);
  6699. lua_interface->ResetFunctionStack(state);
  6700. if (!spawn) {
  6701. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (!spawn->IsEntity()) {
  6705. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. if (spellID == 0) {
  6709. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6710. return 0;
  6711. }
  6712. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6713. if (effect) {
  6714. if (tier > 0) {
  6715. // If a tier was passed chec to see if it is the same as the effect
  6716. if (tier == effect->tier)
  6717. lua_interface->SetBooleanValue(state, true);
  6718. else
  6719. lua_interface->SetBooleanValue(state, false);
  6720. return 1;
  6721. }
  6722. else {
  6723. // Have an effect but no tier was passed so return true
  6724. lua_interface->SetBooleanValue(state, true);
  6725. }
  6726. return 1;
  6727. }
  6728. // no effect so return false
  6729. lua_interface->SetBooleanValue(state, false);
  6730. return 1;
  6731. }
  6732. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6733. if (!lua_interface)
  6734. return 0;
  6735. Spawn* spawn = lua_interface->GetSpawn(state);
  6736. int32 id = lua_interface->GetInt32Value(state, 2);
  6737. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6738. lua_interface->ResetFunctionStack(state);
  6739. Spawn* spawn2 = 0;
  6740. vector<Spawn*> list;
  6741. if (!spawn) {
  6742. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6743. return 0;
  6744. }
  6745. //If zone not provided, use spawn's zone
  6746. if (!zone)
  6747. zone = spawn->GetZone();
  6748. list = zone->GetSpawnsByID(id);
  6749. if (list.size() == 0) {
  6750. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6751. return 0;
  6752. }
  6753. vector<Spawn*>::iterator itr = list.begin();
  6754. for (int8 i = 0; i < list.size(); i++) {
  6755. spawn2 = itr[i];
  6756. if (spawn2)
  6757. spawn2->AddAllowAccessSpawn(spawn);
  6758. }
  6759. return 0;
  6760. }
  6761. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6762. if (!lua_interface)
  6763. return 0;
  6764. Spawn* spawn = lua_interface->GetSpawn(state);
  6765. int32 id = lua_interface->GetInt32Value(state, 2);
  6766. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6767. lua_interface->ResetFunctionStack(state);
  6768. Spawn* spawn2 = 0;
  6769. if (!spawn) {
  6770. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. //If zone not provided, use spawn's zone
  6774. if (!zone)
  6775. zone = spawn->GetZone();
  6776. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6777. vector<Spawn*>::iterator itr = list.begin();
  6778. if (list.size() == 0) {
  6779. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. for (int8 i = 0; i < list.size(); i++) {
  6783. spawn2 = itr[i];
  6784. if (spawn2)
  6785. spawn2->RemoveSpawnAccess(spawn);
  6786. }
  6787. return 0;
  6788. }
  6789. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6790. if (!lua_interface)
  6791. return 0;
  6792. Quest* quest = lua_interface->GetQuest(state);
  6793. lua_interface->ResetFunctionStack(state);
  6794. if (!quest) {
  6795. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6796. return 0;
  6797. }
  6798. quest->SetYellowName(true);
  6799. return 0;
  6800. }
  6801. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6802. if (!lua_interface)
  6803. return 0;
  6804. Spawn* spawn = lua_interface->GetSpawn(state);
  6805. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6806. lua_interface->ResetFunctionStack(state);
  6807. if (!spawn) {
  6808. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6809. return 0;
  6810. }
  6811. if (!spawn->IsPlayer()) {
  6812. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6813. return 0;
  6814. }
  6815. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6816. return 1;
  6817. }
  6818. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6819. if (!lua_interface)
  6820. return 0;
  6821. Spawn* spawn = lua_interface->GetSpawn(state);
  6822. lua_interface->ResetFunctionStack(state);
  6823. if (!spawn) {
  6824. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. if (!spawn->IsPlayer()) {
  6828. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. ZoneServer* zone = spawn->GetZone();
  6832. if (!zone) {
  6833. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. Instance_Type iType = zone->GetInstanceType();
  6837. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6838. iType == GROUP_LOCKOUT_INSTANCE ||
  6839. iType == RAID_LOCKOUT_INSTANCE ||
  6840. iType == SOLO_PERSIST_INSTANCE ||
  6841. iType == GROUP_PERSIST_INSTANCE ||
  6842. iType == RAID_PERSIST_INSTANCE) {
  6843. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6844. if (data) {
  6845. // Check to see if the timer has already been set, if it has return out.
  6846. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6847. return 0;
  6848. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6849. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6850. if(spawn->IsPlayer()) {
  6851. Client* client = ((Player*)spawn)->GetClient();
  6852. if (client) {
  6853. string time_msg = "";
  6854. int32 time = data->success_lockout_time;
  6855. int16 hour;
  6856. int8 min;
  6857. int8 sec;
  6858. hour = time / 3600;
  6859. time = time % 3600;
  6860. min = time / 60;
  6861. time = time % 60;
  6862. sec = time;
  6863. if (hour > 0) {
  6864. char temp[10];
  6865. sprintf(temp, " %i", hour);
  6866. time_msg.append(temp);
  6867. time_msg.append(" hour");
  6868. time_msg.append((hour > 1) ? "s" : "");
  6869. }
  6870. if (min > 0) {
  6871. char temp[5];
  6872. sprintf(temp, " %i", min);
  6873. time_msg.append(temp);
  6874. time_msg.append(" minute");
  6875. time_msg.append((min > 1) ? "s" : "");
  6876. }
  6877. // Only add seconds if minutes and hours are 0
  6878. if (hour == 0 && min == 0 && sec > 0) {
  6879. char temp[5];
  6880. sprintf(temp, " %i", sec);
  6881. time_msg.append(temp);
  6882. time_msg.append(" second");
  6883. time_msg.append((sec > 1) ? "s" : "");
  6884. }
  6885. 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());
  6886. }
  6887. else {
  6888. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6889. }
  6890. }
  6891. }
  6892. else
  6893. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6894. }
  6895. else
  6896. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6897. return 0;
  6898. }
  6899. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6900. if (!lua_interface)
  6901. return 0;
  6902. Spawn* spawn = lua_interface->GetSpawn(state);
  6903. lua_interface->ResetFunctionStack(state);
  6904. if (!spawn) {
  6905. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6906. return 0;
  6907. }
  6908. if (!spawn->IsPlayer()) {
  6909. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6910. return 0;
  6911. }
  6912. ZoneServer* zone = spawn->GetZone();
  6913. if (!zone) {
  6914. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6915. return 0;
  6916. }
  6917. Instance_Type iType = zone->GetInstanceType();
  6918. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6919. iType == GROUP_LOCKOUT_INSTANCE ||
  6920. iType == RAID_LOCKOUT_INSTANCE ||
  6921. iType == SOLO_PERSIST_INSTANCE ||
  6922. iType == GROUP_PERSIST_INSTANCE ||
  6923. iType == RAID_PERSIST_INSTANCE) {
  6924. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6925. if (data) {
  6926. // Check to see if the timer has already been set, if it has return out.
  6927. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6928. return 0;
  6929. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6930. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6931. if(spawn->IsPlayer()) {
  6932. Client* client = ((Player*)spawn)->GetClient();
  6933. if (client) {
  6934. string time_msg = "";
  6935. int32 time = data->failure_lockout_time;
  6936. int16 hour;
  6937. int8 min;
  6938. int8 sec;
  6939. hour = time / 3600;
  6940. time = time % 3600;
  6941. min = time / 60;
  6942. time = time % 60;
  6943. sec = time;
  6944. if (hour > 0) {
  6945. char temp[10];
  6946. sprintf(temp, " %i", hour);
  6947. time_msg.append(temp);
  6948. time_msg.append(" hour");
  6949. time_msg.append((hour > 1) ? "s" : "");
  6950. }
  6951. if (min > 0) {
  6952. char temp[5];
  6953. sprintf(temp, " %i", min);
  6954. time_msg.append(temp);
  6955. time_msg.append(" minute");
  6956. time_msg.append((min > 1) ? "s" : "");
  6957. }
  6958. // Only add seconds if minutes and hours are 0
  6959. if (hour == 0 && min == 0 && sec > 0) {
  6960. char temp[5];
  6961. sprintf(temp, " %i", sec);
  6962. time_msg.append(temp);
  6963. time_msg.append(" second");
  6964. time_msg.append((sec > 1) ? "s" : "");
  6965. }
  6966. 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());
  6967. }
  6968. }
  6969. else {
  6970. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6971. }
  6972. }
  6973. else
  6974. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6975. }
  6976. else
  6977. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6978. return 0;
  6979. }
  6980. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6981. if (!lua_interface)
  6982. return 0;
  6983. Spawn* spawn = lua_interface->GetSpawn(state);
  6984. lua_interface->ResetFunctionStack(state);
  6985. if (!spawn) {
  6986. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6987. return 0;
  6988. }
  6989. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6990. return 1;
  6991. }
  6992. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6993. if (!lua_interface)
  6994. return 0;
  6995. Spawn* player = lua_interface->GetSpawn(state);
  6996. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6997. if (!player) {
  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 (!player->IsPlayer()) {
  7003. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7004. lua_interface->ResetFunctionStack(state);
  7005. return 0;
  7006. }
  7007. if (!ground) {
  7008. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7009. lua_interface->ResetFunctionStack(state);
  7010. return 0;
  7011. }
  7012. if (!ground->IsGroundSpawn()) {
  7013. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7014. lua_interface->ResetFunctionStack(state);
  7015. return 0;
  7016. }
  7017. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7018. if (!groundspawn_entries) {
  7019. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7020. lua_interface->ResetFunctionStack(state);
  7021. return 0;
  7022. }
  7023. Skill* skill = 0;
  7024. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7025. if (collection_skill == "Collecting")
  7026. skill = ((Player*)player)->GetSkillByName("Gathering");
  7027. else
  7028. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7029. if (!skill) {
  7030. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7031. lua_interface->ResetFunctionStack(state);
  7032. return 0;
  7033. }
  7034. vector<GroundSpawnEntry*>::iterator itr;
  7035. GroundSpawnEntry* entry = 0;
  7036. bool can_harvest = false;
  7037. sint32 min_skill = -1;
  7038. int16 totalSkill = skill->current_val;
  7039. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7040. if(skillID != 0xFFFFFFFF)
  7041. {
  7042. ((Entity*)player)->MStats.lock();
  7043. totalSkill += ((Entity*)player)->stats[skillID];
  7044. ((Entity*)player)->MStats.unlock();
  7045. }
  7046. // first, iterate through groundspawn_entries, discard tables player cannot use
  7047. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7048. {
  7049. entry = *itr;
  7050. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7051. min_skill = entry->min_skill_level;
  7052. // if player lacks skill, skip table
  7053. if (entry->min_skill_level > totalSkill)
  7054. continue;
  7055. // if bonus, but player lacks level, skip table
  7056. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7057. continue;
  7058. can_harvest = true;
  7059. break;
  7060. }
  7061. lua_interface->SetBooleanValue(state, can_harvest);
  7062. // If false, send the message to the client
  7063. if (!can_harvest) {
  7064. Client* client = ((Player*)player)->GetClient();
  7065. if (client) {
  7066. string msg = "You do not have enough skill to ";
  7067. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7068. msg.append("gather");
  7069. else if (collection_skill == "Mining")
  7070. msg.append("mine");
  7071. else if (collection_skill == "Trapping")
  7072. msg.append("trap");
  7073. else if (collection_skill == "Foresting")
  7074. msg.append("forest");
  7075. else if (collection_skill == "Fishing")
  7076. msg.append("catch");
  7077. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7078. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7079. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7080. }
  7081. }
  7082. lua_interface->ResetFunctionStack(state);
  7083. return 1;
  7084. }
  7085. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7086. if (!lua_interface)
  7087. return 0;
  7088. Spawn* player = lua_interface->GetSpawn(state);
  7089. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7090. lua_interface->ResetFunctionStack(state);
  7091. if (!player) {
  7092. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7093. return 0;
  7094. }
  7095. if (!player->IsPlayer()) {
  7096. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7097. return 0;
  7098. }
  7099. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7100. lua_interface->SetBooleanValue(state, ret);
  7101. return 1;
  7102. }
  7103. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7104. // Check to see if we have a valid lua_interface
  7105. if (!lua_interface)
  7106. return 0;
  7107. // Get the spawn that is getting the pet
  7108. Spawn* spawn = lua_interface->GetSpawn(state);
  7109. Spawn* target = lua_interface->GetSpawn(state, 2);
  7110. // Get the DB ID of the pet
  7111. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7112. float x = lua_interface->GetFloatValue(state, 4);
  7113. float y = lua_interface->GetFloatValue(state, 5);
  7114. float z = lua_interface->GetFloatValue(state, 6);
  7115. // Get the spell that this command was called from
  7116. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7117. lua_interface->ResetFunctionStack(state);
  7118. // Check to make sure the spawn pointer is valid
  7119. if (!spawn) {
  7120. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7121. return 0;
  7122. }
  7123. // Check to make sure the spawn is an entity
  7124. if (!spawn->IsEntity()) {
  7125. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. if (!target) {
  7129. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7130. return 0;
  7131. }
  7132. if (!target->IsEntity()) {
  7133. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. // Check to see if the DB ID for the pet is set
  7137. if (pet_id == 0) {
  7138. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7139. return 0;
  7140. }
  7141. // Check to see if the pointer to the spell is valid
  7142. if (!luaspell) {
  7143. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7144. return 0;
  7145. }
  7146. if(luaspell->resisted) {
  7147. return 0;
  7148. }
  7149. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7150. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7151. if (!pet) {
  7152. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7153. return 0;
  7154. }
  7155. // Check to make sure the pet is an npc
  7156. if (!pet->IsNPC()) {
  7157. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7158. return 0;
  7159. }
  7160. if (x == 0)
  7161. x = spawn->GetX();
  7162. if (y == 0)
  7163. y = spawn->GetY();
  7164. if (z == 0)
  7165. z = spawn->GetZ();
  7166. // Spawn the pet at the same location as the owner
  7167. pet->SetX(x);
  7168. pet->SetY(y);
  7169. pet->SetZ(z);
  7170. pet->SetLocation(spawn->GetLocation());
  7171. pet->SetHeading(spawn->GetHeading());
  7172. spawn->GetZone()->AddSpawn(pet);
  7173. const char* spawn_script = world.GetSpawnScript(pet_id);
  7174. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7175. spawn->SetSpawnScript(string(spawn_script));
  7176. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7177. }
  7178. std::string petName = std::string("");
  7179. if(spawn->IsEntity()) {
  7180. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7181. }
  7182. if(petName.size() < 1) {
  7183. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7184. petName = spawn->GetZone()->pet_names.at(rand_index);
  7185. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7186. }
  7187. // Set the pets name
  7188. pet->SetName(petName.c_str());
  7189. // Set the level of the pet to the owners level
  7190. pet->SetLevel(spawn->GetLevel());
  7191. // Set the faction of the pet to the same faction as the owner
  7192. pet->SetFactionID(spawn->GetFactionID());
  7193. // Set the spawn as a pet
  7194. pet->SetPet(true);
  7195. // Give a pointer of the owner to the pet
  7196. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7197. // Set the pet type
  7198. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7199. // Set the spell id used to create this pet
  7200. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7201. // Set the spell tier used to create this pet
  7202. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7203. // Set the pets spawn type to 6
  7204. pet->SetSpawnType(6);
  7205. // Set the pets brain
  7206. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7207. // Check to see if the pet has a subtitle
  7208. if (strlen(pet->GetSubTitle()) > 0) {
  7209. // Add the players name to the front of the sub title
  7210. string pet_subtitle;
  7211. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7212. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7213. // Set the pets subtitle to the new one
  7214. pet->SetSubTitle(pet_subtitle.c_str());
  7215. }
  7216. // Set the pet as the return value for this function
  7217. lua_interface->SetSpawnValue(state, pet);
  7218. return 1;
  7219. }
  7220. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7221. if (!lua_interface)
  7222. return 0;
  7223. Spawn* spawn = lua_interface->GetSpawn(state);
  7224. Spawn* player = lua_interface->GetSpawn(state, 2);
  7225. float max_distance = lua_interface->GetFloatValue(state, 3);
  7226. string type = lua_interface->GetStringValue(state, 4);
  7227. lua_interface->ResetFunctionStack(state);
  7228. if (!spawn || (spawn && spawn->IsPlayer())) {
  7229. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7230. return 0;
  7231. }
  7232. if (!player || !player->IsPlayer()) {
  7233. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7234. return 0;
  7235. }
  7236. Client* client = ((Player*)player)->GetClient();
  7237. if (!client) {
  7238. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7239. return 0;
  7240. }
  7241. //Set max_distance to default if not set or not proper value
  7242. if (max_distance <= 0)
  7243. max_distance = 500;
  7244. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7245. if (packet) {
  7246. float unknown2_3 = 0;
  7247. int8 placement_mode = 0;
  7248. if (type == "wall") {
  7249. placement_mode = 2;
  7250. unknown2_3 = 150;
  7251. }
  7252. else if (type == "ceiling")
  7253. placement_mode = 1;
  7254. packet->setDataByName("placement_mode", placement_mode);
  7255. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7256. packet->setDataByName("model_type", spawn->GetModelType());
  7257. packet->setDataByName("unknown", 1); //size
  7258. packet->setDataByName("unknown2", 1); //size 2
  7259. packet->setDataByName("unknown2", .5, 1); //size 3
  7260. packet->setDataByName("unknown2", 3, 2);
  7261. packet->setDataByName("unknown2", unknown2_3, 3);
  7262. packet->setDataByName("max_distance", max_distance);
  7263. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7264. client->QueuePacket(packet->serialize());
  7265. safe_delete(packet);
  7266. }
  7267. return 0;
  7268. }
  7269. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7270. if (!lua_interface)
  7271. return 0;
  7272. Item* item = lua_interface->GetItem(state);
  7273. lua_interface->ResetFunctionStack(state);
  7274. if (!item) {
  7275. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7276. return 0;
  7277. }
  7278. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7279. return 1;
  7280. }
  7281. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7282. if (!lua_interface)
  7283. return 0;
  7284. Item* item = lua_interface->GetItem(state);
  7285. lua_interface->ResetFunctionStack(state);
  7286. if (!item) {
  7287. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7288. return 0;
  7289. }
  7290. lua_interface->SetInt32Value(state, item->effect_type);
  7291. return 1;
  7292. }
  7293. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7294. if (!lua_interface)
  7295. return 0;
  7296. Spawn* spawn = lua_interface->GetSpawn(state);
  7297. lua_interface->ResetFunctionStack(state);
  7298. if (!spawn) {
  7299. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7300. return 0;
  7301. }
  7302. if (spawn->GetZone())
  7303. spawn->GetZone()->AddTransportSpawn(spawn);
  7304. return 0;
  7305. }
  7306. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7307. if (!lua_interface)
  7308. return 0;
  7309. Spawn* spawn = lua_interface->GetSpawn(state);
  7310. lua_interface->ResetFunctionStack(state);
  7311. if (!spawn) {
  7312. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7313. return 0;
  7314. }
  7315. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7316. return 1;
  7317. }
  7318. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7319. if (!lua_interface)
  7320. return 0;
  7321. Skill* skill = lua_interface->GetSkill(state);
  7322. lua_interface->ResetFunctionStack(state);
  7323. if (!skill) {
  7324. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7325. return 0;
  7326. }
  7327. lua_interface->SetInt32Value(state, skill->current_val);
  7328. return 1;
  7329. }
  7330. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7331. if (!lua_interface)
  7332. return 0;
  7333. Skill* skill = lua_interface->GetSkill(state);
  7334. lua_interface->ResetFunctionStack(state);
  7335. if (!skill) {
  7336. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7337. return 0;
  7338. }
  7339. lua_interface->SetInt32Value(state, skill->max_val);
  7340. return 1;
  7341. }
  7342. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7343. if (!lua_interface)
  7344. return 0;
  7345. Skill* skill = lua_interface->GetSkill(state);
  7346. lua_interface->ResetFunctionStack(state);
  7347. if (!skill) {
  7348. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7349. return 0;
  7350. }
  7351. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7352. return 1;
  7353. }
  7354. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7355. if (!lua_interface)
  7356. return 0;
  7357. Skill* skill = lua_interface->GetSkill(state);
  7358. int16 value = lua_interface->GetInt16Value(state, 2);
  7359. lua_interface->ResetFunctionStack(state);
  7360. if (!skill) {
  7361. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. skill->max_val = value;
  7365. if (skill->max_val < skill->current_val)
  7366. skill->current_val = skill->max_val;
  7367. return 0;
  7368. }
  7369. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7370. if (!lua_interface)
  7371. return 0;
  7372. Skill* skill = lua_interface->GetSkill(state);
  7373. int16 value = lua_interface->GetInt16Value(state, 2);
  7374. lua_interface->ResetFunctionStack(state);
  7375. if (!skill) {
  7376. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7377. return 0;
  7378. }
  7379. if (value > skill->max_val)
  7380. skill->current_val = skill->max_val;
  7381. else
  7382. skill->current_val = value;
  7383. return 0;
  7384. }
  7385. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7386. if (!lua_interface)
  7387. return 0;
  7388. Spawn* player = lua_interface->GetSpawn(state);
  7389. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7390. lua_interface->ResetFunctionStack(state);
  7391. if (skill_id > 0 && player && player->IsPlayer()) {
  7392. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7393. return 1;
  7394. }
  7395. return 0;
  7396. }
  7397. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7398. if (!lua_interface)
  7399. return 0;
  7400. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7401. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7402. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7403. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7404. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7405. lua_interface->ResetFunctionStack(state);
  7406. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7407. if (player_spawn && player_spawn->IsPlayer()) {
  7408. Player* player = (Player*)player_spawn;
  7409. bool added = false;
  7410. if (!player->skill_list.HasSkill(skill_id)) {
  7411. player->AddSkill(skill_id, current_val, max_val, true);
  7412. added = true;
  7413. }
  7414. 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
  7415. Client* client = player->GetClient();
  7416. if (client) {
  7417. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7418. if (packet)
  7419. client->QueuePacket(packet);
  7420. }
  7421. }
  7422. if (added) {
  7423. lua_interface->SetBooleanValue(state, true);
  7424. return 1;
  7425. }
  7426. }
  7427. else {
  7428. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7429. }
  7430. }
  7431. else {
  7432. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7433. }
  7434. lua_interface->SetBooleanValue(state, false);
  7435. return 1;
  7436. }
  7437. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7438. if (!lua_interface)
  7439. return 0;
  7440. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7441. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7442. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7443. lua_interface->ResetFunctionStack(state);
  7444. if (skill_id > 0) {
  7445. if (player_spawn && player_spawn->IsPlayer()) {
  7446. Player* player = (Player*)player_spawn;
  7447. if (player->skill_list.HasSkill(skill_id)) {
  7448. player->RemovePlayerSkill(skill_id);
  7449. if (!more_to_remove) {
  7450. Client* client = player->GetClient();
  7451. if (client) {
  7452. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7453. if (packet)
  7454. client->QueuePacket(packet);
  7455. }
  7456. }
  7457. }
  7458. }
  7459. else {
  7460. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7461. }
  7462. }
  7463. else {
  7464. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7465. }
  7466. return 0;
  7467. }
  7468. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7469. if (!lua_interface)
  7470. return 0;
  7471. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7472. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7473. int16 amount = lua_interface->GetInt8Value(state, 3);
  7474. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7475. lua_interface->ResetFunctionStack(state);
  7476. if (amount > 0 && skill_type < 100) {
  7477. if (player_spawn && player_spawn->IsPlayer()) {
  7478. Player* player = (Player*)player_spawn;
  7479. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7480. if (!more_to_increase) {
  7481. Client* client = player->GetClient();
  7482. if (client) {
  7483. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7484. if (packet)
  7485. client->QueuePacket(packet);
  7486. }
  7487. }
  7488. }
  7489. else {
  7490. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7491. }
  7492. }
  7493. else {
  7494. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7495. }
  7496. return 0;
  7497. }
  7498. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7499. if (!lua_interface)
  7500. return 0;
  7501. Spawn* spawn = lua_interface->GetSpawn(state);
  7502. string name = lua_interface->GetStringValue(state, 2);
  7503. lua_interface->ResetFunctionStack(state);
  7504. if (!spawn) {
  7505. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7506. return 0;
  7507. }
  7508. if (!spawn->IsEntity()) {
  7509. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7513. if (skill) {
  7514. lua_interface->SetSkillValue(state, skill);
  7515. return 1;
  7516. }
  7517. return 0;
  7518. }
  7519. int EQ2Emu_lua_AddProc(lua_State* state) {
  7520. if (!lua_interface)
  7521. return 0;
  7522. Spawn* spawn = lua_interface->GetSpawn(state);
  7523. int8 type = lua_interface->GetInt8Value(state, 2);
  7524. float chance = lua_interface->GetFloatValue(state, 3);
  7525. Item* item = lua_interface->GetItem(state, 4);
  7526. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7527. LuaSpell* spell = 0;
  7528. if (!spawn && (!spell || !use_all_spelltargets)) {
  7529. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7530. return 0;
  7531. }
  7532. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7533. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7534. return 0;
  7535. }
  7536. if (!item)
  7537. spell = lua_interface->GetCurrentSpell(state);
  7538. if (!item && !spell) {
  7539. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7540. return 0;
  7541. }
  7542. if(spell && spell->resisted) {
  7543. return 0;
  7544. }
  7545. if (spell && use_all_spelltargets) {
  7546. Spawn* target;
  7547. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7548. for (int8 i = 0; i < spell->targets.size(); i++) {
  7549. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7550. if (!target || !target->IsEntity())
  7551. continue;
  7552. ((Entity*)target)->AddProc(type, chance, item, spell);
  7553. }
  7554. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7555. }
  7556. else
  7557. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7558. return 0;
  7559. }
  7560. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7561. if (!lua_interface)
  7562. return 0;
  7563. Spawn* spawn = lua_interface->GetSpawn(state);
  7564. Item* item = lua_interface->GetItem(state, 2);
  7565. LuaSpell* spell = 0;
  7566. if (!spawn) {
  7567. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7568. lua_interface->ResetFunctionStack(state);
  7569. return 0;
  7570. }
  7571. if (!spawn->IsEntity()) {
  7572. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7573. lua_interface->ResetFunctionStack(state);
  7574. return 0;
  7575. }
  7576. if (!item)
  7577. spell = lua_interface->GetCurrentSpell(state);
  7578. lua_interface->ResetFunctionStack(state);
  7579. if (!item && !spell) {
  7580. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7581. return 0;
  7582. }
  7583. if (spell) {
  7584. Spawn* target;
  7585. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7586. for (int8 i = 0; i < spell->targets.size(); i++) {
  7587. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7588. if (!target || !target->IsEntity())
  7589. continue;
  7590. ((Entity*)target)->RemoveProc(item, spell);
  7591. }
  7592. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7593. spell->caster->RemoveProc(item, spell);
  7594. }
  7595. else
  7596. ((Entity*)spawn)->RemoveProc(item, spell);
  7597. return 0;
  7598. }
  7599. int EQ2Emu_lua_Knockback(lua_State* state) {
  7600. if (!lua_interface)
  7601. return 0;
  7602. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7603. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7604. int32 duration = lua_interface->GetInt32Value(state, 3);
  7605. float vertical = lua_interface->GetFloatValue(state, 4);
  7606. float horizontal = lua_interface->GetFloatValue(state, 5);
  7607. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7608. lua_interface->ResetFunctionStack(state);
  7609. if (!target_spawn) {
  7610. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7611. return 0;
  7612. }
  7613. if (!spawn) {
  7614. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7615. return 0;
  7616. }
  7617. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7618. Client* client = ((Player*)spawn)->GetClient();
  7619. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7620. if (packet) {
  7621. packet->setDataByName("target_x", target_spawn->GetX());
  7622. packet->setDataByName("target_y", target_spawn->GetY());
  7623. packet->setDataByName("target_z", target_spawn->GetZ());
  7624. packet->setDataByName("vertical_movement", vertical);
  7625. packet->setDataByName("horizontal_movement", horizontal);
  7626. if (use_heading)
  7627. packet->setDataByName("use_player_heading", 1);
  7628. client->QueuePacket(packet->serialize());
  7629. }
  7630. safe_delete(packet);
  7631. }
  7632. return 0;
  7633. }
  7634. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7635. if (!lua_interface)
  7636. return 0;
  7637. Spawn* spawn = lua_interface->GetSpawn(state);
  7638. lua_interface->ResetFunctionStack(state);
  7639. if (!spawn) {
  7640. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7641. return 0;
  7642. }
  7643. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7644. return 1;
  7645. }
  7646. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7647. if (!lua_interface)
  7648. return 0;
  7649. Spawn* caster = lua_interface->GetSpawn(state);
  7650. Spawn* target = lua_interface->GetSpawn(state, 2);
  7651. string name = lua_interface->GetStringValue(state, 3);
  7652. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7653. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7654. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7655. string success_msg = lua_interface->GetStringValue(state, 7);
  7656. string effect_msg = lua_interface->GetStringValue(state, 8);
  7657. lua_interface->ResetFunctionStack(state);
  7658. if (!caster) {
  7659. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7660. return 0;
  7661. }
  7662. if (!caster->IsEntity()) {
  7663. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if (!target) {
  7667. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. if (!target->IsEntity()) {
  7671. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7672. return 0;
  7673. }
  7674. if (name.length() == 0) {
  7675. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7676. return 0;
  7677. }
  7678. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7679. return 0;
  7680. }
  7681. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7682. if (!lua_interface)
  7683. return 0;
  7684. string name = lua_interface->GetStringValue(state);
  7685. lua_interface->ResetFunctionStack(state);
  7686. if (name.length() == 0) {
  7687. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7688. return 0;
  7689. }
  7690. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7691. if (!skill) {
  7692. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7693. return 0;
  7694. }
  7695. lua_interface->SetInt32Value(state, skill->skill_id);
  7696. return 1;
  7697. }
  7698. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7699. if (!lua_interface)
  7700. return 0;
  7701. Spawn* spawn = lua_interface->GetSpawn(state);
  7702. lua_interface->ResetFunctionStack(state);
  7703. if (!spawn) {
  7704. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7708. return 1;
  7709. }
  7710. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7711. if (!lua_interface)
  7712. return 0;
  7713. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7714. lua_interface->ResetFunctionStack(state);
  7715. if (!luaspell) {
  7716. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7717. return 0;
  7718. }
  7719. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7720. return 1;
  7721. }
  7722. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7723. if (!lua_interface)
  7724. return 0;
  7725. Spawn* spawn = lua_interface->GetSpawn(state);
  7726. Spawn* target = lua_interface->GetSpawn(state, 2);
  7727. lua_interface->ResetFunctionStack(state);
  7728. if (!spawn) {
  7729. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7730. return 0;
  7731. }
  7732. if (!spawn->IsEntity()) {
  7733. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7734. return 0;
  7735. }
  7736. if (!target) {
  7737. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7738. return 0;
  7739. }
  7740. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7741. return 1;
  7742. }
  7743. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7744. if (!lua_interface)
  7745. return 0;
  7746. Spawn* spawn = lua_interface->GetSpawn(state);
  7747. Spawn* target = lua_interface->GetSpawn(state, 2);
  7748. lua_interface->ResetFunctionStack(state);
  7749. if (!spawn) {
  7750. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7751. return 0;
  7752. }
  7753. if (!spawn->IsEntity()) {
  7754. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (!target) {
  7758. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7762. return 1;
  7763. }
  7764. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7765. if (!lua_interface)
  7766. return 0;
  7767. Item* item = lua_interface->GetItem(state);
  7768. lua_interface->ResetFunctionStack(state);
  7769. if (!item) {
  7770. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7771. return 0;
  7772. }
  7773. lua_interface->SetInt32Value(state, item->details.count);
  7774. return 1;
  7775. }
  7776. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7777. if (!lua_interface)
  7778. return 0;
  7779. Item* item = lua_interface->GetItem(state);
  7780. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7781. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7782. lua_interface->ResetFunctionStack(state);
  7783. if (!item) {
  7784. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7785. return 0;
  7786. }
  7787. if (!owner) {
  7788. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7789. return 0;
  7790. }
  7791. if (!owner->IsPlayer()) {
  7792. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. if (item->stack_count < new_count) {
  7796. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. if (new_count > 0) {
  7800. item->details.count = new_count;
  7801. item->save_needed = true;
  7802. }
  7803. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7804. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7805. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7806. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7807. else
  7808. {
  7809. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. Client* client = ((Player*)owner)->GetClient();
  7813. if (!client)
  7814. return 0;
  7815. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7816. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7817. if (app)
  7818. client->QueuePacket(app);
  7819. return 0;
  7820. }
  7821. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7822. if (!lua_interface)
  7823. return 0;
  7824. int32 time = lua_interface->GetInt32Value(state);
  7825. string function = lua_interface->GetStringValue(state, 2);
  7826. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7827. Spawn* target = lua_interface->GetSpawn(state, 4);
  7828. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7829. lua_interface->ResetFunctionStack(state);
  7830. if (time == 0) {
  7831. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. if (function.length() == 0) {
  7835. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7836. return 0;
  7837. }
  7838. if (!spell) {
  7839. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7840. return 0;
  7841. }
  7842. SpellScriptTimer* timer = new SpellScriptTimer;
  7843. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7844. #ifdef WIN32
  7845. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7846. #else
  7847. bzero(timer, sizeof(SpellScriptTimer));
  7848. #endif*/
  7849. timer->caster = 0;
  7850. timer->deleteWhenDone = false;
  7851. timer->target = 0;
  7852. timer->time = Timer::GetCurrentTime2() + time;
  7853. timer->customFunction = function;
  7854. timer->spell = spell;
  7855. if (caster)
  7856. timer->caster = caster->GetID();
  7857. if (target)
  7858. timer->target = target->GetID();
  7859. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7860. return 0;
  7861. }
  7862. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7863. if (!lua_interface)
  7864. return 0;
  7865. float hp_perc = lua_interface->GetFloatValue(state);
  7866. float power_perc = lua_interface->GetFloatValue(state, 2);
  7867. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7868. Spawn* target = lua_interface->GetSpawn(state, 4);
  7869. string heal_name = lua_interface->GetStringValue(state, 5);
  7870. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7871. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7872. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7873. lua_interface->ResetFunctionStack(state);
  7874. if (!spell) {
  7875. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. Entity* caster = spell->caster;
  7879. if (!caster) {
  7880. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7881. return 0;
  7882. }
  7883. Client* client = 0;
  7884. PendingResurrection* rez = 0;
  7885. ZoneServer* zone = spell->caster->GetZone();
  7886. if (!target) {
  7887. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7888. if (spell->targets.size() > 0) {
  7889. vector<int32> spell_targets = spell->targets;
  7890. for (int8 i = 0; i < spell_targets.size(); i++) {
  7891. target = zone->GetSpawnByID(spell_targets.at(i));
  7892. if (!target)
  7893. continue;
  7894. if (!target->IsPlayer())
  7895. continue;
  7896. client = ((Player*)target)->GetClient();
  7897. if (!client)
  7898. continue;
  7899. rez = client->GetCurrentRez();
  7900. if (rez->active)
  7901. continue;
  7902. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7903. rez->active = true;
  7904. rez->caster = caster;
  7905. rez->expire_timer = new Timer;
  7906. int32 duration = spell->spell->GetSpellDuration();
  7907. rez->expire_timer->Start(duration * 100);
  7908. rez->hp_perc = hp_perc;
  7909. rez->mp_perc = power_perc;
  7910. rez->range = spell->spell->GetSpellData()->range;
  7911. rez->spell_name = spell->spell->GetName();
  7912. if (heal_name.length() > 0)
  7913. rez->heal_name = heal_name;
  7914. else
  7915. rez->heal_name = rez->spell_name;
  7916. rez->no_calcs = no_calcs;
  7917. rez->crit_mod = crit_mod;
  7918. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7919. if (send_window)
  7920. client->SendResurrectionWindow();
  7921. else {
  7922. target->GetZone()->ResurrectSpawn(target, client);
  7923. rez->should_delete = true;
  7924. }
  7925. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7926. }
  7927. }
  7928. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7929. }
  7930. else {
  7931. if(!target->IsPlayer())
  7932. return 0;
  7933. client = ((Player*)target)->GetClient();
  7934. if (!client)
  7935. return 0;
  7936. rez = client->GetCurrentRez();
  7937. if (rez->active)
  7938. return 0;
  7939. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7940. rez->active = true;
  7941. rez->caster = caster;
  7942. rez->expire_timer = new Timer;
  7943. int32 duration = spell->spell->GetSpellDuration();
  7944. rez->expire_timer->Start(duration * 100);
  7945. rez->hp_perc = hp_perc;
  7946. rez->mp_perc = power_perc;
  7947. rez->range = spell->spell->GetSpellData()->range;
  7948. rez->spell_name = spell->spell->GetName();
  7949. if (heal_name.length() > 0)
  7950. rez->heal_name = heal_name;
  7951. else
  7952. rez->heal_name = rez->spell_name;
  7953. rez->no_calcs = no_calcs;
  7954. rez->crit_mod = crit_mod;
  7955. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7956. if (send_window)
  7957. client->SendResurrectionWindow();
  7958. else {
  7959. target->GetZone()->ResurrectSpawn(target, client);
  7960. rez->should_delete = true;
  7961. }
  7962. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7963. }
  7964. return 0;
  7965. }
  7966. int EQ2Emu_lua_SetVision(lua_State* state) {
  7967. if (!lua_interface)
  7968. return 0;
  7969. Spawn* spawn = lua_interface->GetSpawn(state);
  7970. int32 vision = lua_interface->GetInt32Value(state, 2);
  7971. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7972. lua_interface->ResetFunctionStack(state);
  7973. if (!spawn) {
  7974. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7975. return 0;
  7976. }
  7977. if (!spawn->IsEntity()) {
  7978. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7979. return 0;
  7980. }
  7981. if (spell && spell->targets.size() > 0) {
  7982. ZoneServer* zone = spell->caster->GetZone();
  7983. for (int8 i = 0; i < spell->targets.size(); i++) {
  7984. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7985. if (target && target->IsEntity()) {
  7986. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7987. if (target->IsPlayer())
  7988. ((Player*)target)->SetCharSheetChanged(true);
  7989. }
  7990. }
  7991. }
  7992. else {
  7993. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7994. if (spawn->IsPlayer())
  7995. ((Player*)spawn)->SetCharSheetChanged(true);
  7996. }
  7997. return 0;
  7998. }
  7999. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8000. if (!lua_interface)
  8001. return 0;
  8002. Spawn* spawn = lua_interface->GetSpawn(state);
  8003. float intensity = lua_interface->GetFloatValue(state, 2);
  8004. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8005. lua_interface->ResetFunctionStack(state);
  8006. if (!spawn) {
  8007. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8008. return 0;
  8009. }
  8010. if (!spawn->IsEntity()) {
  8011. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8012. return 0;
  8013. }
  8014. if (spell && spell->targets.size() > 0) {
  8015. ZoneServer* zone = spell->caster->GetZone();
  8016. for (int8 i = 0; i < spell->targets.size(); i++) {
  8017. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8018. if (target && target->IsEntity()) {
  8019. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8020. if (target->IsPlayer())
  8021. ((Player*)target)->SetCharSheetChanged(true);
  8022. }
  8023. }
  8024. }
  8025. else {
  8026. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8027. if (spawn->IsPlayer())
  8028. ((Player*)spawn)->SetCharSheetChanged(true);
  8029. }
  8030. return 0;
  8031. }
  8032. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8033. if (!lua_interface)
  8034. return 0;
  8035. Spawn* spawn = lua_interface->GetSpawn(state);
  8036. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8037. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8038. lua_interface->ResetFunctionStack(state);
  8039. if (!spawn) {
  8040. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8041. return 0;
  8042. }
  8043. if (!spawn->IsEntity()) {
  8044. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8045. return 0;
  8046. }
  8047. if (spell && spell->targets.size() > 0) {
  8048. ZoneServer* zone = spell->caster->GetZone();
  8049. for (int8 i = 0; i < spell->targets.size(); i++) {
  8050. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8051. if (target && target->IsEntity()) {
  8052. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8053. if (target->IsPlayer())
  8054. ((Player*)target)->SetCharSheetChanged(true);
  8055. }
  8056. }
  8057. }
  8058. else {
  8059. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8060. if (spawn->IsPlayer())
  8061. ((Player*)spawn)->SetCharSheetChanged(true);
  8062. }
  8063. return 0;
  8064. }
  8065. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8066. if (!lua_interface)
  8067. return 0;
  8068. Item* item = lua_interface->GetItem(state);
  8069. int8 type = lua_interface->GetInt32Value(state, 2);
  8070. lua_interface->ResetFunctionStack(state);
  8071. if (!item) {
  8072. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8073. return 0;
  8074. }
  8075. if (type == 1)
  8076. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8077. else if (type == 2)
  8078. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8079. return 1;
  8080. }
  8081. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8082. if (!lua_interface)
  8083. return 0;
  8084. Spawn* target = lua_interface->GetSpawn(state);
  8085. float val = lua_interface->GetFloatValue(state, 2);
  8086. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8087. lua_interface->ResetFunctionStack(state);
  8088. // Added from Gangrenous post
  8089. if (spell && spell->resisted)
  8090. return 0;
  8091. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8092. if (val > 1.0f)
  8093. val = 1.0f - (val / 100.0f);
  8094. if (spell && spell->spell && spell->targets.size() > 0) {
  8095. ZoneServer* zone = spell->caster->GetZone();
  8096. for (int32 i = 0; i != spell->targets.size(); i++) {
  8097. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8098. if (spawn && spawn->IsEntity()) {
  8099. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8100. if (spawn->IsPlayer())
  8101. ((Player*)spawn)->SetCharSheetChanged(true);
  8102. }
  8103. }
  8104. }
  8105. else {
  8106. if (target && target->IsEntity()) {
  8107. ((Entity*)target)->SetSpeedMultiplier(val);
  8108. if (target->IsPlayer())
  8109. ((Player*)target)->SetCharSheetChanged(true);
  8110. }
  8111. }
  8112. return 0;
  8113. }
  8114. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8115. if (!lua_interface)
  8116. return 0;
  8117. Spawn* spawn = lua_interface->GetSpawn(state);
  8118. int16 model = lua_interface->GetInt16Value(state, 2);
  8119. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8120. lua_interface->ResetFunctionStack(state);
  8121. if (spell && spell->spell && spell->targets.size() > 0) {
  8122. ZoneServer* zone = spell->caster->GetZone();
  8123. for (int32 i = 0; i < spell->targets.size(); i++) {
  8124. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8125. if (target)
  8126. target->SetIllusionModel(model);
  8127. }
  8128. }
  8129. else {
  8130. if (!spawn) {
  8131. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. spawn->SetIllusionModel(model);
  8135. }
  8136. return 0;
  8137. }
  8138. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8139. if (!lua_interface)
  8140. return 0;
  8141. Spawn* spawn = lua_interface->GetSpawn(state);
  8142. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8143. lua_interface->ResetFunctionStack(state);
  8144. if (spell && spell->spell && spell->targets.size() > 0) {
  8145. ZoneServer* zone = spell->caster->GetZone();
  8146. for (int32 i = 0; i < spell->targets.size(); i++) {
  8147. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8148. if (target)
  8149. target->SetIllusionModel(0);
  8150. }
  8151. }
  8152. else {
  8153. if (!spawn) {
  8154. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8155. return 0;
  8156. }
  8157. spawn->SetIllusionModel(0);
  8158. }
  8159. return 0;
  8160. }
  8161. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8162. if (!lua_interface)
  8163. return 0;
  8164. Spawn* caster = lua_interface->GetSpawn(state);
  8165. Spawn* target = lua_interface->GetSpawn(state, 2);
  8166. float chance = lua_interface->GetFloatValue(state, 3);
  8167. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8168. lua_interface->ResetFunctionStack(state);
  8169. if (!caster) {
  8170. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8171. return 0;
  8172. }
  8173. if (!caster->IsEntity()) {
  8174. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8175. return 0;
  8176. }
  8177. if (!target) {
  8178. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8179. return 0;
  8180. }
  8181. if (!target->IsEntity()) {
  8182. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8183. return 0;
  8184. }
  8185. if (chance <= 0) {
  8186. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. if (!spell) {
  8190. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. if(spell->resisted) {
  8194. return 0;
  8195. }
  8196. if (((Entity*)caster)->GetThreatTransfer()) {
  8197. return 0;
  8198. }
  8199. ThreatTransfer* transfer = new ThreatTransfer;
  8200. transfer->Target = target->GetID();
  8201. transfer->Amount = chance;
  8202. transfer->Spell = spell;
  8203. ((Entity*)caster)->SetThreatTransfer(transfer);
  8204. return 0;
  8205. }
  8206. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8207. if (!lua_interface)
  8208. return 0;
  8209. Spawn* spawn = lua_interface->GetSpawn(state);
  8210. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8211. lua_interface->ResetFunctionStack(state);
  8212. if (!spawn) {
  8213. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8214. return 0;
  8215. }
  8216. if (!spell) {
  8217. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8221. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8222. if(transfer && transfer->Spell != spell) {
  8223. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8224. return 0;
  8225. }
  8226. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8227. }
  8228. return 0;
  8229. }
  8230. int EQ2Emu_lua_CureByType(lua_State* state) {
  8231. if (!lua_interface)
  8232. return 0;
  8233. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8234. int8 cure_count = lua_interface->GetInt8Value(state);
  8235. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8236. string cure_name = lua_interface->GetStringValue(state, 3);
  8237. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8238. Spawn* target = lua_interface->GetSpawn(state, 5);
  8239. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8240. lua_interface->ResetFunctionStack(state);
  8241. if(spell && spell->resisted) {
  8242. return 0;
  8243. }
  8244. if (target) {
  8245. if (!target->IsEntity()) {
  8246. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8247. return 0;
  8248. }
  8249. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8250. std::string alternate_name = "item";
  8251. if(spell)
  8252. alternate_name = std::string(spell->spell->GetName());
  8253. if(!caster && spell)
  8254. caster = (Spawn*)spell->caster;
  8255. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8256. }
  8257. }
  8258. else {
  8259. ZoneServer* zone = spell->caster->GetZone();
  8260. vector<int32> targets = spell->targets;
  8261. vector<Entity*> targets_to_cure;
  8262. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8263. for (int8 i = 0; i < targets.size(); i++) {
  8264. target = zone->GetSpawnByID(targets.at(i));
  8265. if (!target || !target->IsEntity())
  8266. continue;
  8267. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8268. targets_to_cure.push_back((Entity*)target);
  8269. }
  8270. }
  8271. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8272. vector<Entity*>::iterator itr;
  8273. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8274. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8275. }
  8276. }
  8277. return 0;
  8278. }
  8279. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8280. if (!lua_interface)
  8281. return 0;
  8282. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8283. if (!spell) {
  8284. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8285. lua_interface->ResetFunctionStack(state);
  8286. return 0;
  8287. }
  8288. if(spell->resisted) {
  8289. lua_interface->ResetFunctionStack(state);
  8290. return 0;
  8291. }
  8292. int8 cure_count = lua_interface->GetInt8Value(state);
  8293. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8294. string cure_name = lua_interface->GetStringValue(state, 3);
  8295. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8296. Spawn* target = lua_interface->GetSpawn(state, 5);
  8297. lua_interface->ResetFunctionStack(state);
  8298. if (target) {
  8299. if (!target->IsEntity()) {
  8300. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8301. return 0;
  8302. }
  8303. if (((Entity*)target)->GetDetCount() > 0)
  8304. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8305. }
  8306. else {
  8307. ZoneServer* zone = spell->caster->GetZone();
  8308. vector<int32> targets = spell->targets;
  8309. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8310. for (int8 i = 0; i < targets.size(); i++) {
  8311. target = zone->GetSpawnByID(targets.at(i));
  8312. if (!target || !target->IsEntity())
  8313. continue;
  8314. if (((Entity*)target)->GetDetCount() > 0)
  8315. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8316. }
  8317. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8318. }
  8319. return 0;
  8320. }
  8321. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8322. if (!lua_interface)
  8323. return 0;
  8324. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8325. lua_interface->ResetFunctionStack(state);
  8326. if (!spell) {
  8327. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8328. return 0;
  8329. }
  8330. if (!spell->caster) {
  8331. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8332. return 0;
  8333. }
  8334. if (!spell->caster->GetZone()) {
  8335. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8339. return 0;
  8340. }
  8341. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8342. if (!lua_interface)
  8343. return 0;
  8344. Spawn* spawn = lua_interface->GetSpawn(state);
  8345. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8346. lua_interface->ResetFunctionStack(state);
  8347. if (!spell) {
  8348. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. if (spawn && spawn->IsEntity())
  8352. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8353. else {
  8354. ZoneServer* zone = spell->caster->GetZone();
  8355. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8356. for (int32 i = 0; i < spell->targets.size(); i++) {
  8357. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8358. if (!spawn || !spawn->IsEntity())
  8359. continue;
  8360. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8361. }
  8362. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8363. }
  8364. return 0;
  8365. }
  8366. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8367. if (!lua_interface)
  8368. return 0;
  8369. Spawn* spawn = lua_interface->GetSpawn(state);
  8370. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8371. lua_interface->ResetFunctionStack(state);
  8372. if (!spell) {
  8373. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. if (spawn && spawn->IsEntity())
  8377. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8378. else {
  8379. ZoneServer* zone = spell->caster->GetZone();
  8380. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8381. for (int32 i = 0; i < spell->targets.size(); i++) {
  8382. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8383. if (!spawn || !spawn->IsEntity())
  8384. continue;
  8385. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8386. }
  8387. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8388. }
  8389. return 0;
  8390. }
  8391. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8392. if (!lua_interface)
  8393. return 0;
  8394. Spawn* caster = lua_interface->GetSpawn(state);
  8395. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8396. lua_interface->ResetFunctionStack(state);
  8397. if (!caster) {
  8398. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. if (!caster->IsPlayer()) {
  8402. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8403. return 0;
  8404. }
  8405. Spawn* target = caster->GetTarget();
  8406. if (!target) {
  8407. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. Client* client = ((Player*)caster)->GetClient();
  8411. if (!client) {
  8412. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8413. return 0;
  8414. }
  8415. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8416. if (ho) {
  8417. ho->SetTarget(target->GetID());
  8418. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8419. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8420. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8421. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8422. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8423. deque<GroupMemberInfo*>::iterator itr;
  8424. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8425. if (group)
  8426. {
  8427. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8428. deque<GroupMemberInfo*>* members = group->GetMembers();
  8429. for (itr = members->begin(); itr != members->end(); itr++) {
  8430. if ((*itr)->client)
  8431. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8432. }
  8433. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8434. }
  8435. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8436. }
  8437. else
  8438. safe_delete(ho);
  8439. }
  8440. else {
  8441. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8442. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8443. }
  8444. else
  8445. safe_delete(ho);
  8446. }
  8447. }
  8448. return 0;
  8449. }
  8450. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8451. if (!lua_interface)
  8452. return 0;
  8453. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8454. if (!spell) {
  8455. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. int16 triggerCount = lua_interface->GetInt16Value(state);
  8459. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8460. if (!triggerCount) {
  8461. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8462. return 0;
  8463. }
  8464. spell->num_triggers = triggerCount;
  8465. spell->had_triggers = true;
  8466. spell->cancel_after_all_triggers = cancel_after_triggers;
  8467. return 0;
  8468. }
  8469. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8470. if (!lua_interface)
  8471. return 0;
  8472. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8473. lua_interface->ResetFunctionStack(state);
  8474. if (!spell) {
  8475. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. lua_interface->SetInt32Value(state, spell->num_triggers);
  8479. return 1;
  8480. }
  8481. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8482. if (!lua_interface)
  8483. return 0;
  8484. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8485. if (!spell) {
  8486. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8487. lua_interface->ResetFunctionStack(state);
  8488. return 0;
  8489. }
  8490. int16 remove_count = lua_interface->GetInt16Value(state);
  8491. lua_interface->ResetFunctionStack(state);
  8492. if (!remove_count)
  8493. remove_count = 1;
  8494. if (remove_count >= spell->num_triggers) {
  8495. spell->num_triggers = 0;
  8496. if (spell->cancel_after_all_triggers)
  8497. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8498. }
  8499. else {
  8500. spell->num_triggers -= remove_count;
  8501. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8502. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8503. }
  8504. return 0;
  8505. }
  8506. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8507. if (!lua_interface)
  8508. return 0;
  8509. Spawn* spawn = lua_interface->GetSpawn(state);
  8510. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8511. lua_interface->ResetFunctionStack(state);
  8512. if (!spawn) {
  8513. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8514. return 0;
  8515. }
  8516. if (!copy_spawn) {
  8517. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8518. return 0;
  8519. }
  8520. spawn->CopySpawnAppearance(copy_spawn);
  8521. return 0;
  8522. }
  8523. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8524. Spawn* spawn = lua_interface->GetSpawn(state);
  8525. int8 type = lua_interface->GetInt8Value(state, 2);
  8526. lua_interface->ResetFunctionStack(state);
  8527. if (!spawn) {
  8528. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8529. return 0;
  8530. }
  8531. else if (!spawn->IsEntity()) {
  8532. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8533. return 0;
  8534. }
  8535. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8536. return 1;
  8537. }
  8538. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8539. if (!lua_interface)
  8540. return 0;
  8541. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8542. int8 type = lua_interface->GetInt8Value(state);
  8543. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8544. lua_interface->ResetFunctionStack(state);
  8545. if (!spell) {
  8546. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. if(spell->resisted) {
  8550. return 0;
  8551. }
  8552. if (spawn) {
  8553. if (!spawn->IsEntity()) {
  8554. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. Entity* entity = ((Entity*)spawn);
  8558. entity->AddImmunity(spell, type);
  8559. }
  8560. else {
  8561. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8562. for (int8 i = 0; i < spell->targets.size(); i++) {
  8563. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8564. if (!spawn || !spawn->IsEntity())
  8565. continue;
  8566. Entity* entity = ((Entity*)spawn);
  8567. entity->AddImmunity(spell, type);
  8568. }
  8569. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8570. }
  8571. return 0;
  8572. }
  8573. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8574. if (!lua_interface)
  8575. return 0;
  8576. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8577. int8 type = lua_interface->GetInt8Value(state);
  8578. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8579. lua_interface->ResetFunctionStack(state);
  8580. if (!spell) {
  8581. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8582. return 0;
  8583. }
  8584. if (spawn) {
  8585. if (!spawn->IsEntity()) {
  8586. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8587. return 0;
  8588. }
  8589. Entity* entity = ((Entity*)spawn);
  8590. entity->RemoveImmunity(spell, type);
  8591. }
  8592. else {
  8593. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8594. for (int8 i = 0; i < spell->targets.size(); i++) {
  8595. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8596. if (!spawn || !spawn->IsEntity())
  8597. continue;
  8598. Entity* entity = ((Entity*)spawn);
  8599. entity->RemoveImmunity(spell, type);
  8600. }
  8601. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8602. }
  8603. return 0;
  8604. }
  8605. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8606. if (!lua_interface)
  8607. return 0;
  8608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8609. if (!spell) {
  8610. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8611. lua_interface->ResetFunctionStack(state);
  8612. return 0;
  8613. }
  8614. if(spell->resisted) {
  8615. lua_interface->ResetFunctionStack(state);
  8616. return 0;
  8617. }
  8618. float snare = lua_interface->GetFloatValue(state);
  8619. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8620. lua_interface->ResetFunctionStack(state);
  8621. // convert the val to the speed multipler value (100 - val)
  8622. float val = 100.0 - snare;
  8623. val /= 100.0;
  8624. if (spawn) {
  8625. if (!spawn->IsEntity()) {
  8626. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8627. return 0;
  8628. }
  8629. ((Entity*)spawn)->SetSnareValue(spell, val);
  8630. }
  8631. else {
  8632. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8633. for (int8 i = 0; i < spell->targets.size(); i++) {
  8634. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8635. if (!spawn || !spawn->IsEntity())
  8636. continue;
  8637. ((Entity*)spawn)->SetSnareValue(spell, val);
  8638. }
  8639. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8640. }
  8641. return 0;
  8642. }
  8643. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8644. if (!lua_interface)
  8645. return 0;
  8646. Spawn* spawn = lua_interface->GetSpawn(state);
  8647. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8648. lua_interface->ResetFunctionStack(state);
  8649. if (!spawn) {
  8650. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8651. return 0;
  8652. }
  8653. if (race_id == 0) {
  8654. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8655. return 0;
  8656. }
  8657. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8658. return 1;
  8659. }
  8660. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8661. if (!lua_interface)
  8662. return 0;
  8663. Spawn* spawn = lua_interface->GetSpawn(state);
  8664. lua_interface->ResetFunctionStack(state);
  8665. if (!spawn) {
  8666. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8670. return 1;
  8671. }
  8672. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8673. if (!lua_interface)
  8674. return 0;
  8675. Spawn* spawn = lua_interface->GetSpawn(state);
  8676. lua_interface->ResetFunctionStack(state);
  8677. if (!spawn) {
  8678. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8679. return 0;
  8680. }
  8681. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8682. return 1;
  8683. }
  8684. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8685. if (!lua_interface)
  8686. return 0;
  8687. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8688. lua_interface->ResetFunctionStack(state);
  8689. if (!spell) {
  8690. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8691. return 0;
  8692. }
  8693. lua_interface->SetStringValue(state, spell->spell->GetName());
  8694. return 1;
  8695. }
  8696. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. Quest* quest = lua_interface->GetQuest(state);
  8700. lua_interface->ResetFunctionStack(state);
  8701. if (!quest) {
  8702. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8703. return 0;
  8704. }
  8705. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8706. return 1;
  8707. }
  8708. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8709. if (!lua_interface)
  8710. return 0;
  8711. Quest* quest = lua_interface->GetQuest(state);
  8712. int32 flags = lua_interface->GetInt32Value(state, 2);
  8713. lua_interface->ResetFunctionStack(state);
  8714. if (!quest) {
  8715. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8716. return 0;
  8717. }
  8718. quest->SetQuestFlags(flags);
  8719. return 0;
  8720. }
  8721. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8722. if (!lua_interface)
  8723. return 0;
  8724. Quest* quest = lua_interface->GetQuest(state);
  8725. Spawn* player = lua_interface->GetSpawn(state, 2);
  8726. int32 step = lua_interface->GetInt32Value(state, 3);
  8727. int32 duration = lua_interface->GetInt32Value(state, 4);
  8728. string action = lua_interface->GetStringValue(state, 5);
  8729. lua_interface->ResetFunctionStack(state);
  8730. if (!quest) {
  8731. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8732. return 0;
  8733. }
  8734. if (!player) {
  8735. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8736. return 0;
  8737. }
  8738. if (!player->IsPlayer()) {
  8739. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. if (step == 0) {
  8743. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8744. return 0;
  8745. }
  8746. if (duration == 0) {
  8747. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8748. return 0;
  8749. }
  8750. if (action.length() == 0) {
  8751. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8752. return 0;
  8753. }
  8754. Client* client = ((Player*)player)->GetClient();
  8755. if (!client) {
  8756. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8757. return 0;
  8758. }
  8759. quest->SetTimerStep(step);
  8760. quest->AddFailedAction(step, action);
  8761. quest->SetStepTimer(duration);
  8762. client->AddQuestTimer(quest->GetQuestID());
  8763. return 0;
  8764. }
  8765. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8766. if (!lua_interface)
  8767. return 0;
  8768. Quest* quest = lua_interface->GetQuest(state);
  8769. Spawn* player = lua_interface->GetSpawn(state, 2);
  8770. lua_interface->ResetFunctionStack(state);
  8771. if (!quest) {
  8772. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. if (!player) {
  8776. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. if (!player->IsPlayer()) {
  8780. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. Client* client = ((Player*)player)->GetClient();
  8784. if (!client) {
  8785. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8786. return 0;
  8787. }
  8788. quest->SetTimerStep(0);
  8789. quest->SetStepTimer(0);
  8790. client->RemoveQuestTimer(quest->GetQuestID());
  8791. return 0;
  8792. }
  8793. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8794. if (!lua_interface)
  8795. return 0;
  8796. Spawn* player = lua_interface->GetSpawn(state);
  8797. Quest* quest = lua_interface->GetQuest(state, 2);
  8798. int32 step = lua_interface->GetInt32Value(state, 3);
  8799. lua_interface->ResetFunctionStack(state);
  8800. if (!player) {
  8801. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8802. return 0;
  8803. }
  8804. if (!player->IsPlayer()) {
  8805. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8806. return 0;
  8807. }
  8808. if (!quest) {
  8809. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8810. return 0;
  8811. }
  8812. if (step == 0) {
  8813. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. Client* client = ((Player*)player)->GetClient();
  8817. if (!client) {
  8818. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8819. return 0;
  8820. }
  8821. if (quest->RemoveQuestStep(step, client)) {
  8822. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8823. client->GetCurrentZone()->SendQuestUpdates(client);
  8824. }
  8825. else
  8826. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8827. return 0;
  8828. }
  8829. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8830. if (!lua_interface)
  8831. return 0;
  8832. Quest* quest = lua_interface->GetQuest(state, 1);
  8833. int32 step = lua_interface->GetInt32Value(state, 2);
  8834. string desc = lua_interface->GetStringValue(state, 3);
  8835. string task_group = lua_interface->GetStringValue(state, 4);
  8836. lua_interface->ResetFunctionStack(state);
  8837. if (!quest) {
  8838. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8839. return 0;
  8840. }
  8841. if (step == 0) {
  8842. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. QuestStep* quest_step = quest->GetQuestStep(step);
  8846. if (!quest_step) {
  8847. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8848. return 0;
  8849. }
  8850. quest_step->SetStepProgress(0);
  8851. quest_step->SetTaskGroup(task_group);
  8852. quest_step->SetDescription(desc);
  8853. return 0;
  8854. }
  8855. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8856. if (!lua_interface)
  8857. return 0;
  8858. Quest* quest = lua_interface->GetQuest(state);
  8859. int32 step = lua_interface->GetInt32Value(state, 2);
  8860. string action = lua_interface->GetStringValue(state, 3);
  8861. lua_interface->ResetFunctionStack(state);
  8862. if (!quest) {
  8863. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8864. return 0;
  8865. }
  8866. if (step == 0) {
  8867. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8868. return 0;
  8869. }
  8870. if (action.length() == 0) {
  8871. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8872. return 0;
  8873. }
  8874. quest->AddFailedAction(step, action);
  8875. return 0;
  8876. }
  8877. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8878. if (!lua_interface)
  8879. return 0;
  8880. Spawn* player = lua_interface->GetSpawn(state);
  8881. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8882. int32 step = lua_interface->GetInt32Value(state, 3);
  8883. lua_interface->ResetFunctionStack(state);
  8884. if (!player) {
  8885. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8886. return 0;
  8887. }
  8888. if (!player->IsPlayer()) {
  8889. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. if (quest_id == 0) {
  8893. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. if (step == 0) {
  8897. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8901. if (!quest) {
  8902. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8903. return 0;
  8904. }
  8905. quest->StepFailed(step);
  8906. return 0;
  8907. }
  8908. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8909. if (!lua_interface)
  8910. return 0;
  8911. Spawn* player = lua_interface->GetSpawn(state);
  8912. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8913. lua_interface->ResetFunctionStack(state);
  8914. if (!player) {
  8915. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8916. return 0;
  8917. }
  8918. if (!player->IsPlayer()) {
  8919. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8920. return 0;
  8921. }
  8922. if (quest_id == 0) {
  8923. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8924. return 0;
  8925. }
  8926. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  8927. return 1;
  8928. }
  8929. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8930. if (!lua_interface)
  8931. return 0;
  8932. string name = lua_interface->GetStringValue(state);
  8933. string value = lua_interface->GetStringValue(state, 2);
  8934. string comment = lua_interface->GetStringValue(state, 3);
  8935. lua_interface->ResetFunctionStack(state);
  8936. if (name.length() == 0) {
  8937. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8938. return 0;
  8939. }
  8940. if (value.length() == 0) {
  8941. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8942. return 0;
  8943. }
  8944. string varname = string("lua_").append(name);
  8945. Variable* var = variables.FindVariable(varname);
  8946. if (var)
  8947. var->SetValue(value.c_str());
  8948. else {
  8949. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8950. variables.AddVariable(var);
  8951. }
  8952. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8953. return 0;
  8954. }
  8955. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8956. if (!lua_interface)
  8957. return 0;
  8958. string name = lua_interface->GetStringValue(state);
  8959. lua_interface->ResetFunctionStack(state);
  8960. if (name.length() == 0) {
  8961. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. string varname = string("lua_").append(name);
  8965. Variable* var = variables.FindVariable(varname);
  8966. if (var)
  8967. lua_interface->SetStringValue(state, var->GetValue());
  8968. else
  8969. lua_interface->SetStringValue(state, "NULL");
  8970. return 1;
  8971. }
  8972. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8973. if (!lua_interface)
  8974. return 0;
  8975. Spawn* player = lua_interface->GetSpawn(state);
  8976. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8977. lua_interface->ResetFunctionStack(state);
  8978. if (!player) {
  8979. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8980. return 0;
  8981. }
  8982. if (!player->IsPlayer()) {
  8983. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8984. return 0;
  8985. }
  8986. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8987. return 1;
  8988. }
  8989. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8990. if (!lua_interface)
  8991. return 0;
  8992. Spawn* player = lua_interface->GetSpawn(state);
  8993. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8994. lua_interface->ResetFunctionStack(state);
  8995. if (!player) {
  8996. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8997. return 0;
  8998. }
  8999. if (!player->IsPlayer()) {
  9000. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9001. return 0;
  9002. }
  9003. Language* language = master_languages_list.GetLanguage(language_id);
  9004. if (language)
  9005. {
  9006. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9007. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9008. }
  9009. return 0;
  9010. }
  9011. int EQ2Emu_lua_IsNight(lua_State* state) {
  9012. if (!lua_interface)
  9013. return 0;
  9014. ZoneServer* zone = lua_interface->GetZone(state);
  9015. lua_interface->ResetFunctionStack(state);
  9016. if (!zone) {
  9017. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9018. return 0;
  9019. }
  9020. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9021. return 1;
  9022. }
  9023. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9024. if (!lua_interface)
  9025. return 0;
  9026. Spawn* spawn = lua_interface->GetSpawn(state);
  9027. lua_interface->ResetFunctionStack(state);
  9028. if (!spawn) {
  9029. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9030. return 0;
  9031. }
  9032. if (!spawn->IsWidget()) {
  9033. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9034. return 0;
  9035. }
  9036. ((Widget*)spawn)->SetMultiFloorLift(true);
  9037. if (spawn->GetZone())
  9038. spawn->GetZone()->AddTransportSpawn(spawn);
  9039. return 0;
  9040. }
  9041. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9042. if (!lua_interface)
  9043. return 0;
  9044. Spawn* player = lua_interface->GetSpawn(state);
  9045. int32 path = lua_interface->GetInt32Value(state, 2);
  9046. lua_interface->ResetFunctionStack(state);
  9047. if (!player) {
  9048. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. if (!player->IsPlayer()) {
  9052. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. if (path == 0) {
  9056. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. Client* client = ((Player*)player)->GetClient();
  9060. if (!client) {
  9061. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9062. return 0;
  9063. }
  9064. client->SendFlightAutoMount(path);
  9065. return 0;
  9066. }
  9067. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9068. if (!lua_interface)
  9069. return 0;
  9070. Spawn* player = lua_interface->GetSpawn(state);
  9071. if (!player) {
  9072. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. if (!player->IsPlayer()) {
  9076. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. Client* client = ((Player*)player)->GetClient();
  9080. if (!client) {
  9081. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9082. return 0;
  9083. }
  9084. client->EndAutoMount();
  9085. return 0;
  9086. }
  9087. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9088. if (!lua_interface)
  9089. return 0;
  9090. Spawn* player = lua_interface->GetSpawn(state);
  9091. lua_interface->ResetFunctionStack(state);
  9092. if (!player) {
  9093. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9094. return 0;
  9095. }
  9096. if (!player->IsPlayer()) {
  9097. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9098. return 0;
  9099. }
  9100. Client* client = ((Player*)player)->GetClient();
  9101. if (!client) {
  9102. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9103. return 0;
  9104. }
  9105. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9106. return 1;
  9107. }
  9108. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9109. if (!lua_interface)
  9110. return 0;
  9111. Spawn* player = lua_interface->GetSpawn(state);
  9112. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9113. int32 value = lua_interface->GetInt32Value(state, 3);
  9114. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9115. lua_interface->ResetFunctionStack(state);
  9116. if (!player) {
  9117. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9118. return 0;
  9119. }
  9120. if (!player->IsPlayer()) {
  9121. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9122. return 0;
  9123. }
  9124. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9125. return 0;
  9126. }
  9127. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Spawn* player = lua_interface->GetSpawn(state);
  9131. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9132. lua_interface->ResetFunctionStack(state);
  9133. if (!player) {
  9134. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9135. return 0;
  9136. }
  9137. if (!player->IsPlayer()) {
  9138. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9139. return 0;
  9140. }
  9141. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9142. if (!hd)
  9143. return 0;
  9144. lua_interface->SetInt32Value(state, hd->Value);
  9145. lua_interface->SetInt32Value(state, hd->Value2);
  9146. return 2;
  9147. }
  9148. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9149. if (!lua_interface)
  9150. return 0;
  9151. Spawn* spawn = lua_interface->GetSpawn(state);
  9152. int32 grid = lua_interface->GetInt32Value(state, 2);
  9153. lua_interface->ResetFunctionStack(state);
  9154. if (!spawn) {
  9155. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9156. return 0;
  9157. }
  9158. if (grid == 0) {
  9159. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9160. return 0;
  9161. }
  9162. spawn->SetLocation(grid);
  9163. return 0;
  9164. }
  9165. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9166. if (!lua_interface)
  9167. return 0;
  9168. Spawn* spawn = lua_interface->GetSpawn(state);
  9169. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9170. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9171. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9172. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9173. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9174. lua_interface->ResetFunctionStack(state);
  9175. if (!spawn) {
  9176. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9177. return 0;
  9178. }
  9179. //Add this quest to the list of required quests for this spawn
  9180. spawn->SetRequiredHistory(event_id, value1, value2);
  9181. //If private spawn value set
  9182. if (private_spawn) {
  9183. //Set the spawn to be private when not granted access via history
  9184. spawn->AddAllowAccessSpawn(spawn);
  9185. spawn->SetPrivateQuestSpawn(true);
  9186. }
  9187. //This value will override vis_flags in the vis packet
  9188. if (flag_override > 0)
  9189. spawn->SetQuestsRequiredOverride(flag_override);
  9190. return 0;
  9191. }
  9192. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9193. if (!lua_interface)
  9194. return 0;
  9195. Spawn* player = lua_interface->GetSpawn(state);
  9196. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9197. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9198. lua_interface->ResetFunctionStack(state);
  9199. if (!player) {
  9200. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9201. return 0;
  9202. }
  9203. if (!player->IsPlayer()) {
  9204. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9205. return 0;
  9206. }
  9207. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9208. return 1;
  9209. }
  9210. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9211. if (!lua_interface)
  9212. return 0;
  9213. Spawn* player = lua_interface->GetSpawn(state);
  9214. int8 level = lua_interface->GetInt8Value(state, 2);
  9215. lua_interface->ResetFunctionStack(state);
  9216. if (!player) {
  9217. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9218. return 0;
  9219. }
  9220. if (!player->IsPlayer()) {
  9221. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9222. return 0;
  9223. }
  9224. if (level == 0) {
  9225. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. Client* client = ((Player*)player)->GetClient();
  9229. if (!client) {
  9230. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9231. return 0;
  9232. }
  9233. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9234. return 0;
  9235. }
  9236. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9237. if (!lua_interface)
  9238. return 0;
  9239. Spawn* player = lua_interface->GetSpawn(state);
  9240. int32 amount = lua_interface->GetInt32Value(state, 2);
  9241. lua_interface->ResetFunctionStack(state);
  9242. if (!player) {
  9243. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9244. return 0;
  9245. }
  9246. if (!player->IsPlayer()) {
  9247. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9248. return 0;
  9249. }
  9250. if (amount == 0) {
  9251. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9252. return 0;
  9253. }
  9254. ((Player*)player)->AddCoins(amount);
  9255. return 0;
  9256. }
  9257. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9258. if (!lua_interface)
  9259. return 0;
  9260. Spawn* player = lua_interface->GetSpawn(state);
  9261. int32 amount = lua_interface->GetInt32Value(state, 2);
  9262. lua_interface->ResetFunctionStack(state);
  9263. if (!player) {
  9264. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9265. return 0;
  9266. }
  9267. if (!player->IsPlayer()) {
  9268. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9269. return 0;
  9270. }
  9271. if (amount == 0) {
  9272. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9276. return 1;
  9277. }
  9278. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9279. if (!lua_interface)
  9280. return 0;
  9281. ZoneServer* zone = lua_interface->GetZone(state);
  9282. lua_interface->ResetFunctionStack(state);
  9283. if (!zone) {
  9284. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9285. return 0;
  9286. }
  9287. vector<Entity*> players = zone->GetPlayers();
  9288. if (players.size() == 0)
  9289. return 0;
  9290. lua_createtable(state, players.size(), 0);
  9291. int newTable = lua_gettop(state);
  9292. for (int32 i = 0; i < players.size(); i++) {
  9293. lua_interface->SetSpawnValue(state, players.at(i));
  9294. lua_rawseti(state, newTable, i + 1);
  9295. }
  9296. return 1;
  9297. }
  9298. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9299. if (!lua_interface)
  9300. return 0;
  9301. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9302. if (!zone) {
  9303. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9304. return 0;
  9305. }
  9306. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9307. lua_interface->ResetFunctionStack(state);
  9308. //Map of <placement_id, location_id>
  9309. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9310. map<int32, int32>::iterator itr;
  9311. vector<Spawn*> group;
  9312. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9313. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9314. if (!location) {
  9315. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9316. return 0;
  9317. }
  9318. Spawn* spawn = 0;
  9319. if (location->entities[0]) {
  9320. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9321. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9322. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9323. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9324. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9325. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9326. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9327. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9328. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9329. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9330. if(spawn && spawn->IsOmittedByDBFlag())
  9331. {
  9332. 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);
  9333. safe_delete(spawn);
  9334. continue;
  9335. }
  9336. if (spawn) {
  9337. const char* script = 0;
  9338. for (int x = 0; x < 3; x++) {
  9339. switch (x) {
  9340. case 0:
  9341. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9342. break;
  9343. case 1:
  9344. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9345. break;
  9346. case 2:
  9347. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9348. break;
  9349. }
  9350. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9351. spawn->SetSpawnScript(string(script));
  9352. break;
  9353. }
  9354. }
  9355. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9356. lua_interface->SetSpawnValue(state, spawn);
  9357. group.push_back(spawn);
  9358. }
  9359. else {
  9360. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9361. safe_delete(spawn);
  9362. }
  9363. }
  9364. }
  9365. if (!group.empty()) {
  9366. lua_createtable(state, group.size(), 0);
  9367. int newTable = lua_gettop(state);
  9368. for (int32 i = 0; i < group.size(); i++) {
  9369. lua_interface->SetSpawnValue(state, group[i]);
  9370. lua_rawseti(state, newTable, i + 1);
  9371. }
  9372. }
  9373. else
  9374. lua_pushnil(state);
  9375. return 1;
  9376. }
  9377. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9378. if (!lua_interface)
  9379. return 0;
  9380. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9381. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9382. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9383. lua_interface->ResetFunctionStack(state);
  9384. if (!spawn) {
  9385. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. if (anim_id == 0) {
  9389. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9390. return 0;
  9391. }
  9392. if (leeway == 0)
  9393. leeway = 5000;
  9394. spawn->SetSpawnAnim(anim_id);
  9395. spawn->SetSpawnAnimLeeway(leeway);
  9396. return 0;
  9397. }
  9398. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9399. if (!lua_interface)
  9400. return 0;
  9401. Spawn* player = lua_interface->GetSpawn(state);
  9402. lua_interface->ResetFunctionStack(state);
  9403. if (!player || !player->IsPlayer()) {
  9404. return 0;
  9405. }
  9406. Client* client = ((Player*)player)->GetClient();
  9407. if (!client) {
  9408. return 0;
  9409. }
  9410. lua_interface->SetInt32Value(state, client->GetVersion());
  9411. return 1;
  9412. }
  9413. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9414. if (!lua_interface)
  9415. return 0;
  9416. Item* item = lua_interface->GetItem(state);
  9417. lua_interface->ResetFunctionStack(state);
  9418. if (!item) {
  9419. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9420. return 0;
  9421. }
  9422. lua_interface->SetInt32Value(state, item->details.item_id);
  9423. return 1;
  9424. }
  9425. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9426. if (!lua_interface)
  9427. return 0;
  9428. Spawn* spawn = lua_interface->GetSpawn(state);
  9429. lua_interface->ResetFunctionStack(state);
  9430. if (!spawn) {
  9431. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9432. return 0;
  9433. }
  9434. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9435. return 1;
  9436. }
  9437. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9438. if (!lua_interface)
  9439. return 0;
  9440. Spawn* spawn = lua_interface->GetSpawn(state);
  9441. lua_interface->ResetFunctionStack(state);
  9442. if (!spawn) {
  9443. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9444. return 0;
  9445. }
  9446. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9447. return 1;
  9448. }
  9449. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9450. if (!lua_interface)
  9451. return 0;
  9452. Spawn* spawn = lua_interface->GetSpawn(state);
  9453. lua_interface->ResetFunctionStack(state);
  9454. if (!spawn) {
  9455. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9456. return 0;
  9457. }
  9458. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9459. return 1;
  9460. }
  9461. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9462. if (!lua_interface)
  9463. return 0;
  9464. Spawn* spawn = lua_interface->GetSpawn(state);
  9465. lua_interface->ResetFunctionStack(state);
  9466. if (!spawn) {
  9467. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9468. return 0;
  9469. }
  9470. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9471. return 1;
  9472. }
  9473. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. Spawn* spawn = lua_interface->GetSpawn(state);
  9477. float pct = lua_interface->GetFloatValue(state, 2);
  9478. lua_interface->ResetFunctionStack(state);
  9479. if (!spawn) {
  9480. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9481. return 0;
  9482. }
  9483. if (pct == 0) {
  9484. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9485. return 0;
  9486. }
  9487. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9488. lua_interface->SetInt32Value(state, amount);
  9489. return 1;
  9490. }
  9491. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9492. if (!lua_interface)
  9493. return 0;
  9494. Spawn* spawn = lua_interface->GetSpawn(state);
  9495. float pct = lua_interface->GetFloatValue(state, 2);
  9496. lua_interface->ResetFunctionStack(state);
  9497. if (!spawn) {
  9498. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9499. return 0;
  9500. }
  9501. if (pct == 0) {
  9502. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9503. return 0;
  9504. }
  9505. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9506. lua_interface->SetInt32Value(state, amount);
  9507. return 1;
  9508. }
  9509. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9510. if (!lua_interface)
  9511. return 0;
  9512. Spawn* spawn = lua_interface->GetSpawn(state);
  9513. lua_interface->ResetFunctionStack(state);
  9514. if (!spawn) {
  9515. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9516. return 0;
  9517. }
  9518. if (!spawn->IsPlayer()) {
  9519. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9520. return 0;
  9521. }
  9522. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9523. return 1;
  9524. }
  9525. int EQ2Emu_lua_Evac(lua_State* state) {
  9526. if (!lua_interface)
  9527. return 0;
  9528. Spawn* target = lua_interface->GetSpawn(state);
  9529. if (target) {
  9530. float x = target->GetZone()->GetSafeX();
  9531. float y = target->GetZone()->GetSafeY();
  9532. float z = target->GetZone()->GetSafeZ();
  9533. float h = target->GetZone()->GetSafeHeading();
  9534. target->SetX(x);
  9535. target->SetY(y);
  9536. target->SetZ(z);
  9537. target->SetHeading(h);
  9538. target->SetSpawnOrigX(x);
  9539. target->SetSpawnOrigY(y);
  9540. target->SetSpawnOrigZ(z);
  9541. target->SetSpawnOrigHeading(h);
  9542. if (target->IsPlayer()) {
  9543. Client* client = ((Player*)target)->GetClient();
  9544. if (client) {
  9545. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9546. int numargs = lua_interface->GetNumberOfArgs(state);
  9547. if(numargs == 4) {
  9548. x = lua_interface->GetFloatValue(state,1);
  9549. y = lua_interface->GetFloatValue(state,2);
  9550. z = lua_interface->GetFloatValue(state,3);
  9551. h = lua_interface->GetFloatValue(state,4);
  9552. }
  9553. client->SetReloadingZone(true);
  9554. target->SetX(x);
  9555. target->SetY(y);
  9556. target->SetZ(z);
  9557. target->SetHeading(h);
  9558. target->SetSpawnOrigX(x);
  9559. target->SetSpawnOrigY(y);
  9560. target->SetSpawnOrigZ(z);
  9561. target->SetSpawnOrigHeading(h);
  9562. target->SetAppearancePosition(x,y,z);
  9563. client->SetZoningCoords(x,y,z,h);
  9564. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9565. if (packet)
  9566. {
  9567. packet->setDataByName("x", x);
  9568. packet->setDataByName("y", y);
  9569. packet->setDataByName("z", z);
  9570. client->QueuePacket(packet->serialize());
  9571. safe_delete(packet);
  9572. }
  9573. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9574. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9575. }
  9576. }
  9577. lua_interface->ResetFunctionStack(state);
  9578. }
  9579. else {
  9580. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9581. if(!spell) {
  9582. lua_interface->ResetFunctionStack(state);
  9583. return 0;
  9584. }
  9585. ZoneServer* zone = spell->caster->GetZone();
  9586. float x = spell->caster->GetZone()->GetSafeX();
  9587. float y = spell->caster->GetZone()->GetSafeY();
  9588. float z = spell->caster->GetZone()->GetSafeZ();
  9589. float h = spell->caster->GetZone()->GetSafeHeading();
  9590. int numargs = lua_interface->GetNumberOfArgs(state);
  9591. if(numargs == 4) {
  9592. x = lua_interface->GetFloatValue(state,1);
  9593. y = lua_interface->GetFloatValue(state,2);
  9594. z = lua_interface->GetFloatValue(state,3);
  9595. h = lua_interface->GetFloatValue(state,4);
  9596. }
  9597. lua_interface->ResetFunctionStack(state);
  9598. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9599. for (int32 i = 0; i < spell->targets.size(); i++) {
  9600. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9601. if (!target2)
  9602. continue;
  9603. if (target2->IsPlayer()) {
  9604. Client* client = ((Player*)target2)->GetClient();
  9605. if (client) {
  9606. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9607. client->SetReloadingZone(true);
  9608. target2->SetX(x);
  9609. target2->SetY(y);
  9610. target2->SetZ(z);
  9611. target2->SetHeading(h);
  9612. target2->SetSpawnOrigX(x);
  9613. target2->SetSpawnOrigY(y);
  9614. target2->SetSpawnOrigZ(z);
  9615. target2->SetSpawnOrigHeading(h);
  9616. target2->SetAppearancePosition(x,y,z);
  9617. client->SetZoningCoords(x,y,z,h);
  9618. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9619. if (packet)
  9620. {
  9621. packet->setDataByName("x", x);
  9622. packet->setDataByName("y", y);
  9623. packet->setDataByName("z", z);
  9624. client->QueuePacket(packet->serialize());
  9625. safe_delete(packet);
  9626. }
  9627. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9628. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9629. }
  9630. }
  9631. }
  9632. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9633. }
  9634. return 0;
  9635. }
  9636. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9637. if (!lua_interface)
  9638. return 0;
  9639. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9640. lua_interface->ResetFunctionStack(state);
  9641. if (!luaspell) {
  9642. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9643. return 0;
  9644. }
  9645. int8 tier = luaspell->spell->GetSpellTier();
  9646. lua_interface->SetInt32Value(state, tier);
  9647. return 1;
  9648. }
  9649. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9650. if (!lua_interface)
  9651. return 0;
  9652. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9653. lua_interface->ResetFunctionStack(state);
  9654. if (!luaspell) {
  9655. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9656. return 0;
  9657. }
  9658. int32 spell_id = luaspell->spell->GetSpellID();
  9659. lua_interface->SetInt32Value(state, spell_id);
  9660. return 1;
  9661. }
  9662. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9663. if (!lua_interface)
  9664. return 0;
  9665. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9666. lua_interface->ResetFunctionStack(state);
  9667. if (!spawn) {
  9668. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9669. return 0;
  9670. }
  9671. if (!spawn->IsPlayer()) {
  9672. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9673. return 0;
  9674. }
  9675. ZoneServer* zone = spawn->GetZone();
  9676. if (!zone) {
  9677. return 0;
  9678. }
  9679. Client* client = ((Player*)spawn)->GetClient();
  9680. if (!client) {
  9681. return 0;
  9682. }
  9683. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9684. return 0;
  9685. }
  9686. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9687. if (!lua_interface)
  9688. return 0;
  9689. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9690. lua_interface->ResetFunctionStack(state);
  9691. if (!spawn) {
  9692. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9693. return 0;
  9694. }
  9695. if (!spawn->IsPlayer()) {
  9696. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9697. return 0;
  9698. }
  9699. ZoneServer* zone = spawn->GetZone();
  9700. if (!zone) {
  9701. return 0;
  9702. }
  9703. Client* client = ((Player*)spawn)->GetClient();
  9704. if (!client) {
  9705. return 0;
  9706. }
  9707. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9708. return 0;
  9709. }
  9710. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9711. if (!lua_interface)
  9712. return 0;
  9713. Spawn* caster = lua_interface->GetSpawn(state);
  9714. Spawn* target = lua_interface->GetSpawn(state, 2);
  9715. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9716. string spell_name = lua_interface->GetStringValue(state, 4);
  9717. lua_interface->ResetFunctionStack(state);
  9718. if (!caster) {
  9719. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9720. return 0;
  9721. }
  9722. if (!caster->IsEntity()) {
  9723. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9724. return 0;
  9725. }
  9726. if (!target) {
  9727. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9728. return 0;
  9729. }
  9730. if (!target->IsEntity()) {
  9731. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9732. return 0;
  9733. }
  9734. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9735. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9736. return 0;
  9737. }
  9738. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9739. if (!lua_interface)
  9740. return 0;
  9741. Spawn* player = lua_interface->GetSpawn(state);
  9742. int32 amount = lua_interface->GetInt32Value(state, 2);
  9743. lua_interface->ResetFunctionStack(state);
  9744. if (player && player->IsPlayer() && amount > 0) {
  9745. ((Player*)player)->AddXP(amount);
  9746. }
  9747. return 0;
  9748. }
  9749. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9750. if (!lua_interface)
  9751. return 0;
  9752. Spawn* player = lua_interface->GetSpawn(state);
  9753. int8 type = lua_interface->GetInt8Value(state, 2);
  9754. string text = lua_interface->GetStringValue(state, 3);
  9755. lua_interface->ResetFunctionStack(state);
  9756. Client* client = 0;
  9757. if (player && player->IsPlayer())
  9758. client = ((Player*)player)->GetClient();
  9759. if (!client || text.length() == 0) {
  9760. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9761. return 0;
  9762. }
  9763. client->SimpleMessage(type, text.c_str());
  9764. return 0;
  9765. }
  9766. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9767. if (!lua_interface)
  9768. return 0;
  9769. Spawn* player = lua_interface->GetSpawn(state);
  9770. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9771. lua_interface->ResetFunctionStack(state);
  9772. Client* client = 0;
  9773. if (player && player->IsPlayer())
  9774. client = ((Player*)player)->GetClient();
  9775. if (!client || !spawn) {
  9776. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9777. return 0;
  9778. }
  9779. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9780. if (!items) {
  9781. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9782. return 0;
  9783. }
  9784. client->Loot(spawn->GetLootCoins(), items, spawn);
  9785. return 0;
  9786. }
  9787. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9788. if (!lua_interface)
  9789. return 0;
  9790. Spawn* spawnref = lua_interface->GetSpawn(state);
  9791. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9792. lua_interface->ResetFunctionStack(state);
  9793. if (spawn_id > 0 && spawnref) {
  9794. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9795. if (spawns.size() == 0) {
  9796. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9797. return 0;
  9798. }
  9799. Spawn* spawn = 0;
  9800. int16 index = MakeRandomInt(0, spawns.size());
  9801. if (index >= spawns.size() || index < 0)
  9802. index = 0;
  9803. spawn = spawns[index];
  9804. lua_interface->SetSpawnValue(state, spawn);
  9805. return 1;
  9806. }
  9807. else {
  9808. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9809. }
  9810. return 0;
  9811. }
  9812. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9813. Spawn* player = lua_interface->GetSpawn(state);
  9814. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9815. string name = lua_interface->GetStringValue(state, 3);
  9816. float distance = lua_interface->GetFloatValue(state, 4);
  9817. string command = lua_interface->GetStringValue(state, 5);
  9818. string error_text = lua_interface->GetStringValue(state, 6);
  9819. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9820. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9821. lua_interface->ResetFunctionStack(state);
  9822. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9823. if (distance == 0)
  9824. distance = 10.0f;
  9825. if (command.length() == 0)
  9826. command = name;
  9827. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9828. if (spawns.size() == 0) {
  9829. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9830. return 0;
  9831. }
  9832. Spawn* spawn = 0;
  9833. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9834. spawn = *itr;
  9835. if (spawn) {
  9836. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9837. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9838. }
  9839. }
  9840. }
  9841. return 0;
  9842. }
  9843. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9844. if (!lua_interface)
  9845. return 0;
  9846. Client* client = 0;
  9847. Spawn* player = lua_interface->GetSpawn(state);
  9848. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9849. lua_interface->ResetFunctionStack(state);
  9850. if (player && player->IsPlayer() && player->GetZone())
  9851. client = ((Player*)player)->GetClient();
  9852. else{
  9853. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9854. return 0;
  9855. }
  9856. if (client) {
  9857. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9858. if (packet) {
  9859. packet->setDataByName("goal_num", goal_num);
  9860. client->QueuePacket(packet->serialize());
  9861. safe_delete(packet);
  9862. }
  9863. }
  9864. return 0;
  9865. }
  9866. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9867. if (!lua_interface)
  9868. return 0;
  9869. Client* client = 0;
  9870. Spawn* player = lua_interface->GetSpawn(state);
  9871. lua_interface->ResetFunctionStack(state);
  9872. if (player && player->IsPlayer() && player->GetZone())
  9873. client = ((Player*)player)->GetClient();
  9874. else {
  9875. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9876. return 0;
  9877. }
  9878. if (client) {
  9879. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9880. }
  9881. return 0;
  9882. }
  9883. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9884. if (!lua_interface)
  9885. return 0;
  9886. Client* client = 0;
  9887. Spawn* player = lua_interface->GetSpawn(state);
  9888. float duration = lua_interface->GetFloatValue(state, 2);
  9889. string text = lua_interface->GetStringValue(state, 3);
  9890. string voice = lua_interface->GetStringValue(state, 4);
  9891. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9892. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9893. string signal = lua_interface->GetStringValue(state, 7);
  9894. string goal1 = lua_interface->GetStringValue(state, 8);
  9895. string task1 = lua_interface->GetStringValue(state, 9);
  9896. string goal2 = lua_interface->GetStringValue(state, 10);
  9897. string task2 = lua_interface->GetStringValue(state, 11);
  9898. string goal3 = lua_interface->GetStringValue(state, 12);
  9899. string task3 = lua_interface->GetStringValue(state, 13);
  9900. string goal4 = lua_interface->GetStringValue(state, 14);
  9901. string task4 = lua_interface->GetStringValue(state, 15);
  9902. lua_interface->ResetFunctionStack(state);
  9903. if (!player) {
  9904. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9905. return 0;
  9906. }
  9907. if (!player->IsPlayer()) {
  9908. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9909. return 0;
  9910. }
  9911. else
  9912. client = ((Player*)player)->GetClient();
  9913. if (!client) {
  9914. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9915. return 0;
  9916. }
  9917. if (text.length() == 0) {
  9918. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9919. return 0;
  9920. }
  9921. if (duration >= 0 && duration < 2)
  9922. duration = 2;
  9923. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9924. if (packet) {
  9925. packet->setDataByName("open_seconds_max", duration);
  9926. packet->setDataByName("text", text.c_str());
  9927. packet->setDataByName("voice", voice.c_str());
  9928. int8 num_goals = 1;
  9929. if (task2.length() > 0)
  9930. num_goals++;
  9931. if (task3.length() > 0)
  9932. num_goals++;
  9933. if (task4.length() > 0)
  9934. num_goals++;
  9935. packet->setArrayLengthByName("num_goals", num_goals);
  9936. for (int8 i = 0; i < num_goals; i++) {
  9937. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9938. }
  9939. if (goal1.length() > 0)
  9940. packet->setArrayDataByName("goal_text", goal1.c_str());
  9941. if (goal2.length() > 0)
  9942. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9943. if (goal3.length() > 0)
  9944. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9945. if (goal4.length() > 0)
  9946. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9947. packet->setSubArrayDataByName("task_text", task1.c_str());
  9948. if (task2.length() > 0)
  9949. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9950. if (task3.length() > 0)
  9951. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9952. if (task4.length() > 0)
  9953. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9954. packet->setDataByName("complete_sound", "click");
  9955. packet->setDataByName("signal", signal.c_str());
  9956. packet->setDataByName("voice_key1", voice_key1);
  9957. packet->setDataByName("voice_key2", voice_key2);
  9958. client->QueuePacket(packet->serialize());
  9959. safe_delete(packet);
  9960. }
  9961. return 0;
  9962. }
  9963. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9964. if (!lua_interface)
  9965. return 0;
  9966. Client* client = 0;
  9967. Spawn* player = lua_interface->GetSpawn(state);
  9968. string window = lua_interface->GetStringValue(state, 2);
  9969. int8 show = lua_interface->GetInt8Value(state, 3);
  9970. lua_interface->ResetFunctionStack(state);
  9971. if (!player) {
  9972. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9973. return 0;
  9974. }
  9975. if (!player->IsPlayer()) {
  9976. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9977. return 0;
  9978. }
  9979. else
  9980. client = ((Player*)player)->GetClient();
  9981. if (!client) {
  9982. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9983. return 0;
  9984. }
  9985. if (window.length() == 0) {
  9986. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9987. return 0;
  9988. }
  9989. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9990. if (packet) {
  9991. packet->setDataByName("window", window.c_str());
  9992. packet->setDataByName("show", show);
  9993. client->QueuePacket(packet->serialize());
  9994. safe_delete(packet);
  9995. }
  9996. return 0;
  9997. }
  9998. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9999. //See GameEvents.txt for options that can be used for this function
  10000. if (!lua_interface)
  10001. return 0;
  10002. Client* client = 0;
  10003. Spawn* player = lua_interface->GetSpawn(state);
  10004. string event_name = lua_interface->GetStringValue(state, 2);
  10005. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10006. lua_interface->ResetFunctionStack(state);
  10007. if (!player || !player->IsPlayer()) {
  10008. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10009. return 0;
  10010. }
  10011. client = ((Player*)player)->GetClient();
  10012. if (!client) {
  10013. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10014. return 0;
  10015. }
  10016. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10017. if (packet) {
  10018. packet->setDataByName("event_name", event_name.c_str());
  10019. packet->setDataByName("enabled", enabled);
  10020. client->QueuePacket(packet->serialize());
  10021. safe_delete(packet);
  10022. }
  10023. return 0;
  10024. }
  10025. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10026. if (!lua_interface)
  10027. return 0;
  10028. Spawn* player = lua_interface->GetSpawn(state);
  10029. lua_interface->ResetFunctionStack(state);
  10030. if (player && player->IsPlayer()) {
  10031. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10032. return 1;
  10033. }
  10034. return 0;
  10035. }
  10036. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10037. if (!lua_interface)
  10038. return 0;
  10039. Spawn* player = lua_interface->GetSpawn(state);
  10040. int8 step = lua_interface->GetInt8Value(state, 2);
  10041. lua_interface->ResetFunctionStack(state);
  10042. if (player && player->IsPlayer() && step > 0) {
  10043. ((Player*)player)->SetTutorialStep(step);
  10044. }
  10045. return 0;
  10046. }
  10047. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10048. if (!lua_interface)
  10049. return 0;
  10050. Client* client = 0;
  10051. Spawn* player = lua_interface->GetSpawn(state);
  10052. string window = lua_interface->GetStringValue(state, 2);
  10053. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10054. lua_interface->ResetFunctionStack(state);
  10055. if (!player) {
  10056. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10057. return 0;
  10058. }
  10059. if (!player->IsPlayer()) {
  10060. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10061. return 0;
  10062. }
  10063. else
  10064. client = ((Player*)player)->GetClient();
  10065. if (!client) {
  10066. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10067. return 0;
  10068. }
  10069. if (window.length() == 0) {
  10070. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10071. return 0;
  10072. }
  10073. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10074. if (packet) {
  10075. packet->setDataByName("window", window.c_str());
  10076. packet->setDataByName("flash_seconds", flash_seconds);
  10077. client->QueuePacket(packet->serialize());
  10078. safe_delete(packet);
  10079. }
  10080. return 0;
  10081. }
  10082. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10083. if (!lua_interface)
  10084. return 0;
  10085. Spawn* spawn = lua_interface->GetSpawn(state);
  10086. Spawn* target = lua_interface->GetSpawn(state, 2);
  10087. lua_interface->ResetFunctionStack(state);
  10088. if (spawn && target)
  10089. return spawn->CheckLoS(target);
  10090. return 0;
  10091. }
  10092. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10093. if (!lua_interface)
  10094. return 0;
  10095. Spawn* spawn = lua_interface->GetSpawn(state);
  10096. float x = lua_interface->GetFloatValue(state, 2);
  10097. float y = lua_interface->GetFloatValue(state, 3);
  10098. float z = lua_interface->GetFloatValue(state, 4);
  10099. lua_interface->ResetFunctionStack(state);
  10100. if (spawn)
  10101. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10102. return 0;
  10103. }
  10104. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10105. if (!lua_interface)
  10106. return 0;
  10107. ZoneServer* zone = lua_interface->GetZone(state);
  10108. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10109. lua_interface->ResetFunctionStack(state);
  10110. if (zone)
  10111. zone->SetExpansionFlag(xpackFlag);
  10112. return 0;
  10113. }
  10114. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10115. if (!lua_interface)
  10116. return 0;
  10117. ZoneServer* zone = lua_interface->GetZone(state);
  10118. lua_interface->ResetFunctionStack(state);
  10119. if (zone) {
  10120. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10121. return 1;
  10122. }
  10123. return 0;
  10124. }
  10125. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10126. if (!lua_interface)
  10127. return 0;
  10128. ZoneServer* zone = lua_interface->GetZone(state);
  10129. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10130. lua_interface->ResetFunctionStack(state);
  10131. if (zone)
  10132. zone->SetHolidayFlag(holidayFlag);
  10133. return 0;
  10134. }
  10135. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10136. if (!lua_interface)
  10137. return 0;
  10138. ZoneServer* zone = lua_interface->GetZone(state);
  10139. lua_interface->ResetFunctionStack(state);
  10140. if (zone) {
  10141. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10142. return 1;
  10143. }
  10144. return 0;
  10145. }
  10146. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10147. if (!lua_interface)
  10148. return 0;
  10149. Spawn* player = lua_interface->GetSpawn(state);
  10150. ZoneServer* zone = player->GetZone();
  10151. bool canbind = lua_interface->GetInt32Value(state, 2);
  10152. lua_interface->ResetFunctionStack(state);
  10153. if (zone)
  10154. zone->SetCanBind(canbind);
  10155. return 0;
  10156. }
  10157. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10158. if (!lua_interface)
  10159. return 0;
  10160. Spawn* player = lua_interface->GetSpawn(state);
  10161. ZoneServer* zone = player->GetZone();
  10162. lua_interface->ResetFunctionStack(state);
  10163. if (zone) {
  10164. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10165. return 1;
  10166. }
  10167. return 0;
  10168. }
  10169. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10170. if (!lua_interface)
  10171. return 0;
  10172. Spawn* player = lua_interface->GetSpawn(state);
  10173. ZoneServer* zone = player->GetZone();
  10174. bool cangate = lua_interface->GetInt32Value(state, 2);
  10175. lua_interface->ResetFunctionStack(state);
  10176. if (zone)
  10177. zone->SetCanGate(cangate);
  10178. return 0;
  10179. }
  10180. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10181. if (!lua_interface)
  10182. return 0;
  10183. Spawn* player = lua_interface->GetSpawn(state);
  10184. ZoneServer* zone = player->GetZone();
  10185. lua_interface->ResetFunctionStack(state);
  10186. if (zone) {
  10187. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10188. return 1;
  10189. }
  10190. return 0;
  10191. }
  10192. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10193. if (!lua_interface)
  10194. return 0;
  10195. Spawn* spawn = lua_interface->GetSpawn(state);
  10196. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10197. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10198. float distance = lua_interface->GetFloatValue(state, 4);
  10199. string in_range_function = lua_interface->GetStringValue(state, 5);
  10200. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10201. lua_interface->ResetFunctionStack(state);
  10202. if (spawn && distance > 0 && in_range_function.length() > 0)
  10203. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10204. return 0;
  10205. }
  10206. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10207. if (!lua_interface)
  10208. return 0;
  10209. Spawn* spawn = lua_interface->GetSpawn(state);
  10210. Spawn* target = lua_interface->GetSpawn(state, 2);
  10211. lua_interface->ResetFunctionStack(state);
  10212. if (spawn && target)
  10213. {
  10214. if (spawn->IsPlayer() && target->IsEntity())
  10215. {
  10216. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10217. return 1;
  10218. }
  10219. else if (spawn->IsEntity() && target->IsEntity())
  10220. {
  10221. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10222. return 1;
  10223. }
  10224. }
  10225. return 0;
  10226. }
  10227. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10228. if (!lua_interface)
  10229. return 0;
  10230. Spawn* spawn = lua_interface->GetSpawn(state);
  10231. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10232. lua_interface->ResetFunctionStack(state);
  10233. if (spawn && spawn->IsEntity())
  10234. {
  10235. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10236. if (spawn->IsPlayer())
  10237. {
  10238. Client* client = ((Player*)spawn)->GetClient();
  10239. if (client)
  10240. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10241. }
  10242. }
  10243. return 0;
  10244. }
  10245. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10246. if (!lua_interface)
  10247. return 0;
  10248. Spawn* spawn = lua_interface->GetSpawn(state);
  10249. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10250. lua_interface->ResetFunctionStack(state);
  10251. if (spawn && spawn->IsEntity())
  10252. {
  10253. ((Entity*)spawn)->SetSeeHideSpell(val);
  10254. if (spawn->IsPlayer())
  10255. {
  10256. Client* client = ((Player*)spawn)->GetClient();
  10257. if (client)
  10258. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10259. }
  10260. }
  10261. return 0;
  10262. }
  10263. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10264. {
  10265. if (!lua_interface)
  10266. return 0;
  10267. Spawn* player = lua_interface->GetSpawn(state);
  10268. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10269. string command = lua_interface->GetStringValue(state, 3);
  10270. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10271. lua_interface->ResetFunctionStack(state);
  10272. if (spawn && player && player->IsPlayer())
  10273. {
  10274. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10275. bool res = false;
  10276. if (cmd)
  10277. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10278. lua_interface->SetBooleanValue(state, res);
  10279. return 1;
  10280. }
  10281. return 0;
  10282. }
  10283. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10284. {
  10285. if (!lua_interface)
  10286. return 0;
  10287. Spawn* spawn = lua_interface->GetSpawn(state);
  10288. int32 charID = lua_interface->GetInt32Value(state, 2);
  10289. string command = lua_interface->GetStringValue(state, 3);
  10290. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10291. lua_interface->ResetFunctionStack(state);
  10292. if (spawn && charID)
  10293. {
  10294. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10295. bool res = false;
  10296. if (cmd)
  10297. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10298. lua_interface->SetBooleanValue(state, res);
  10299. return 1;
  10300. }
  10301. return 0;
  10302. }
  10303. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10304. {
  10305. if (!lua_interface)
  10306. return 0;
  10307. Spawn* spawn = lua_interface->GetSpawn(state);
  10308. string command = lua_interface->GetStringValue(state, 2);
  10309. lua_interface->ResetFunctionStack(state);
  10310. if (spawn && command.length() > 0)
  10311. spawn->RemovePrimaryEntityCommand(command.c_str());
  10312. return 0;
  10313. }
  10314. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10315. if (!lua_interface)
  10316. return 0;
  10317. Spawn* spawn = lua_interface->GetSpawn(state);
  10318. float distance = lua_interface->GetFloatValue(state, 2);
  10319. string command = lua_interface->GetStringValue(state, 3);
  10320. Spawn* player = lua_interface->GetSpawn(state, 4);
  10321. lua_interface->ResetFunctionStack(state);
  10322. if (spawn) {
  10323. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10324. }
  10325. return 0;
  10326. }
  10327. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10328. if (!lua_interface)
  10329. return 0;
  10330. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10331. Spawn* spawn = lua_interface->GetSpawn(state);
  10332. Spawn* player = lua_interface->GetSpawn(state, 2);
  10333. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10334. lua_interface->ResetFunctionStack(state);
  10335. if (spawn && player && transport_id && player->IsPlayer()) {
  10336. Client* client = 0;
  10337. if (player && player->IsPlayer())
  10338. client = ((Player*)player)->GetClient();
  10339. if (!client)
  10340. return 0;
  10341. vector<TransportDestination*> destinations;
  10342. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10343. if (destinations.size())
  10344. {
  10345. client->SetTemporaryTransportID(transport_id);
  10346. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10347. }
  10348. else
  10349. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10350. }
  10351. return 0;
  10352. }
  10353. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10354. if (!lua_interface)
  10355. return 0;
  10356. Spawn* player = lua_interface->GetSpawn(state);
  10357. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10358. lua_interface->ResetFunctionStack(state);
  10359. if (player && player->IsPlayer()) {
  10360. Client* client = 0;
  10361. if (player && player->IsPlayer())
  10362. client = ((Player*)player)->GetClient();
  10363. if (!client)
  10364. return 0;
  10365. client->SetTemporaryTransportID(transport_id);
  10366. }
  10367. return 0;
  10368. }
  10369. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10370. if (!lua_interface)
  10371. return 0;
  10372. Spawn* player = lua_interface->GetSpawn(state);
  10373. lua_interface->ResetFunctionStack(state);
  10374. if (player && player->IsPlayer()) {
  10375. Client* client = 0;
  10376. if (player && player->IsPlayer())
  10377. client = ((Player*)player)->GetClient();
  10378. if (!client)
  10379. return 0;
  10380. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10381. return 1;
  10382. }
  10383. return 0;
  10384. }
  10385. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10386. if (!lua_interface)
  10387. return 0;
  10388. Spawn* spawn = lua_interface->GetSpawn(state);
  10389. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10390. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10391. if (!spawn) {
  10392. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10393. return 0;
  10394. }
  10395. if (!spawn->IsEntity()) {
  10396. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10397. return 0;
  10398. }
  10399. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10400. {
  10401. 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);
  10402. return 0;
  10403. }
  10404. lua_interface->ResetFunctionStack(state);
  10405. if (spell && spell->targets.size() > 0) {
  10406. ZoneServer* zone = spell->caster->GetZone();
  10407. for (int8 i = 0; i < spell->targets.size(); i++) {
  10408. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10409. if (target && target->IsEntity()) {
  10410. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10411. if (target->IsPlayer())
  10412. ((Player*)target)->SetCharSheetChanged(true);
  10413. }
  10414. }
  10415. }
  10416. else {
  10417. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10418. if (spawn->IsPlayer())
  10419. ((Player*)spawn)->SetCharSheetChanged(true);
  10420. }
  10421. return 0;
  10422. }
  10423. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10424. if (!lua_interface)
  10425. return 0;
  10426. Spawn* spawn = lua_interface->GetSpawn(state);
  10427. lua_interface->ResetFunctionStack(state);
  10428. if (!spawn) {
  10429. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10430. return 0;
  10431. }
  10432. if (!spawn->IsEntity()) {
  10433. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10434. return 0;
  10435. }
  10436. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10437. return 1;
  10438. }
  10439. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10440. if (!lua_interface)
  10441. return 0;
  10442. int32 spell_id = lua_interface->GetInt32Value(state);
  10443. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10444. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10445. if (spell_id > 0) {
  10446. if (spell_tier == 0)
  10447. spell_tier = 1;
  10448. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10449. LuaSpell* lua_spell = 0;
  10450. if(custom_lua_script.size() > 0)
  10451. {
  10452. // attempt to load the custom script since it isn't already loaded
  10453. // we will re-obtain the lua_spell further below
  10454. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10455. {
  10456. 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());
  10457. lua_interface->LoadLuaSpell(custom_lua_script);
  10458. }
  10459. }
  10460. else
  10461. custom_lua_script = spell->GetSpellData()->lua_script;
  10462. if (!lua_spell && lua_interface)
  10463. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10464. if (!lua_spell)
  10465. {
  10466. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10467. return 0;
  10468. }
  10469. lua_spell->spell = new Spell(spell);
  10470. lua_interface->AddCustomSpell(lua_spell);
  10471. lua_interface->SetSpellValue(state, lua_spell);
  10472. return 1;
  10473. }
  10474. return 0;
  10475. }
  10476. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10477. if (!lua_interface)
  10478. return 0;
  10479. LuaSpell* spell = lua_interface->GetSpell(state);
  10480. string field = lua_interface->GetStringValue(state, 2);
  10481. if (!spell) {
  10482. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10483. return 0;
  10484. }
  10485. if (!spell->spell || !spell->spell->GetSpellData()) {
  10486. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10487. return 0;
  10488. }
  10489. boost::to_lower(field);
  10490. return spell->spell->GetSpellData(state, field);
  10491. }
  10492. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10493. if (!lua_interface)
  10494. return 0;
  10495. LuaSpell* spell = lua_interface->GetSpell(state);
  10496. string field = lua_interface->GetStringValue(state, 2);
  10497. int8 fieldArg = 3; // field value after the initial set
  10498. if (!spell) {
  10499. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10500. return 0;
  10501. }
  10502. if (!spell->spell || !spell->spell->GetSpellData()) {
  10503. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10504. return 0;
  10505. }
  10506. boost::to_lower(field);
  10507. bool valSet = false;
  10508. spell->spell->SetSpellData(state, field, fieldArg);
  10509. return valSet;
  10510. }
  10511. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10512. if (!lua_interface)
  10513. return 0;
  10514. LuaSpell* spell = lua_interface->GetSpell(state);
  10515. int8 idx = lua_interface->GetInt32Value(state, 2);
  10516. if (!spell) {
  10517. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10518. return 0;
  10519. }
  10520. if (!spell->spell || !spell->spell->GetSpellData()) {
  10521. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10522. return 0;
  10523. }
  10524. if (spell->spell->lua_data.size() <= idx)
  10525. {
  10526. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10527. return 0;
  10528. }
  10529. bool setVal = true;
  10530. LUAData* data = spell->spell->lua_data[idx];
  10531. switch (data->type)
  10532. {
  10533. case 0:
  10534. {
  10535. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10536. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10537. data->int_value = value;
  10538. data->int_value2 = value2;
  10539. break;
  10540. }
  10541. case 1:
  10542. {
  10543. float value = lua_interface->GetFloatValue(state, 3);
  10544. float value2 = lua_interface->GetFloatValue(state, 4);
  10545. data->float_value = value;
  10546. data->float_value2 = value2;
  10547. break;
  10548. }
  10549. case 2:
  10550. {
  10551. bool value = lua_interface->GetBooleanValue(state, 3);
  10552. data->bool_value = value;
  10553. break;
  10554. }
  10555. case 3:
  10556. {
  10557. string value = lua_interface->GetStringValue(state, 3);
  10558. string value2 = lua_interface->GetStringValue(state, 4);
  10559. data->string_value = value;
  10560. data->string_value2 = value2;
  10561. break;
  10562. }
  10563. default:
  10564. setVal = false;
  10565. }
  10566. return setVal;
  10567. }
  10568. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10569. if (!lua_interface)
  10570. return 0;
  10571. LuaSpell* spell = lua_interface->GetSpell(state);
  10572. int8 idx = lua_interface->GetInt32Value(state, 2);
  10573. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10574. if (!spell) {
  10575. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10576. return 0;
  10577. }
  10578. if (!spell->spell || !spell->spell->GetSpellData()) {
  10579. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10580. return 0;
  10581. }
  10582. if (spell->spell->lua_data.size() <= idx)
  10583. {
  10584. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10585. return 0;
  10586. }
  10587. bool setVal = true;
  10588. LUAData* data = spell->spell->lua_data[idx];
  10589. switch (data->type)
  10590. {
  10591. case 0:
  10592. {
  10593. if(!secondfield)
  10594. lua_interface->SetSInt32Value(state, data->int_value);
  10595. else
  10596. lua_interface->SetSInt32Value(state, data->int_value2);
  10597. break;
  10598. }
  10599. case 1:
  10600. {
  10601. if (!secondfield)
  10602. lua_interface->SetFloatValue(state, data->float_value);
  10603. else
  10604. lua_interface->SetFloatValue(state, data->float_value2);
  10605. break;
  10606. }
  10607. case 2:
  10608. {
  10609. lua_interface->SetBooleanValue(state, data->bool_value);
  10610. break;
  10611. }
  10612. case 3:
  10613. {
  10614. if (!secondfield)
  10615. lua_interface->SetStringValue(state, data->string_value.c_str());
  10616. else
  10617. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10618. break;
  10619. }
  10620. default:
  10621. setVal = false;
  10622. }
  10623. return setVal;
  10624. }
  10625. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10626. if (!lua_interface)
  10627. return 0;
  10628. LuaSpell* spell = lua_interface->GetSpell(state);
  10629. int8 idx = lua_interface->GetInt32Value(state, 2);
  10630. string field = lua_interface->GetStringValue(state, 3);
  10631. boost::to_lower(field);
  10632. if (!spell) {
  10633. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10634. return 0;
  10635. }
  10636. if (!spell->spell || !spell->spell->GetSpellData()) {
  10637. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10638. return 0;
  10639. }
  10640. if (spell->spell->effects.size() <= idx)
  10641. {
  10642. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10643. return 0;
  10644. }
  10645. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10646. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10647. if (field == "description")
  10648. effect->description = string(lua_interface->GetStringValue(state, 4));
  10649. else if (field == "bullet")
  10650. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10651. else if (field == "percentage")
  10652. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10653. else // no match
  10654. return 0;
  10655. return 1;
  10656. }
  10657. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10658. if (!lua_interface)
  10659. return 0;
  10660. LuaSpell* spell = lua_interface->GetSpell(state);
  10661. int8 idx = lua_interface->GetInt32Value(state, 2);
  10662. string field = lua_interface->GetStringValue(state, 3);
  10663. boost::to_lower(field);
  10664. if (!spell) {
  10665. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10666. return 0;
  10667. }
  10668. if (!spell->spell || !spell->spell->GetSpellData()) {
  10669. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10670. return 0;
  10671. }
  10672. if (spell->spell->effects.size() <= idx)
  10673. {
  10674. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10675. return 0;
  10676. }
  10677. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10678. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10679. if (field == "description")
  10680. lua_interface->SetStringValue(state, effect->description.c_str());
  10681. else if (field == "bullet")
  10682. lua_interface->SetInt32Value(state, effect->subbullet);
  10683. else if (field == "percentage")
  10684. lua_interface->SetInt32Value(state, effect->percentage);
  10685. else // no match
  10686. return 0;
  10687. return 1;
  10688. }
  10689. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10690. if (!lua_interface)
  10691. return 0;
  10692. LuaSpell* spell = lua_interface->GetSpell(state);
  10693. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10694. Spawn* target = lua_interface->GetSpawn(state, 3);
  10695. if (!target) {
  10696. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10697. return 0;
  10698. }
  10699. if (!target->IsEntity()) {
  10700. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10701. return 0;
  10702. }
  10703. if (!spell) {
  10704. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10705. return 0;
  10706. }
  10707. if (caster && !caster->IsEntity()) {
  10708. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10709. return 0;
  10710. }
  10711. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10712. return 0;
  10713. }
  10714. int EQ2Emu_lua_InWater(lua_State* state) {
  10715. if (!lua_interface)
  10716. return 0;
  10717. Spawn* spawn = lua_interface->GetSpawn(state);
  10718. lua_interface->ResetFunctionStack(state);
  10719. if (spawn) {
  10720. lua_interface->SetBooleanValue(state, spawn->InWater());
  10721. return 1;
  10722. }
  10723. return 0;
  10724. }
  10725. int EQ2Emu_lua_InLava(lua_State* state) {
  10726. if (!lua_interface)
  10727. return 0;
  10728. Spawn* spawn = lua_interface->GetSpawn(state);
  10729. lua_interface->ResetFunctionStack(state);
  10730. if (spawn) {
  10731. lua_interface->SetBooleanValue(state, spawn->InLava());
  10732. return 1;
  10733. }
  10734. return 0;
  10735. }
  10736. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10737. if (!lua_interface)
  10738. return 0;
  10739. Spawn* attacker = lua_interface->GetSpawn(state);
  10740. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10741. int8 type = lua_interface->GetInt8Value(state, 3);
  10742. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10743. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10744. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10745. string spell_name = lua_interface->GetStringValue(state, 7);
  10746. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10747. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10748. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10749. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10750. lua_interface->ResetFunctionStack(state);
  10751. if (!attacker) {
  10752. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10753. return 0;
  10754. }
  10755. if (!attacker->IsEntity()) {
  10756. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10757. return 0;
  10758. }
  10759. if (!victim) {
  10760. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10761. return 0;
  10762. }
  10763. if (!victim->IsEntity()) {
  10764. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10765. return 0;
  10766. }
  10767. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10768. return 0;
  10769. }
  10770. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10771. if (!lua_interface)
  10772. return 0;
  10773. Spawn* spawn = lua_interface->GetSpawn(state);
  10774. lua_interface->ResetFunctionStack(state);
  10775. if (spawn) {
  10776. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10777. return 1;
  10778. }
  10779. return 0;
  10780. }
  10781. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10782. if (!lua_interface)
  10783. return 0;
  10784. Spawn* spawn = lua_interface->GetSpawn(state);
  10785. bool invul = lua_interface->GetBooleanValue(state, 2);
  10786. lua_interface->ResetFunctionStack(state);
  10787. if (spawn) {
  10788. spawn->SetInvulnerable(invul);
  10789. }
  10790. return 0;
  10791. }
  10792. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10793. if (!lua_interface)
  10794. return 0;
  10795. string category = lua_interface->GetStringValue(state);
  10796. string name = lua_interface->GetStringValue(state, 2);
  10797. lua_interface->ResetFunctionStack(state);
  10798. Rule *ret = 0;
  10799. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10800. lua_interface->SetBooleanValue(state, ret->GetBool());
  10801. return 1;
  10802. }
  10803. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10804. return 0;
  10805. }
  10806. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10807. if (!lua_interface)
  10808. return 0;
  10809. string category = lua_interface->GetStringValue(state);
  10810. string name = lua_interface->GetStringValue(state, 2);
  10811. lua_interface->ResetFunctionStack(state);
  10812. Rule *ret = 0;
  10813. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10814. lua_interface->SetInt32Value(state, ret->GetInt32());
  10815. return 1;
  10816. }
  10817. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10818. return 0;
  10819. }
  10820. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10821. if (!lua_interface)
  10822. return 0;
  10823. string category = lua_interface->GetStringValue(state);
  10824. string name = lua_interface->GetStringValue(state, 2);
  10825. lua_interface->ResetFunctionStack(state);
  10826. Rule *ret = 0;
  10827. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10828. lua_interface->SetFloatValue(state, ret->GetFloat());
  10829. return 1;
  10830. }
  10831. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10832. return 0;
  10833. }
  10834. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10835. if (!lua_interface)
  10836. return 0;
  10837. Spawn* spawn = lua_interface->GetSpawn(state);
  10838. string type = lua_interface->GetStringValue(state, 2);
  10839. lua_interface->ResetFunctionStack(state);
  10840. if (spawn) {
  10841. int res = 1;
  10842. boost::to_lower(type);
  10843. if(type == "assigned_aa")
  10844. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10845. else if ( type == "unassigned_aa")
  10846. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10847. else if ( type == "assigned_tradeskill_aa")
  10848. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10849. else if ( type == "unassigned_tradeskill_aa")
  10850. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10851. else if ( type == "assigned_prestige_aa")
  10852. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10853. else if ( type == "unassigned_prestige_aa")
  10854. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10855. else if ( type == "assigned_tradeskill_prestige_aa")
  10856. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10857. else if ( type == "unassigned_tradeskill_prestige_aa")
  10858. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10859. else
  10860. res = 0;
  10861. return res;
  10862. }
  10863. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10864. return 0;
  10865. }
  10866. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10867. if (!lua_interface)
  10868. return 0;
  10869. Spawn* spawn = lua_interface->GetSpawn(state);
  10870. string type = lua_interface->GetStringValue(state, 2);
  10871. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10872. lua_interface->ResetFunctionStack(state);
  10873. if (spawn) {
  10874. boost::to_lower(type);
  10875. if(type == "assigned_aa")
  10876. spawn->SetAssignedAA((sint16)value);
  10877. else if ( type == "unassigned_aa")
  10878. spawn->SetUnassignedAA((sint16)value);
  10879. else if ( type == "assigned_tradeskill_aa")
  10880. spawn->SetTradeskillAA((sint16)value);
  10881. else if ( type == "unassigned_tradeskill_aa")
  10882. spawn->SetUnassignedTradeskillAA((sint16)value);
  10883. else if ( type == "assigned_prestige_aa")
  10884. spawn->SetPrestigeAA((sint16)value);
  10885. else if ( type == "unassigned_prestige_aa")
  10886. spawn->SetUnassignedPrestigeAA((sint16)value);
  10887. else if ( type == "assigned_tradeskill_prestige_aa")
  10888. spawn->SetTradeskillPrestigeAA((sint16)value);
  10889. else if ( type == "unassigned_tradeskill_prestige_aa")
  10890. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10891. if(spawn->IsPlayer())
  10892. ((Player*)spawn)->SetCharSheetChanged(true);
  10893. }
  10894. return 0;
  10895. }
  10896. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10897. if (!lua_interface)
  10898. return 0;
  10899. string titleName = lua_interface->GetStringValue(state);
  10900. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10901. lua_interface->ResetFunctionStack(state);
  10902. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10903. lua_interface->SetSInt32Value(state, index);
  10904. return 1;
  10905. }
  10906. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10907. if (!lua_interface)
  10908. return 0;
  10909. Spawn* spawn = lua_interface->GetSpawn(state);
  10910. string titleName = lua_interface->GetStringValue(state, 2);
  10911. lua_interface->ResetFunctionStack(state);
  10912. if(!spawn->IsPlayer())
  10913. {
  10914. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10915. lua_interface->SetSInt32Value(state, -1);
  10916. return 1;
  10917. }
  10918. Player* player = (Player*)spawn;
  10919. // check if player already has the title, don't need to add twice
  10920. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10921. if ( playerHasTitle)
  10922. {
  10923. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10924. return 1;
  10925. }
  10926. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10927. if(!title)
  10928. {
  10929. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10930. lua_interface->SetSInt32Value(state, -1);
  10931. return 1;
  10932. }
  10933. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10934. if(returnIdx < 0)
  10935. {
  10936. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10937. }
  10938. lua_interface->SetSInt32Value(state, returnIdx);
  10939. player->GetClient()->SendTitleUpdate();
  10940. return 1;
  10941. }
  10942. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10943. if (!lua_interface)
  10944. return 0;
  10945. Spawn* spawn = lua_interface->GetSpawn(state);
  10946. string titleName = lua_interface->GetStringValue(state, 2);
  10947. lua_interface->ResetFunctionStack(state);
  10948. if(!spawn->IsPlayer())
  10949. {
  10950. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10951. return 0;
  10952. }
  10953. Player* player = (Player*)spawn;
  10954. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10955. if(!title)
  10956. {
  10957. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10958. return 0;
  10959. }
  10960. if(title->GetPrefix())
  10961. {
  10962. 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());
  10963. return 0;
  10964. }
  10965. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10966. player->GetClient()->SendTitleUpdate();
  10967. return 1;
  10968. }
  10969. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10970. if (!lua_interface)
  10971. return 0;
  10972. Spawn* spawn = lua_interface->GetSpawn(state);
  10973. string titleName = lua_interface->GetStringValue(state, 2);
  10974. lua_interface->ResetFunctionStack(state);
  10975. if(!spawn->IsPlayer())
  10976. {
  10977. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10978. return 0;
  10979. }
  10980. Player* player = (Player*)spawn;
  10981. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10982. if(!title)
  10983. {
  10984. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10985. return 0;
  10986. }
  10987. if(!title->GetPrefix())
  10988. {
  10989. 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());
  10990. return 0;
  10991. }
  10992. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10993. player->GetClient()->SendTitleUpdate();
  10994. return 1;
  10995. }
  10996. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10997. if (!lua_interface)
  10998. return 0;
  10999. Spawn* spawn = lua_interface->GetSpawn(state);
  11000. lua_interface->ResetFunctionStack(state);
  11001. if(!spawn->IsPlayer())
  11002. {
  11003. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11004. return 0;
  11005. }
  11006. Player* player = (Player*)spawn;
  11007. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11008. player->GetClient()->SendTitleUpdate();
  11009. return 1;
  11010. }
  11011. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11012. if (!lua_interface)
  11013. return 0;
  11014. Spawn* spawn = lua_interface->GetSpawn(state);
  11015. lua_interface->ResetFunctionStack(state);
  11016. if(!spawn->IsPlayer())
  11017. {
  11018. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11019. return 0;
  11020. }
  11021. Player* player = (Player*)spawn;
  11022. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11023. player->GetClient()->SendTitleUpdate();
  11024. return 1;
  11025. }
  11026. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11027. if (!lua_interface)
  11028. return 0;
  11029. Spawn* spawn = lua_interface->GetSpawn(state);
  11030. string field = lua_interface->GetStringValue(state, 2);
  11031. lua_interface->ResetFunctionStack(state);
  11032. if(!spawn || !spawn->IsEntity())
  11033. {
  11034. 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));
  11035. return 0;
  11036. }
  11037. Entity* ent = (Entity*)spawn;
  11038. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11039. return 1;
  11040. }
  11041. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11042. if (!lua_interface)
  11043. return 0;
  11044. Spawn* spawn = lua_interface->GetSpawn(state);
  11045. string field = lua_interface->GetStringValue(state, 2);
  11046. lua_interface->ResetFunctionStack(state);
  11047. if(!spawn || !spawn->IsEntity())
  11048. {
  11049. 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));
  11050. return 0;
  11051. }
  11052. Entity* ent = (Entity*)spawn;
  11053. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11054. return 1;
  11055. }
  11056. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11057. if (!lua_interface)
  11058. return 0;
  11059. Spawn* spawn = lua_interface->GetSpawn(state);
  11060. string field = lua_interface->GetStringValue(state, 2);
  11061. lua_interface->ResetFunctionStack(state);
  11062. if(!spawn || !spawn->IsEntity())
  11063. {
  11064. 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));
  11065. return 0;
  11066. }
  11067. Entity* ent = (Entity*)spawn;
  11068. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11069. return 1;
  11070. }
  11071. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11072. if (!lua_interface)
  11073. return 0;
  11074. Spawn* spawn = lua_interface->GetSpawn(state);
  11075. string field = lua_interface->GetStringValue(state, 2);
  11076. lua_interface->ResetFunctionStack(state);
  11077. if(!spawn || !spawn->IsEntity())
  11078. {
  11079. 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));
  11080. return 0;
  11081. }
  11082. Entity* ent = (Entity*)spawn;
  11083. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11084. return 1;
  11085. }
  11086. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11087. if (!lua_interface)
  11088. return 0;
  11089. Spawn* spawn = lua_interface->GetSpawn(state);
  11090. string field = lua_interface->GetStringValue(state, 2);
  11091. string value = lua_interface->GetStringValue(state, 3);
  11092. lua_interface->ResetFunctionStack(state);
  11093. if(!spawn || !spawn->IsEntity())
  11094. {
  11095. 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));
  11096. return 0;
  11097. }
  11098. Entity* ent = (Entity*)spawn;
  11099. bool set_ = ent->SetInfoStructString(field, value);
  11100. lua_interface->SetBooleanValue(state, set_);
  11101. return 1;
  11102. }
  11103. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11104. if (!lua_interface)
  11105. return 0;
  11106. Spawn* spawn = lua_interface->GetSpawn(state);
  11107. string field = lua_interface->GetStringValue(state, 2);
  11108. int64 value = lua_interface->GetInt64Value(state, 3);
  11109. lua_interface->ResetFunctionStack(state);
  11110. if(!spawn || !spawn->IsEntity())
  11111. {
  11112. 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));
  11113. return 0;
  11114. }
  11115. Entity* ent = (Entity*)spawn;
  11116. bool set_ = ent->SetInfoStructUInt(field, value);
  11117. lua_interface->SetBooleanValue(state, set_);
  11118. return 1;
  11119. }
  11120. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11121. if (!lua_interface)
  11122. return 0;
  11123. Spawn* spawn = lua_interface->GetSpawn(state);
  11124. string field = lua_interface->GetStringValue(state, 2);
  11125. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11126. lua_interface->ResetFunctionStack(state);
  11127. if(!spawn || !spawn->IsEntity())
  11128. {
  11129. 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));
  11130. return 0;
  11131. }
  11132. Entity* ent = (Entity*)spawn;
  11133. bool set_ = ent->SetInfoStructSInt(field, value);
  11134. lua_interface->SetBooleanValue(state, set_);
  11135. return 1;
  11136. }
  11137. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11138. if (!lua_interface)
  11139. return 0;
  11140. Spawn* spawn = lua_interface->GetSpawn(state);
  11141. string field = lua_interface->GetStringValue(state, 2);
  11142. float value = lua_interface->GetFloatValue(state, 3);
  11143. lua_interface->ResetFunctionStack(state);
  11144. if(!spawn || !spawn->IsEntity())
  11145. {
  11146. 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));
  11147. return 0;
  11148. }
  11149. Entity* ent = (Entity*)spawn;
  11150. bool set_ = ent->SetInfoStructFloat(field, value);
  11151. lua_interface->SetBooleanValue(state, set_);
  11152. return 1;
  11153. }
  11154. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11155. if (!lua_interface)
  11156. return 0;
  11157. Spawn* spawn = lua_interface->GetSpawn(state);
  11158. bool value = lua_interface->GetBooleanValue(state, 2);
  11159. lua_interface->ResetFunctionStack(state);
  11160. if(!spawn || !spawn->IsPlayer())
  11161. {
  11162. 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));
  11163. return 0;
  11164. }
  11165. ((Player*)spawn)->SetCharSheetChanged(value);
  11166. return 0;
  11167. }
  11168. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11169. if (!lua_interface)
  11170. return 0;
  11171. Spawn* spawn = lua_interface->GetSpawn(state);
  11172. std::string fromName = lua_interface->GetStringValue(state, 2);
  11173. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11174. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11175. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11176. int32 copper = lua_interface->GetInt32Value(state, 6);
  11177. int32 silver = lua_interface->GetInt32Value(state, 7);
  11178. int32 gold = lua_interface->GetInt32Value(state, 8);
  11179. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11180. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11181. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11182. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11183. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11184. lua_interface->ResetFunctionStack(state);
  11185. if(!spawn || !spawn->IsPlayer())
  11186. {
  11187. 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));
  11188. lua_interface->SetBooleanValue(state, false);
  11189. return 1;
  11190. }
  11191. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11192. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11193. lua_interface->SetBooleanValue(state, true);
  11194. return 1;
  11195. }
  11196. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11197. if (!lua_interface)
  11198. return 0;
  11199. int32 char_id = lua_interface->GetInt32Value(state);
  11200. std::string fromName = lua_interface->GetStringValue(state, 2);
  11201. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11202. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11203. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11204. int32 copper = lua_interface->GetInt32Value(state, 6);
  11205. int32 silver = lua_interface->GetInt32Value(state, 7);
  11206. int32 gold = lua_interface->GetInt32Value(state, 8);
  11207. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11208. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11209. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11210. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11211. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11212. lua_interface->ResetFunctionStack(state);
  11213. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11214. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11215. lua_interface->SetBooleanValue(state, true);
  11216. return 1;
  11217. }
  11218. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11219. Spawn* widget;
  11220. if (lua_interface) {
  11221. widget = lua_interface->GetSpawn(state);
  11222. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11223. lua_interface->ResetFunctionStack(state);
  11224. if (widget && widget->IsWidget())
  11225. {
  11226. ((Widget*)widget)->OpenDoor();
  11227. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11228. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11229. }
  11230. else
  11231. 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));
  11232. }
  11233. return 0;
  11234. }
  11235. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11236. Spawn* widget;
  11237. if (lua_interface) {
  11238. widget = lua_interface->GetSpawn(state);
  11239. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11240. lua_interface->ResetFunctionStack(state);
  11241. if (widget && widget->IsWidget())
  11242. {
  11243. ((Widget*)widget)->CloseDoor();
  11244. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11245. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11246. }
  11247. else
  11248. 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));
  11249. }
  11250. return 0;
  11251. }
  11252. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11253. if (!lua_interface)
  11254. return 0;
  11255. Spawn* widget = lua_interface->GetSpawn(state);
  11256. lua_interface->ResetFunctionStack(state);
  11257. if (widget && widget->IsWidget())
  11258. {
  11259. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11260. return 1;
  11261. }
  11262. return 0;
  11263. }
  11264. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11265. if (!lua_interface)
  11266. return 0;
  11267. sint32 min = lua_interface->GetSInt32Value(state);
  11268. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11269. lua_interface->ResetFunctionStack(state);
  11270. sint32 result = MakeRandomInt(min, max);
  11271. lua_interface->SetSInt32Value(state, result);
  11272. return 1;
  11273. }
  11274. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11275. if (!lua_interface)
  11276. return 0;
  11277. float min = lua_interface->GetFloatValue(state);
  11278. float max = lua_interface->GetFloatValue(state, 2);
  11279. lua_interface->ResetFunctionStack(state);
  11280. float result = MakeRandomFloat(min, max);
  11281. lua_interface->SetFloatValue(state, result);
  11282. return 1;
  11283. }
  11284. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11285. if (!lua_interface)
  11286. return 0;
  11287. Spawn* spawn = lua_interface->GetSpawn(state);
  11288. int32 value = lua_interface->GetInt32Value(state, 2);
  11289. lua_interface->ResetFunctionStack(state);
  11290. if(!spawn)
  11291. {
  11292. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11293. lua_interface->SetBooleanValue(state, false);
  11294. return 1;
  11295. }
  11296. spawn->AddIconValue(value);
  11297. lua_interface->SetBooleanValue(state, true);
  11298. return 1;
  11299. }
  11300. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11301. if (!lua_interface)
  11302. return 0;
  11303. Spawn* spawn = lua_interface->GetSpawn(state);
  11304. int32 value = lua_interface->GetInt32Value(state, 2);
  11305. lua_interface->ResetFunctionStack(state);
  11306. if(!spawn)
  11307. {
  11308. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11309. lua_interface->SetBooleanValue(state, false);
  11310. return 1;
  11311. }
  11312. spawn->RemoveIconValue(value);
  11313. lua_interface->SetBooleanValue(state, true);
  11314. return 1;
  11315. }
  11316. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11317. Spawn* npc = lua_interface->GetSpawn(state);
  11318. lua_interface->ResetFunctionStack(state);
  11319. if (npc && npc->IsNPC()) {
  11320. NPC* shard = (NPC*)npc;
  11321. int32 shardid = shard->GetShardID();
  11322. lua_interface->SetInt32Value(state, shardid);
  11323. return 1;
  11324. }
  11325. lua_interface->SetInt32Value(state, 0);
  11326. return 1;
  11327. }
  11328. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11329. Spawn* npc = lua_interface->GetSpawn(state);
  11330. lua_interface->ResetFunctionStack(state);
  11331. if (npc && npc->IsNPC()) {
  11332. NPC* shard = (NPC*)npc;
  11333. int32 charid = shard->GetShardCharID();
  11334. lua_interface->SetInt32Value(state, charid);
  11335. return 1;
  11336. }
  11337. lua_interface->SetInt32Value(state, 0);
  11338. return 1;
  11339. }
  11340. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11341. Spawn* npc = lua_interface->GetSpawn(state);
  11342. lua_interface->ResetFunctionStack(state);
  11343. if (npc && npc->IsNPC()) {
  11344. NPC* shard = (NPC*)npc;
  11345. int64 timestamp = shard->GetShardCreatedTimestamp();
  11346. lua_interface->SetSInt64Value(state, timestamp);
  11347. return 1;
  11348. }
  11349. lua_interface->SetSInt64Value(state, 0);
  11350. return 1;
  11351. }
  11352. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11353. if (!lua_interface)
  11354. return 0;
  11355. int32 shardid = lua_interface->GetInt32Value(state);
  11356. lua_interface->ResetFunctionStack(state);
  11357. if(shardid < 1)
  11358. lua_interface->SetBooleanValue(state, false);
  11359. else
  11360. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11361. return 1;
  11362. }
  11363. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11364. if (!lua_interface)
  11365. return 0;
  11366. Spawn* spawn = lua_interface->GetSpawn(state);
  11367. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11368. if (spawn) {
  11369. spawn->PauseMovement(delay_in_ms);
  11370. }
  11371. lua_interface->ResetFunctionStack(state);
  11372. return 0;
  11373. }
  11374. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11375. if (!lua_interface)
  11376. return 0;
  11377. Spawn* spawn = lua_interface->GetSpawn(state);
  11378. if (spawn) {
  11379. spawn->StopMovement();
  11380. }
  11381. lua_interface->ResetFunctionStack(state);
  11382. return 0;
  11383. }
  11384. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11385. Player* player = (Player*)lua_interface->GetSpawn(state);
  11386. int8 level = lua_interface->GetInt8Value(state, 2);
  11387. lua_interface->ResetFunctionStack(state);
  11388. if (player && player->IsPlayer() && level > 0) {
  11389. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11390. return 1;
  11391. }
  11392. return 0;
  11393. }
  11394. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11395. Player* player = (Player*)lua_interface->GetSpawn(state);
  11396. int8 level = lua_interface->GetInt8Value(state, 2);
  11397. lua_interface->ResetFunctionStack(state);
  11398. if (player && player->IsPlayer() && level > 0) {
  11399. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11400. return 1;
  11401. }
  11402. return 0;
  11403. }
  11404. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11405. ZoneServer* zone = lua_interface->GetZone(state);
  11406. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11407. lua_interface->ResetFunctionStack(state);
  11408. if (zone) {
  11409. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11410. if (spawn) {
  11411. lua_interface->SetSpawnValue(state, spawn);
  11412. return 1;
  11413. }
  11414. }
  11415. return 0;
  11416. }
  11417. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11418. if (!lua_interface)
  11419. return 0;
  11420. Spawn* spawn = lua_interface->GetSpawn(state);
  11421. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11422. lua_interface->ResetFunctionStack(state);
  11423. bool res = false;
  11424. if(spawn && spawn->IsTransportSpawn())
  11425. {
  11426. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11427. spawn->SetRailID(rail_id);
  11428. res = true;
  11429. }
  11430. else if (!spawn) {
  11431. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11432. }
  11433. else if(!spawn->IsTransportSpawn()) {
  11434. 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());
  11435. }
  11436. lua_interface->SetBooleanValue(state, res);
  11437. return 1;
  11438. }
  11439. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11440. if (!lua_interface)
  11441. return 0;
  11442. ZoneServer* zone = lua_interface->GetZone(state);
  11443. lua_interface->ResetFunctionStack(state);
  11444. if (zone) {
  11445. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11446. return 1;
  11447. }
  11448. return 0;
  11449. }
  11450. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11451. if (!lua_interface)
  11452. return 0;
  11453. Spawn* spawn = lua_interface->GetSpawn(state);
  11454. lua_interface->ResetFunctionStack(state);
  11455. if (spawn) {
  11456. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11457. return 1;
  11458. }
  11459. return 0;
  11460. }
  11461. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11462. if (!lua_interface)
  11463. return 0;
  11464. Spawn* player = lua_interface->GetSpawn(state);
  11465. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11466. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11467. lua_interface->ResetFunctionStack(state);
  11468. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11469. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11470. }
  11471. else if(!zoneID) {
  11472. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11473. }
  11474. else
  11475. {
  11476. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11477. return 1;
  11478. }
  11479. return 0;
  11480. }
  11481. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11482. if (!lua_interface)
  11483. return 0;
  11484. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11485. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11486. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11487. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11488. lua_interface->ResetFunctionStack(state);
  11489. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11490. world.GetWorldTimeStruct()->year = newYear;
  11491. world.GetWorldTimeStruct()->month = newMonth;
  11492. world.GetWorldTimeStruct()->hour = newHour;
  11493. world.GetWorldTimeStruct()->minute = newMinute;
  11494. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11495. return 0;
  11496. }
  11497. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11498. if (!lua_interface)
  11499. return 0;
  11500. lua_interface->ResetFunctionStack(state);
  11501. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11502. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11503. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11504. return 1;
  11505. }
  11506. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11507. if (!lua_interface)
  11508. return 0;
  11509. lua_interface->ResetFunctionStack(state);
  11510. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11511. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11512. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11513. return 1;
  11514. }
  11515. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11516. if (!lua_interface)
  11517. return 0;
  11518. lua_interface->ResetFunctionStack(state);
  11519. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11520. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11521. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11522. return 1;
  11523. }
  11524. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11525. if (!lua_interface)
  11526. return 0;
  11527. lua_interface->ResetFunctionStack(state);
  11528. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11529. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11530. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11531. return 1;
  11532. }
  11533. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11534. if (!lua_interface)
  11535. return 0;
  11536. lua_interface->ResetFunctionStack(state);
  11537. world.SendTimeUpdate();
  11538. return 0;
  11539. }
  11540. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11541. bool update_result = false;
  11542. Faction* faction = 0;
  11543. Spawn* spawn = lua_interface->GetSpawn(state);
  11544. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11545. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11546. lua_interface->ResetFunctionStack(state);
  11547. if(!spawn || !spawn->IsPlayer()) {
  11548. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11549. return 0;
  11550. }
  11551. Player* player = (Player*)spawn;
  11552. Client* client = player->GetClient();
  11553. if (faction_id > 0) {
  11554. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11555. if(hasfaction == 0) {
  11556. //they do not have the faction. Lets get the default value and feed it in.
  11557. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11558. //add the default faction for the player.
  11559. player->SetFactionValue(faction_id, defaultfaction);
  11560. }
  11561. if(increase >= 0) {
  11562. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11563. faction = master_faction_list.GetFaction(faction_id);
  11564. if(faction && update_result)
  11565. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11566. else if(faction)
  11567. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11568. lua_interface->SetBooleanValue(state, true);
  11569. return 1;
  11570. }
  11571. if(increase < 0){
  11572. //change the negative to a positive, since thats how decreasefaction() likes it.
  11573. increase *= -1;
  11574. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11575. faction = master_faction_list.GetFaction(faction_id);
  11576. if(faction && update_result)
  11577. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11578. else if(faction)
  11579. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11580. lua_interface->SetBooleanValue(state, true);
  11581. return 1;
  11582. }
  11583. }
  11584. lua_interface->SetBooleanValue(state, false);
  11585. return 1;
  11586. }
  11587. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11588. bool hascoin = 0;
  11589. Player* player = (Player*)lua_interface->GetSpawn(state);
  11590. int32 coins = lua_interface->GetInt32Value(state, 2);
  11591. lua_interface->ResetFunctionStack(state);
  11592. if (player && player->IsPlayer()) {
  11593. hascoin = player->HasCoins(coins);
  11594. if(hascoin == 0) {
  11595. lua_interface->SetBooleanValue(state, false);
  11596. return 1;
  11597. }
  11598. if(hascoin == 1) {
  11599. lua_interface->SetBooleanValue(state, true);
  11600. return 1;
  11601. }
  11602. }
  11603. return 0;
  11604. }
  11605. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11606. int32 loot_tier = 0;
  11607. Spawn* spawn = lua_interface->GetSpawn(state);
  11608. lua_interface->ResetFunctionStack(state);
  11609. if (spawn) {
  11610. loot_tier = spawn->GetLootTier();
  11611. lua_interface->SetInt32Value(state, loot_tier);
  11612. return 1;
  11613. }
  11614. return 0;
  11615. }
  11616. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11617. if (!lua_interface)
  11618. return 0;
  11619. Spawn* spawn = lua_interface->GetSpawn(state);
  11620. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11621. lua_interface->ResetFunctionStack(state);
  11622. if (spawn) {
  11623. spawn->SetLootTier(loot_tier);
  11624. lua_interface->SetBooleanValue(state, true);
  11625. return 1;
  11626. }
  11627. lua_interface->SetBooleanValue(state, false);
  11628. return 1;
  11629. }
  11630. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11631. int32 loot_drop_type = 0;
  11632. Spawn* spawn = lua_interface->GetSpawn(state);
  11633. lua_interface->ResetFunctionStack(state);
  11634. if (spawn) {
  11635. loot_drop_type = spawn->GetLootDropType();
  11636. lua_interface->SetInt32Value(state, loot_drop_type);
  11637. return 1;
  11638. }
  11639. return 0;
  11640. }
  11641. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11642. if (!lua_interface)
  11643. return 0;
  11644. Spawn* spawn = lua_interface->GetSpawn(state);
  11645. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11646. lua_interface->ResetFunctionStack(state);
  11647. if (spawn) {
  11648. spawn->SetLootDropType(loot_drop_type);
  11649. lua_interface->SetBooleanValue(state, true);
  11650. return 1;
  11651. }
  11652. lua_interface->SetBooleanValue(state, false);
  11653. return 1;
  11654. }
  11655. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11656. if (!lua_interface)
  11657. return 0;
  11658. Spawn* spawn = lua_interface->GetSpawn(state);
  11659. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11660. if(damage_amount > 100) {
  11661. damage_amount = 100;
  11662. }
  11663. if (!spawn) {
  11664. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11665. lua_interface->ResetFunctionStack(state);
  11666. return 0;
  11667. }
  11668. lua_interface->ResetFunctionStack(state);
  11669. if (spawn->IsPlayer()) {
  11670. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11671. lua_interface->SetBooleanValue(state, true);
  11672. else
  11673. lua_interface->SetBooleanValue(state, false);
  11674. }
  11675. else {
  11676. lua_interface->SetBooleanValue(state, false);
  11677. }
  11678. return 1;
  11679. }
  11680. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11681. ZoneServer* zone = lua_interface->GetZone(state);
  11682. int32 version = lua_interface->GetInt32Value(state, 2);
  11683. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11684. if(region_map == nullptr) {
  11685. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11686. lua_interface->ResetFunctionStack(state);
  11687. return 0;
  11688. }
  11689. string region_name = lua_interface->GetStringValue(state, 3);
  11690. string env_name = lua_interface->GetStringValue(state, 4);
  11691. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11692. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11693. float dist = lua_interface->GetFloatValue(state, 7);
  11694. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11695. lua_interface->ResetFunctionStack(state);
  11696. lua_interface->SetBooleanValue(state, true);
  11697. return 1;
  11698. }
  11699. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11700. ZoneServer* zone = lua_interface->GetZone(state);
  11701. int32 version = lua_interface->GetInt32Value(state, 2);
  11702. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11703. if(region_map == nullptr) {
  11704. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11705. lua_interface->ResetFunctionStack(state);
  11706. return 0;
  11707. }
  11708. string region_name = lua_interface->GetStringValue(state, 3);
  11709. region_map->RemoveRegionNode(region_name);
  11710. lua_interface->ResetFunctionStack(state);
  11711. lua_interface->SetBooleanValue(state, true);
  11712. return 1;
  11713. }
  11714. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11715. Client* client = nullptr;
  11716. Spawn* player = lua_interface->GetSpawn(state);
  11717. if (!player) {
  11718. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11719. lua_interface->SetBooleanValue(state, false);
  11720. lua_interface->ResetFunctionStack(state);
  11721. return 1;
  11722. }
  11723. if (!player->IsPlayer()) {
  11724. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11725. lua_interface->SetBooleanValue(state, false);
  11726. lua_interface->ResetFunctionStack(state);
  11727. return 1;
  11728. }
  11729. client = player->GetClient();
  11730. if (!client) {
  11731. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11732. lua_interface->SetBooleanValue(state, false);
  11733. lua_interface->ResetFunctionStack(state);
  11734. return 1;
  11735. }
  11736. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11737. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11738. lua_interface->ResetFunctionStack(state);
  11739. lua_interface->SetBooleanValue(state, success_sight);
  11740. return 1;
  11741. }
  11742. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11743. if (!lua_interface)
  11744. return 0;
  11745. bool result = false;
  11746. Spawn* spawn = lua_interface->GetSpawn(state);
  11747. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11748. lua_interface->ResetFunctionStack(state);
  11749. if (!spawn)
  11750. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11751. else if (!spawn->IsNPC())
  11752. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11753. else
  11754. {
  11755. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11756. result = true;
  11757. }
  11758. lua_interface->SetBooleanValue(state, result);
  11759. return 1;
  11760. }
  11761. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11762. if (!lua_interface)
  11763. return 0;
  11764. bool result = false;
  11765. Spawn* spawn = lua_interface->GetSpawn(state);
  11766. lua_interface->ResetFunctionStack(state);
  11767. if (!spawn)
  11768. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11769. else if (!spawn->IsNPC())
  11770. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11771. else
  11772. {
  11773. if(((NPC*)spawn)->cast_on_aggro_completed)
  11774. result = true;
  11775. }
  11776. lua_interface->SetBooleanValue(state, result);
  11777. return 1;
  11778. }
  11779. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11780. Client* client = nullptr;
  11781. Spawn* player = lua_interface->GetSpawn(state);
  11782. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11783. lua_interface->ResetFunctionStack(state);
  11784. if (!player) {
  11785. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11786. lua_interface->SetBooleanValue(state, false);
  11787. return 1;
  11788. }
  11789. if (!player->IsPlayer()) {
  11790. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11791. lua_interface->SetBooleanValue(state, false);
  11792. return 1;
  11793. }
  11794. client = player->GetClient();
  11795. if (!client) {
  11796. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11797. lua_interface->SetBooleanValue(state, false);
  11798. return 1;
  11799. }
  11800. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11801. lua_interface->SetBooleanValue(state, result);
  11802. return 1;
  11803. }
  11804. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11805. Client* client = nullptr;
  11806. Spawn* player = lua_interface->GetSpawn(state);
  11807. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11808. lua_interface->ResetFunctionStack(state);
  11809. if (!player) {
  11810. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11811. lua_interface->SetBooleanValue(state, false);
  11812. return 1;
  11813. }
  11814. if (!player->IsPlayer()) {
  11815. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11816. lua_interface->SetBooleanValue(state, false);
  11817. return 1;
  11818. }
  11819. client = player->GetClient();
  11820. if (!client) {
  11821. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11822. lua_interface->SetBooleanValue(state, false);
  11823. return 1;
  11824. }
  11825. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11826. lua_interface->SetBooleanValue(state, result);
  11827. return 1;
  11828. }