LuaFunctions.cpp 380 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476
  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. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //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
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. spawn->GetZone()->AddChangedSpawn(spawn);
  327. }
  328. return 0;
  329. }
  330. //this function is used to force an update packet to be sent.
  331. //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
  332. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  333. if (!lua_interface)
  334. return 0;
  335. Spawn* spawn = lua_interface->GetSpawn(state);
  336. if (spawn) {
  337. spawn->info_changed = true;
  338. spawn->GetZone()->AddChangedSpawn(spawn);
  339. }
  340. return 0;
  341. }
  342. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. int32 new_state = lua_interface->GetInt32Value(state, 2);
  347. Spawn* player = lua_interface->GetSpawn(state, 3);
  348. lua_interface->ResetFunctionStack(state);
  349. if (spawn) {
  350. if(player)
  351. {
  352. if(player->IsPlayer())
  353. {
  354. Client* client = ((Player*)player)->GetClient();
  355. if(client)
  356. {
  357. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  358. lua_interface->SetBooleanValue(state, true);
  359. return 1;
  360. }
  361. else
  362. 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());
  363. }
  364. else
  365. 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());
  366. }
  367. else
  368. {
  369. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  370. lua_interface->SetBooleanValue(state, true);
  371. return 1;
  372. }
  373. }
  374. lua_interface->SetBooleanValue(state, false);
  375. return 1;
  376. }
  377. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. Spawn* spawn = lua_interface->GetSpawn(state);
  381. string variable = lua_interface->GetStringValue(state, 2);
  382. string value = lua_interface->GetStringValue(state, 3);
  383. 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.
  384. bool temporary_flag = true;
  385. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  386. int8 index = 0;
  387. if(num_args >= 5)
  388. {
  389. 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
  390. index = lua_interface->GetInt8Value(state, 6);
  391. }
  392. int32 type = commands.GetSpawnSetType(variable);
  393. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  394. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  395. return 0;
  396. }
  397. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  398. if (!lua_interface)
  399. return 0;
  400. Spawn* spawn = lua_interface->GetSpawn(state);
  401. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  402. if (spawn && spawn_id > 0) {
  403. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  404. if (closest_spawn) {
  405. lua_interface->SetSpawnValue(state, closest_spawn);
  406. return 1;
  407. }
  408. }
  409. return 0;
  410. }
  411. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  412. if (!lua_interface)
  413. return 0;
  414. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  415. int32 position = lua_interface->GetInt32Value(state, 2);
  416. if (spawnList) {
  417. if (spawnList->size() > position) {
  418. lua_interface->SetSpawnValue(state, spawnList->at(position));
  419. return 1;
  420. }
  421. else {
  422. return 0;
  423. }
  424. return spawnList->size();
  425. }
  426. return 0;
  427. }
  428. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  429. if (!lua_interface)
  430. return 0;
  431. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  432. if (spawnList) {
  433. return spawnList->size();
  434. }
  435. return 0;
  436. }
  437. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  438. if (!lua_interface)
  439. return 0;
  440. vector<Spawn*>* spawnList = new vector<Spawn*>();
  441. lua_interface->SetSpawnListValue(state, spawnList);
  442. return 1;
  443. }
  444. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  445. if (!lua_interface)
  446. return 0;
  447. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  448. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  449. if (spawnList) {
  450. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  451. if (it == spawnList->end())
  452. spawnList->push_back(spawn);
  453. }
  454. return 0;
  455. }
  456. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  457. if (!lua_interface)
  458. return 0;
  459. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  460. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  461. if (spawnList) {
  462. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  463. if(it != spawnList->end())
  464. spawnList->erase(it);
  465. }
  466. return 0;
  467. }
  468. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  469. if (!lua_interface)
  470. return 0;
  471. Spawn* spawn = lua_interface->GetSpawn(state);
  472. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  473. if (spawn) {
  474. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  475. if (spawns.size() > 0) {
  476. vector<Spawn*>* spawnList = new vector<Spawn*>();
  477. vector<Spawn*>::iterator itr;
  478. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  479. spawnList->push_back(*itr);
  480. }
  481. lua_interface->SetSpawnListValue(state, spawnList);
  482. return 1;
  483. }
  484. }
  485. return 0;
  486. }
  487. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  488. if (!lua_interface)
  489. return 0;
  490. Spawn* spawn = lua_interface->GetSpawn(state);
  491. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  492. if (spawn) {
  493. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  494. if (spawns.size() > 0) {
  495. vector<Spawn*>* spawnList = new vector<Spawn*>();
  496. vector<Spawn*>::iterator itr;
  497. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  498. spawnList->push_back(*itr);
  499. }
  500. lua_interface->SetSpawnListValue(state, spawnList);
  501. return 1;
  502. }
  503. }
  504. return 0;
  505. }
  506. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  507. if (!lua_interface)
  508. return 0;
  509. Spawn* spawn = lua_interface->GetSpawn(state);
  510. if (spawn) {
  511. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  512. if (spawns.size() > 0) {
  513. lua_createtable(state, spawns.size(), 0);
  514. int newTable = lua_gettop(state);
  515. for (int32 i = 0; i < spawns.size(); i++) {
  516. lua_interface->SetSpawnValue(state, spawns.at(i));
  517. lua_rawseti(state, newTable, i + 1);
  518. }
  519. return 1;
  520. }
  521. }
  522. return 0;
  523. }
  524. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  525. if (!lua_interface)
  526. return 0;
  527. string variable_name = lua_interface->GetStringValue(state);
  528. Variable* var = variables.FindVariable(variable_name);
  529. if (var) {
  530. lua_interface->SetStringValue(state, var->GetValue());
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  536. if (!lua_interface)
  537. return 0;
  538. int32 total_coins = lua_interface->GetInt32Value(state);
  539. if (total_coins == 0) {
  540. lua_interface->SetStringValue(state, "0 copper");
  541. return 1;
  542. }
  543. char tmp[64] = { 0 };
  544. string message = "";
  545. int32 val = 0;
  546. if (total_coins >= 1000000) {
  547. val = total_coins / 1000000;
  548. total_coins -= 1000000 * val;
  549. sprintf(tmp, " %u Platinum", val);
  550. message.append(tmp);
  551. memset(tmp, 0, 64);
  552. }
  553. if (total_coins >= 10000) {
  554. val = total_coins / 10000;
  555. total_coins -= 10000 * val;
  556. sprintf(tmp, " %u Gold", val);
  557. message.append(tmp);
  558. memset(tmp, 0, 64);
  559. }
  560. if (total_coins >= 100) {
  561. val = total_coins / 100;
  562. total_coins -= 100 * val;
  563. sprintf(tmp, " %u Silver", val);
  564. message.append(tmp);
  565. memset(tmp, 0, 64);
  566. }
  567. if (total_coins > 0) {
  568. sprintf(tmp, " %u Copper", (int32)total_coins);
  569. message.append(tmp);
  570. }
  571. lua_interface->SetStringValue(state, message.c_str());
  572. return 1;
  573. }
  574. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  575. ZoneServer* zone = lua_interface->GetZone(state);
  576. int32 group_id = lua_interface->GetInt32Value(state, 2);
  577. if (zone) {
  578. Spawn* spawn = zone->GetSpawnGroup(group_id);
  579. if (spawn) {
  580. lua_interface->SetSpawnValue(state, spawn);
  581. return 1;
  582. }
  583. }
  584. return 0;
  585. }
  586. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  587. ZoneServer* zone = lua_interface->GetZone(state);
  588. int32 location_id = lua_interface->GetInt32Value(state, 2);
  589. if (zone) {
  590. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  591. if (spawn) {
  592. lua_interface->SetSpawnValue(state, spawn);
  593. return 1;
  594. }
  595. }
  596. return 0;
  597. }
  598. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  599. Spawn* spawn = lua_interface->GetSpawn(state);
  600. if (spawn) {
  601. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  602. return 1;
  603. }
  604. return 0;
  605. }
  606. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  607. Spawn* spawn = lua_interface->GetSpawn(state);
  608. if (spawn) {
  609. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  610. return 1;
  611. }
  612. return 0;
  613. }
  614. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  615. if (!lua_interface)
  616. return 0;
  617. Spawn* spawn = lua_interface->GetSpawn(state);
  618. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  619. lua_interface->ResetFunctionStack(state);
  620. if (spawn) {
  621. spawn->SetSpawnGroupID(new_group_id);
  622. lua_interface->SetBooleanValue(state, true);
  623. return 1;
  624. }
  625. lua_interface->SetBooleanValue(state, false);
  626. return 1;
  627. }
  628. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  629. if (!lua_interface)
  630. return 0;
  631. Spawn* spawn = lua_interface->GetSpawn(state);
  632. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  636. lua_interface->SetBooleanValue(state, true);
  637. return 1;
  638. }
  639. lua_interface->SetBooleanValue(state, false);
  640. return 1;
  641. }
  642. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. if (spawn) {
  645. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  646. return 1;
  647. }
  648. return 0;
  649. }
  650. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  651. Spawn* spawn = lua_interface->GetSpawn(state);
  652. if (spawn) {
  653. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  654. return 1;
  655. }
  656. return 0;
  657. }
  658. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  659. Player* player = (Player*)lua_interface->GetSpawn(state);
  660. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  661. if (player && player->IsPlayer() && faction_id > 0) {
  662. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  663. return 1;
  664. }
  665. return 0;
  666. }
  667. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  668. if (!lua_interface)
  669. return 0;
  670. Spawn* spawn = lua_interface->GetSpawn(state);
  671. int32 value = lua_interface->GetInt32Value(state, 2);
  672. if (spawn) {
  673. spawn->SetFactionID(value);
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. if (spawn) {
  680. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  681. return 1;
  682. }
  683. return 0;
  684. }
  685. int EQ2Emu_lua_GetGender(lua_State* state) {
  686. Spawn* spawn = lua_interface->GetSpawn(state);
  687. if (spawn) {
  688. lua_interface->SetInt32Value(state, spawn->GetGender());
  689. return 1;
  690. }
  691. return 0;
  692. }
  693. int EQ2Emu_lua_GetTarget(lua_State* state) {
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  696. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  697. return 1;
  698. }
  699. return 0;
  700. }
  701. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  702. if (!lua_interface)
  703. return 0;
  704. Spawn* spawn = lua_interface->GetSpawn(state);
  705. string mp3_string = lua_interface->GetStringValue(state, 2);
  706. int32 key1 = lua_interface->GetInt32Value(state, 3);
  707. int32 key2 = lua_interface->GetInt32Value(state, 4);
  708. Spawn* player = lua_interface->GetSpawn(state, 5);
  709. if (spawn && mp3_string.length() > 0) {
  710. Client* client = 0;
  711. if (player && player->IsPlayer())
  712. client = spawn->GetZone()->GetClientBySpawn(player);
  713. if (client) {
  714. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  715. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  716. }
  717. else
  718. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  719. }
  720. return 0;
  721. }
  722. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  723. if (!lua_interface)
  724. return 0;
  725. Spawn* spawn = lua_interface->GetSpawn(state);
  726. if (spawn) {
  727. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  728. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  729. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  730. return 3;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. if (spawn) {
  739. int32 item_id = lua_interface->GetInt32Value(state, 2);
  740. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  741. return 1;
  742. }
  743. return 0;
  744. }
  745. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  746. if (!lua_interface)
  747. return 0;
  748. Spawn* spawn = lua_interface->GetSpawn(state);
  749. if (spawn && spawn->IsEntity()) {
  750. int32 item_id = lua_interface->GetInt32Value(state, 2);
  751. int16 charges = lua_interface->GetInt16Value(state, 3);
  752. if (charges == 0)
  753. charges = 1;
  754. ((Entity*)spawn)->AddLootItem(item_id, charges);
  755. }
  756. return 0;
  757. }
  758. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  759. if (!lua_interface)
  760. return 0;
  761. Spawn* spawn = lua_interface->GetSpawn(state);
  762. if (spawn && spawn->IsEntity()) {
  763. int32 item_id = lua_interface->GetInt32Value(state, 2);
  764. Item* item = spawn->LootItem(item_id);
  765. safe_delete(item);
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 val = lua_interface->GetInt32Value(state, 2);
  775. spawn->AddLootCoins(val);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* entity = lua_interface->GetSpawn(state);
  783. Spawn* player = lua_interface->GetSpawn(state, 2);
  784. if (entity && player && player->IsPlayer()) {
  785. int32 coins = lua_interface->GetInt32Value(state, 3);
  786. vector<Item*>* items = 0;
  787. int i = 0;
  788. int32 item_id = 0;
  789. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  790. if (items == 0)
  791. items = new vector<Item*>;
  792. if (master_item_list.GetItem(item_id))
  793. items->push_back(master_item_list.GetItem(item_id));
  794. i++;
  795. }
  796. Client* client = 0;
  797. client = player->GetZone()->GetClientBySpawn(player);
  798. if (client)
  799. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  800. if(coins > 0)
  801. entity->AddLootCoins(coins);
  802. safe_delete(items);
  803. }
  804. return 0;
  805. }
  806. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  807. if (!lua_interface)
  808. return 0;
  809. Spawn* entity = lua_interface->GetSpawn(state);
  810. Spawn* player = lua_interface->GetSpawn(state, 2);
  811. int32 item_id = lua_interface->GetInt32Value(state, 3);
  812. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  813. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  814. return 1;
  815. }
  816. return 0;
  817. }
  818. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  819. if (!lua_interface)
  820. return 0;
  821. Spawn* entity = lua_interface->GetSpawn(state);
  822. Spawn* player = lua_interface->GetSpawn(state, 2);
  823. if (entity && player && player->IsPlayer()) {
  824. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  825. return 1;
  826. }
  827. return 0;
  828. }
  829. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  830. if (!lua_interface)
  831. return 0;
  832. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  833. safe_delete(conversation);
  834. conversation = new vector<ConversationOption>();
  835. lua_interface->SetConversationValue(state, conversation);
  836. return 1;
  837. }
  838. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  839. if (!lua_interface)
  840. return 0;
  841. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  842. if (conversation) {
  843. ConversationOption conv_option;
  844. conv_option.option = lua_interface->GetStringValue(state, 2);
  845. conv_option.function = lua_interface->GetStringValue(state, 3);
  846. if (conv_option.option.length() > 0)
  847. conversation->push_back(conv_option);
  848. }
  849. return 0;
  850. }
  851. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  852. if (!lua_interface)
  853. return 0;
  854. Spawn* npc = lua_interface->GetSpawn(state);
  855. Spawn* player = lua_interface->GetSpawn(state, 2);
  856. if (npc && player && player->IsPlayer() && player->GetZone()) {
  857. Client* client = player->GetZone()->GetClientBySpawn(player);
  858. if (client) {
  859. int32 conversation_id = client->GetConversationID(npc, 0);
  860. client->CloseDialog(conversation_id);
  861. }
  862. }
  863. return 0;
  864. }
  865. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  866. if (!lua_interface)
  867. return 0;
  868. Item* item = lua_interface->GetItem(state);
  869. Spawn* player = lua_interface->GetSpawn(state, 2);
  870. if (item && player && player->IsPlayer() && player->GetZone()) {
  871. Client* client = player->GetZone()->GetClientBySpawn(player);
  872. if (client) {
  873. int32 conversation_id = client->GetConversationID(0, item);
  874. client->CloseDialog(conversation_id);
  875. }
  876. }
  877. return 0;
  878. }
  879. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  880. if (!lua_interface)
  881. return 0;
  882. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  883. Spawn* spawn = 0;
  884. Item* item = 0;
  885. int8 type = lua_interface->GetInt8Value(state, 2);
  886. if (type == 1 || type == 3)
  887. spawn = lua_interface->GetSpawn(state, 3);
  888. else if (type == 2 || type == 4)
  889. item = lua_interface->GetItem(state, 3);
  890. Spawn* player = lua_interface->GetSpawn(state, 4);
  891. string text = lua_interface->GetStringValue(state, 5);
  892. string mp3 = lua_interface->GetStringValue(state, 6);
  893. int32 key1 = lua_interface->GetInt32Value(state, 7);
  894. int32 key2 = lua_interface->GetInt32Value(state, 8);
  895. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  896. Client* client = player->GetZone()->GetClientBySpawn(player);
  897. if (client) {
  898. if (spawn) {
  899. // Need to do this so the function works the same as it did before
  900. if (type == 1)
  901. type++;
  902. if (mp3.length() > 0)
  903. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  904. else
  905. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  906. }
  907. else {
  908. if (mp3.length() > 0)
  909. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  910. else
  911. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  912. }
  913. }
  914. }
  915. safe_delete(conversation);
  916. lua_interface->SetConversationValue(state, NULL);
  917. return 0;
  918. }
  919. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  920. if(!lua_interface)
  921. return 0;
  922. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  923. Item* item = lua_interface->GetItem(state, 2);
  924. Spawn* player = lua_interface->GetSpawn(state, 3);
  925. string text = lua_interface->GetStringValue(state, 4);
  926. string mp3 = lua_interface->GetStringValue(state, 5);
  927. int32 key1 = lua_interface->GetInt32Value(state, 6);
  928. int32 key2 = lua_interface->GetInt32Value(state, 7);
  929. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  930. Client* client = player->GetZone()->GetClientBySpawn(player);
  931. if(client){
  932. if(mp3.length() > 0)
  933. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  934. else
  935. client->DisplayConversation(item, conversation, (char*)text.c_str());
  936. }
  937. safe_delete(conversation);
  938. }
  939. return 0;
  940. }*/
  941. int EQ2Emu_lua_StartConversation(lua_State* state) {
  942. if (!lua_interface)
  943. return 0;
  944. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  945. Spawn* source = lua_interface->GetSpawn(state, 2);
  946. Spawn* player = lua_interface->GetSpawn(state, 3);
  947. string text = lua_interface->GetStringValue(state, 4);
  948. string mp3 = lua_interface->GetStringValue(state, 5);
  949. int32 key1 = lua_interface->GetInt32Value(state, 6);
  950. int32 key2 = lua_interface->GetInt32Value(state, 7);
  951. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  952. Client* client = source->GetZone()->GetClientBySpawn(player);
  953. if (mp3.length() > 0)
  954. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  955. else
  956. client->DisplayConversation(source, 1, conversation, text.c_str());
  957. safe_delete(conversation);
  958. lua_interface->SetConversationValue(state, NULL);
  959. }
  960. else
  961. 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);
  962. return 0;
  963. }
  964. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  965. if (!lua_interface)
  966. return 0;
  967. Spawn* spawn = lua_interface->GetSpawn(state);
  968. float distance = lua_interface->GetFloatValue(state, 2);
  969. string in_range_function = lua_interface->GetStringValue(state, 3);
  970. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  971. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  972. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  973. return 0;
  974. }
  975. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  976. ZoneServer* zone = lua_interface->GetZone(state);
  977. float x = lua_interface->GetFloatValue(state, 2);
  978. float y = lua_interface->GetFloatValue(state, 3);
  979. float z = lua_interface->GetFloatValue(state, 4);
  980. float max_variation = lua_interface->GetFloatValue(state, 5);
  981. string in_range_function = lua_interface->GetStringValue(state, 6);
  982. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  983. if (zone && in_range_function.length() > 0)
  984. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  985. return 0;
  986. }
  987. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  988. if (!lua_interface)
  989. return 0;
  990. Spawn* spawn = lua_interface->GetSpawn(state);
  991. if (spawn && spawn->IsEntity()) {
  992. int32 val = lua_interface->GetInt32Value(state, 2);
  993. ((Entity*)spawn)->SetLootCoins(val);
  994. }
  995. return 0;
  996. }
  997. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. Spawn* spawn = lua_interface->GetSpawn(state);
  1001. if (spawn && spawn->IsEntity()) {
  1002. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1003. return 1;
  1004. }
  1005. return 0;
  1006. }
  1007. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1008. if (!lua_interface)
  1009. return 0;
  1010. Spawn* spawn = lua_interface->GetSpawn(state);
  1011. float x = lua_interface->GetFloatValue(state, 2);
  1012. float y = lua_interface->GetFloatValue(state, 3);
  1013. float z = lua_interface->GetFloatValue(state, 4);
  1014. float speed = lua_interface->GetFloatValue(state, 5);
  1015. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1016. string function = lua_interface->GetStringValue(state, 7);
  1017. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1018. float heading = lua_interface->GetFloatValue(state, 8);
  1019. if (spawn) {
  1020. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1021. spawn->GetZone()->AddMovementNPC(spawn);
  1022. }
  1023. lua_interface->ResetFunctionStack(state);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. if (spawn) {
  1031. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1032. return 1;
  1033. }
  1034. return 0;
  1035. }
  1036. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1037. if (!lua_interface)
  1038. return 0;
  1039. Spawn* spawn = lua_interface->GetSpawn(state);
  1040. if (spawn && spawn->IsPlayer()) {
  1041. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1042. return 1;
  1043. }
  1044. lua_interface->SetInt32Value(state, 0);
  1045. return 1;
  1046. }
  1047. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. Spawn* spawn = lua_interface->GetSpawn(state);
  1051. Spawn* target = lua_interface->GetSpawn(state, 2);
  1052. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1053. bool reset_action_state = true;
  1054. if(num_args > 2)
  1055. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1056. if (spawn && target) {
  1057. if (spawn->IsEntity())
  1058. // ((Entity*)spawn)->FaceTarget(target);
  1059. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1060. }
  1061. lua_interface->ResetFunctionStack(state);
  1062. return 0;
  1063. }
  1064. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1065. if (!lua_interface)
  1066. return 0;
  1067. Spawn* spawn = lua_interface->GetSpawn(state);
  1068. float x = lua_interface->GetFloatValue(state, 2);
  1069. float y = lua_interface->GetFloatValue(state, 3);
  1070. float z = lua_interface->GetFloatValue(state, 4);
  1071. float speed = lua_interface->GetFloatValue(state, 5);
  1072. string lua_function = lua_interface->GetStringValue(state, 6);
  1073. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1074. if (spawn) {
  1075. if (speed == 0)
  1076. speed = spawn->GetSpeed();
  1077. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1078. }
  1079. lua_interface->ResetFunctionStack(state);
  1080. return 0;
  1081. }
  1082. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1083. if (!lua_interface)
  1084. return 0;
  1085. Spawn* spawn = lua_interface->GetSpawn(state);
  1086. if (spawn) {
  1087. spawn->ClearRunningLocations();
  1088. }
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_Say(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. string message = lua_interface->GetStringValue(state, 2);
  1096. Spawn* player = lua_interface->GetSpawn(state, 3);
  1097. int32 language = lua_interface->GetInt32Value(state, 4);
  1098. if (spawn && message.length() > 0) {
  1099. Client* client = 0;
  1100. if (player && player->IsPlayer())
  1101. client = spawn->GetZone()->GetClientBySpawn(player);
  1102. if (client)
  1103. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1104. else
  1105. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1106. }
  1107. lua_interface->ResetFunctionStack(state);
  1108. return 0;
  1109. }
  1110. int EQ2Emu_lua_Shout(lua_State* state) {
  1111. if (!lua_interface)
  1112. return 0;
  1113. Spawn* spawn = lua_interface->GetSpawn(state);
  1114. string message = lua_interface->GetStringValue(state, 2);
  1115. Spawn* player = lua_interface->GetSpawn(state, 3);
  1116. float dist = lua_interface->GetFloatValue(state, 4);
  1117. if (spawn && message.length() > 0) {
  1118. Client* client = 0;
  1119. if (player && player->IsPlayer())
  1120. client = spawn->GetZone()->GetClientBySpawn(player);
  1121. if (client)
  1122. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1123. else
  1124. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1125. }
  1126. lua_interface->ResetFunctionStack(state);
  1127. return 0;
  1128. }
  1129. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1130. if (!lua_interface)
  1131. return 0;
  1132. Spawn* spawn = lua_interface->GetSpawn(state);
  1133. string message = lua_interface->GetStringValue(state, 2);
  1134. Spawn* player = lua_interface->GetSpawn(state, 3);
  1135. if (spawn && message.length() > 0) {
  1136. Client* client = 0;
  1137. if (player && player->IsPlayer())
  1138. client = spawn->GetZone()->GetClientBySpawn(player);
  1139. if (client)
  1140. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1141. else
  1142. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1143. }
  1144. lua_interface->ResetFunctionStack(state);
  1145. return 0;
  1146. }
  1147. int EQ2Emu_lua_Emote(lua_State* state) {
  1148. if (!lua_interface)
  1149. return 0;
  1150. Spawn* spawn = lua_interface->GetSpawn(state);
  1151. string message = lua_interface->GetStringValue(state, 2);
  1152. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1153. Spawn* player = lua_interface->GetSpawn(state, 4);
  1154. char* to = 0;
  1155. if (spawn2)
  1156. to = spawn2->GetName();
  1157. if (spawn && message.length() > 0) {
  1158. Client* client = 0;
  1159. if (player && player->IsPlayer())
  1160. client = spawn->GetZone()->GetClientBySpawn(player);
  1161. if (client)
  1162. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1163. else
  1164. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1165. }
  1166. lua_interface->ResetFunctionStack(state);
  1167. return 0;
  1168. }
  1169. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1170. if (!lua_interface)
  1171. return 0;
  1172. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1173. if (!luaspell)
  1174. return 0;
  1175. Spawn* caster = luaspell->caster;
  1176. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1177. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1178. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1179. Spawn* target = lua_interface->GetSpawn(state, 4);
  1180. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1181. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1182. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1183. lua_interface->ResetFunctionStack(state);
  1184. boost::to_lower(heal_type);
  1185. if (caster && caster->IsEntity()) {
  1186. bool success = false;
  1187. luaspell->resisted = false;
  1188. if (target) {
  1189. float distance = caster->GetDistance(target, true);
  1190. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1191. success = true;
  1192. }
  1193. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1194. Spawn* target = 0;
  1195. ZoneServer* zone = luaspell->caster->GetZone();
  1196. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1197. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1198. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1199. float distance = caster->GetDistance(target, true);
  1200. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1201. }
  1202. }
  1203. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1204. success = true;
  1205. }
  1206. if (success) {
  1207. if (caster->GetZone())
  1208. caster->GetZone()->TriggerCharSheetTimer();
  1209. }
  1210. }
  1211. return 0;
  1212. }
  1213. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1214. if (!lua_interface)
  1215. return 0;
  1216. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1217. if (!luaspell)
  1218. return 0;
  1219. Spawn* caster = luaspell->caster;
  1220. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1221. float percentage = lua_interface->GetFloatValue(state, 2);
  1222. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1223. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1224. Spawn* target = lua_interface->GetSpawn(state, 5);
  1225. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1226. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1227. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1228. lua_interface->ResetFunctionStack(state);
  1229. boost::to_lower(heal_type);
  1230. int32 min_heal = 0, max_heal = 0;
  1231. if (caster && caster->IsEntity() && target) {
  1232. if(percentage <= 0.0f)
  1233. {
  1234. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1235. return 0;
  1236. }
  1237. if(heal_type == "power")
  1238. {
  1239. if(current_value)
  1240. {
  1241. if(caster_value)
  1242. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1243. else
  1244. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1245. }
  1246. else
  1247. {
  1248. if(caster_value)
  1249. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1250. else
  1251. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1252. }
  1253. }
  1254. else
  1255. {
  1256. if(current_value)
  1257. {
  1258. if(caster_value)
  1259. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1260. else
  1261. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1262. }
  1263. else
  1264. {
  1265. if(caster_value)
  1266. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1267. else
  1268. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1269. }
  1270. }
  1271. bool success = false;
  1272. luaspell->resisted = false;
  1273. if (target) {
  1274. float distance = caster->GetDistance(target, true);
  1275. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1276. success = true;
  1277. }
  1278. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1279. Spawn* target = 0;
  1280. ZoneServer* zone = luaspell->caster->GetZone();
  1281. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1282. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1283. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1284. float distance = caster->GetDistance(target, true);
  1285. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1286. }
  1287. }
  1288. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1289. success = true;
  1290. }
  1291. if (success) {
  1292. if (caster->GetZone())
  1293. caster->GetZone()->TriggerCharSheetTimer();
  1294. }
  1295. }
  1296. return 0;
  1297. }
  1298. int EQ2Emu_lua_AddItem(lua_State* state) {
  1299. if (!lua_interface)
  1300. return 0;
  1301. Spawn* spawn = lua_interface->GetSpawn(state);
  1302. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1303. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1304. // default of 1 quantity to add
  1305. if (quantity == 0)
  1306. quantity = 1;
  1307. if (spawn && spawn->IsPlayer()) {
  1308. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1309. if (client && item_id > 0) {
  1310. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1311. return 1;
  1312. }
  1313. }
  1314. lua_interface->SetBooleanValue(state, false);
  1315. return 1;
  1316. }
  1317. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1318. if (!lua_interface)
  1319. return 0;
  1320. Spawn* spawn = lua_interface->GetSpawn(state);
  1321. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1322. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1323. string location = lua_interface->GetStringValue(state, 4);
  1324. if (spawn && spawn->IsPlayer()) {
  1325. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1326. if (client && item_id > 0) {
  1327. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1328. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1329. else
  1330. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1331. if (send_messages) {
  1332. Item* item = master_item_list.GetItem(item_id);
  1333. if (item) {
  1334. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1335. string popup_text = "You receive " + item->name;
  1336. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1337. }
  1338. }
  1339. return 1;
  1340. }
  1341. }
  1342. lua_interface->SetBooleanValue(state, false);
  1343. return 1;
  1344. }
  1345. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1346. Spawn* spawn = lua_interface->GetSpawn(state);
  1347. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1348. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1349. // default of 1 to remove
  1350. if (quantity == 0)
  1351. quantity = 1;
  1352. Client* client;
  1353. Item* item;
  1354. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1355. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1356. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1357. if (client->RemoveItem(item, quantity)) {
  1358. lua_interface->SetBooleanValue(state, true);
  1359. return 1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. lua_interface->SetBooleanValue(state, false);
  1365. return 1;
  1366. }
  1367. int EQ2Emu_lua_HasItem(lua_State* state) {
  1368. Spawn* player = lua_interface->GetSpawn(state);
  1369. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1370. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1371. if (player && player->IsPlayer()) {
  1372. bool hasItem = false;
  1373. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1374. if (!hasItem)
  1375. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1376. lua_interface->SetBooleanValue(state, hasItem);
  1377. return 1;
  1378. }
  1379. lua_interface->SetBooleanValue(state, false);
  1380. return 1;
  1381. }
  1382. int EQ2Emu_lua_Spawn(lua_State* state) {
  1383. if (!lua_interface)
  1384. return 0;
  1385. ZoneServer* zone = lua_interface->GetZone(state);
  1386. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1387. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1388. float x = lua_interface->GetFloatValue(state, 4);
  1389. float y = lua_interface->GetFloatValue(state, 5);
  1390. float z = lua_interface->GetFloatValue(state, 6);
  1391. float heading = lua_interface->GetFloatValue(state, 7);
  1392. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1393. Spawn* spawn = zone->GetSpawn(spawn_id);
  1394. if (!spawn)
  1395. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1396. else {
  1397. spawn->SetX(x);
  1398. spawn->SetZ(z);
  1399. spawn->SetY(y,true,true);
  1400. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1401. spawn->SetHeading(heading);
  1402. if (restricted_npc)
  1403. spawn->AddAllowAccessSpawn(spawn);
  1404. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1405. bool scriptActive = false;
  1406. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1407. scriptActive = true;
  1408. spawn->SetSpawnScript(string(spawn_script));
  1409. }
  1410. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1411. zone->AddSpawn(spawn);
  1412. if (scriptActive) {
  1413. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1414. }
  1415. lua_interface->SetSpawnValue(state, spawn);
  1416. return 1;
  1417. }
  1418. }
  1419. else {
  1420. string output = "Invalid paramaters to LUA Spawn command: \n";
  1421. if (!zone)
  1422. output = output.append("\t").append("Missing zone reference. \n");
  1423. if (spawn_id == 0)
  1424. output = output.append("\t").append("Missing spawn_id.");
  1425. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1426. }
  1427. return 0;
  1428. }
  1429. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1430. if (!lua_interface)
  1431. return 0;
  1432. ZoneServer* zone = lua_interface->GetZone(state);
  1433. if (zone) {
  1434. lua_interface->SetStringValue(state, zone->GetZoneName());
  1435. return 1;
  1436. }
  1437. return 0;
  1438. }
  1439. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1440. if (!lua_interface)
  1441. return 0;
  1442. ZoneServer* zone = lua_interface->GetZone(state);
  1443. if (zone) {
  1444. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1445. return 1;
  1446. }
  1447. return 0;
  1448. }
  1449. int EQ2Emu_lua_GetZone(lua_State* state) {
  1450. if (!lua_interface)
  1451. return 0;
  1452. int32 zone_id = lua_interface->GetInt32Value(state);
  1453. ZoneServer* zone = 0;
  1454. if (zone_id > 0)
  1455. zone = zone_list.Get(zone_id);
  1456. else {
  1457. string zone_name = lua_interface->GetStringValue(state);
  1458. if (zone_name.length() > 0) {
  1459. zone = zone_list.Get(zone_name.c_str());
  1460. }
  1461. else {
  1462. Spawn* spawn = lua_interface->GetSpawn(state);
  1463. if (spawn)
  1464. zone = spawn->GetZone();
  1465. }
  1466. }
  1467. if (zone) {
  1468. lua_interface->SetZoneValue(state, zone);
  1469. return 1;
  1470. }
  1471. return 0;
  1472. }
  1473. int EQ2Emu_lua_AddHate(lua_State* state) {
  1474. Spawn* entity = lua_interface->GetSpawn(state);
  1475. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1476. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1477. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1478. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1479. if (entity && entity->IsEntity() && amount != 0) {
  1480. if (luaspell) {
  1481. ZoneServer* zone = luaspell->caster->GetZone();
  1482. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1483. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1484. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1485. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1486. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1487. if (send_packet)
  1488. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1489. }
  1490. }
  1491. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1492. }
  1493. else if (npc && npc->IsNPC() && npc->GetZone())
  1494. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1495. }
  1496. return 0;
  1497. }
  1498. int EQ2Emu_lua_Zone(lua_State* state) {
  1499. if (!lua_interface)
  1500. return 0;
  1501. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1502. ZoneServer* zone = lua_interface->GetZone(state);
  1503. Spawn* player = lua_interface->GetSpawn(state, 2);
  1504. Client* client = 0;
  1505. if (player && player->IsPlayer())
  1506. client = player->GetZone()->GetClientBySpawn(player);
  1507. float x = lua_interface->GetFloatValue(state, 3);
  1508. float y = lua_interface->GetFloatValue(state, 4);
  1509. float z = lua_interface->GetFloatValue(state, 5);
  1510. float heading = lua_interface->GetFloatValue(state, 6);
  1511. if (zone && client) {
  1512. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1513. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1514. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1515. {
  1516. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1517. return 0;
  1518. }
  1519. if (x != 0 || y != 0 || z != 0) {
  1520. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1521. player->SetX(x);
  1522. player->SetY(y);
  1523. player->SetZ(z);
  1524. player->SetHeading(heading);
  1525. client->Zone(zone->GetZoneName(), false);
  1526. }
  1527. else
  1528. client->Zone(zone->GetZoneName());
  1529. }
  1530. else
  1531. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. Spawn* spawn = lua_interface->GetSpawn(state);
  1538. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1539. if (spawn && spawn2)
  1540. spawn->AddAllowAccessSpawn(spawn2);
  1541. return 0;
  1542. }
  1543. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1544. if (!lua_interface)
  1545. return 0;
  1546. Spawn* target = lua_interface->GetSpawn(state);
  1547. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1548. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1549. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1550. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1551. if (!target) {
  1552. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1553. return 0;
  1554. }
  1555. if (!target->IsEntity()) {
  1556. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1557. return 0;
  1558. }
  1559. if (spell_id <= 0) {
  1560. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1561. return 0;
  1562. }
  1563. if (caster && !caster->IsEntity()) {
  1564. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1565. return 0;
  1566. }
  1567. if (spell_tier == 0)
  1568. spell_tier = 1;
  1569. if (!caster)
  1570. caster = target;
  1571. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1572. return 0;
  1573. }
  1574. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1575. if (!lua_interface)
  1576. return 0;
  1577. Spawn* target = lua_interface->GetSpawn(state);
  1578. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1579. if (!luaspell)
  1580. return 0;
  1581. Spawn* caster = luaspell->caster;
  1582. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1583. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1584. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1585. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1586. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1587. //lua_interface->ResetFunctionStack(state);
  1588. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1589. vector<int16> faction_req;
  1590. vector<int16> race_req;
  1591. int32 class_req = 0;
  1592. int32 i = 0;
  1593. int8 f = 0;
  1594. int8 r = 0;
  1595. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1596. if (class_id < 100) {
  1597. class_req += pow(2.0, double(class_id - 1));
  1598. }
  1599. else if (class_id > 100 && class_id < 1000) {
  1600. race_req.push_back(class_id);
  1601. r++;
  1602. }
  1603. else {
  1604. faction_req.push_back(class_id);
  1605. f++;
  1606. }
  1607. i++;
  1608. }
  1609. if (caster && caster->IsEntity()) {
  1610. bool race_match = false;
  1611. bool success = false;
  1612. luaspell->resisted = false;
  1613. if (luaspell->targets.size() > 0) {
  1614. ZoneServer* zone = luaspell->caster->GetZone();
  1615. Spawn* target = 0;
  1616. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1617. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1618. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1619. if (race_req.size() > 0) {
  1620. for (int8 i = 0; i < race_req.size(); i++) {
  1621. if (target->GetLuaRaceId() == race_req[i]) {
  1622. race_match = true;
  1623. }
  1624. }
  1625. }
  1626. else
  1627. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1628. if (race_match == true) {
  1629. float distance = caster->GetDistance(target, true);
  1630. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1631. }
  1632. }
  1633. }
  1634. success = true;
  1635. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1636. }
  1637. else if (target) {
  1638. //check class and race/faction here
  1639. if (race_req.size() > 0) {
  1640. for (int8 i = 0; i < race_req.size(); i++) {
  1641. if (target->GetLuaRaceId() == race_req[i]) {
  1642. race_match = true;
  1643. }
  1644. }
  1645. }
  1646. else
  1647. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1648. if (race_match == true) {
  1649. float distance = caster->GetDistance(target, true);
  1650. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1651. success = true;
  1652. }
  1653. }
  1654. if (success) {
  1655. Spell* spell = luaspell->spell;
  1656. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1657. ((Player*)caster)->InCombat(true);
  1658. if (caster->GetZone())
  1659. caster->GetZone()->TriggerCharSheetTimer();
  1660. }
  1661. }
  1662. }
  1663. return 0;
  1664. }
  1665. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1666. if (!lua_interface)
  1667. return 0;
  1668. Spawn* spawn = lua_interface->GetSpawn(state);
  1669. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1670. lua_interface->ResetFunctionStack(state);
  1671. if (spawn && value != 0) {
  1672. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1673. spawn->SetPower(spawn->GetTotalPower());
  1674. else
  1675. spawn->SetPower(spawn->GetPower() + value);
  1676. }
  1677. return 0;
  1678. }
  1679. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1680. if (!lua_interface)
  1681. return 0;
  1682. Spawn* spawn = lua_interface->GetSpawn(state);
  1683. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1684. lua_interface->ResetFunctionStack(state);
  1685. if (spawn && value != 0) {
  1686. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1687. spawn->SetHP(spawn->GetTotalHP());
  1688. else
  1689. spawn->SetHP(spawn->GetHP() + value);
  1690. }
  1691. return 0;
  1692. }
  1693. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1694. if (!lua_interface)
  1695. return 0;
  1696. Spawn* spawn = lua_interface->GetSpawn(state);
  1697. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1698. lua_interface->ResetFunctionStack(state);
  1699. if (spawn && value != 0) {
  1700. spawn->SetPower(spawn->GetPower() + value);
  1701. if (value > spawn->GetTotalHPBase())
  1702. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1703. }
  1704. return 0;
  1705. }
  1706. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1707. if (!lua_interface)
  1708. return 0;
  1709. Spawn* spawn = lua_interface->GetSpawn(state);
  1710. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1711. lua_interface->ResetFunctionStack(state);
  1712. if (spawn && value != 0) {
  1713. spawn->SetHP(spawn->GetHP() + value);
  1714. if (value > spawn->GetTotalHPBase())
  1715. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1716. }
  1717. return 0;
  1718. }
  1719. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1720. if (!lua_interface)
  1721. return 0;
  1722. Spawn* spawn = lua_interface->GetSpawn(state);
  1723. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1724. lua_interface->ResetFunctionStack(state);
  1725. if (spawn) {
  1726. spawn->SetHP(value);
  1727. if (value > spawn->GetTotalHPBase())
  1728. spawn->SetTotalHP(value);
  1729. }
  1730. return 0;
  1731. }
  1732. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1733. if (!lua_interface)
  1734. return 0;
  1735. Spawn* spawn = lua_interface->GetSpawn(state);
  1736. float value = lua_interface->GetFloatValue(state, 2);
  1737. lua_interface->ResetFunctionStack(state);
  1738. if (spawn && spawn->IsEntity() && value > 0)
  1739. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1740. if (spawn->IsPlayer())
  1741. ((Player*)spawn)->SetCharSheetChanged(true);
  1742. return 0;
  1743. }
  1744. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1745. if (!lua_interface)
  1746. return 0;
  1747. Spawn* spawn = lua_interface->GetSpawn(state);
  1748. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1749. lua_interface->ResetFunctionStack(state);
  1750. if (spawn && spawn->IsEntity() && value > 0)
  1751. ((Entity*)spawn)->SetTotalHPBase(value);
  1752. return 0;
  1753. }
  1754. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1755. if (!lua_interface)
  1756. return 0;
  1757. Spawn* spawn = lua_interface->GetSpawn(state);
  1758. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1759. lua_interface->ResetFunctionStack(state);
  1760. if (spawn && value > 0) {
  1761. spawn->SetPower(value);
  1762. if (value > spawn->GetTotalPowerBase())
  1763. spawn->SetTotalPower(value);
  1764. }
  1765. return 0;
  1766. }
  1767. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1768. if (!lua_interface)
  1769. return 0;
  1770. Spawn* spawn = lua_interface->GetSpawn(state);
  1771. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1772. lua_interface->ResetFunctionStack(state);
  1773. if (spawn && spawn->IsEntity() && value > 0)
  1774. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1775. return 0;
  1776. }
  1777. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1778. if (!lua_interface)
  1779. return 0;
  1780. Spawn* spawn = lua_interface->GetSpawn(state);
  1781. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1782. lua_interface->ResetFunctionStack(state);
  1783. if (spawn && spawn->IsEntity() && value > 0)
  1784. ((Entity*)spawn)->SetTotalPowerBase(value);
  1785. return 0;
  1786. }
  1787. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1788. if (!lua_interface)
  1789. return 0;
  1790. Spawn* spawn = lua_interface->GetSpawn(state);
  1791. float x = lua_interface->GetFloatValue(state, 2);
  1792. float y = lua_interface->GetFloatValue(state, 3);
  1793. float z = lua_interface->GetFloatValue(state, 4);
  1794. float heading = lua_interface->GetFloatValue(state, 5);
  1795. lua_interface->ResetFunctionStack(state);
  1796. if (spawn) {
  1797. spawn->SetX(x);
  1798. spawn->SetY(y);
  1799. spawn->SetZ(z);
  1800. if (heading != 0)
  1801. spawn->SetHeading(heading);
  1802. spawn->SetSpawnOrigX(spawn->GetX());
  1803. spawn->SetSpawnOrigY(spawn->GetY());
  1804. spawn->SetSpawnOrigZ(spawn->GetZ());
  1805. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1806. if (spawn->IsPlayer()) {
  1807. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1808. if (client) {
  1809. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1810. client->QueuePacket(packet);
  1811. }
  1812. }
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. float value = lua_interface->GetFloatValue(state, 2);
  1821. lua_interface->ResetFunctionStack(state);
  1822. if (spawn) {
  1823. spawn->SetHeading(value);
  1824. if (spawn->IsPlayer()) {
  1825. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1826. if (client) {
  1827. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1828. client->QueuePacket(packet);
  1829. }
  1830. }
  1831. }
  1832. return 0;
  1833. }
  1834. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1835. if (!lua_interface)
  1836. return 0;
  1837. Spawn* spawn = lua_interface->GetSpawn(state);
  1838. int16 value = lua_interface->GetInt16Value(state, 2);
  1839. lua_interface->ResetFunctionStack(state);
  1840. if (spawn)
  1841. spawn->SetModelType(value);
  1842. return 0;
  1843. }
  1844. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1845. if (!lua_interface)
  1846. return 0;
  1847. Spawn* spawn = lua_interface->GetSpawn(state);
  1848. int8 value = lua_interface->GetInt8Value(state, 2);
  1849. lua_interface->ResetFunctionStack(state);
  1850. if (spawn) {
  1851. if (spawn->IsPlayer())
  1852. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1853. else
  1854. spawn->SetAdventureClass(value);
  1855. }
  1856. return 0;
  1857. }
  1858. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1859. if (!lua_interface)
  1860. return 0;
  1861. Spawn* spawn = lua_interface->GetSpawn(state);
  1862. int8 value = lua_interface->GetInt8Value(state, 2);
  1863. lua_interface->ResetFunctionStack(state);
  1864. if (spawn) {
  1865. spawn->SetTradeskillClass(value);
  1866. if (spawn->IsEntity()) {
  1867. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1868. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1869. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1870. }
  1871. if (spawn->IsPlayer())
  1872. ((Player*)spawn)->SetCharSheetChanged(true);
  1873. }
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_SetMount(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. int16 value = lua_interface->GetInt16Value(state, 2);
  1881. if (spawn && spawn->IsEntity()) {
  1882. ((Entity*)spawn)->SetMount(value);
  1883. EQ2_Color color;
  1884. color.red = 255;
  1885. color.green = 255;
  1886. color.blue = 255;
  1887. ((Entity*)spawn)->SetMountColor(&color);
  1888. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1889. }
  1890. return 0;
  1891. }
  1892. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1893. if (!lua_interface)
  1894. return 0;
  1895. Spawn* spawn = lua_interface->GetSpawn(state);
  1896. EQ2_Color mount_color;
  1897. EQ2_Color saddle_color;
  1898. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1899. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1900. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1901. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1902. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1903. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1904. if (spawn && spawn->IsEntity()) {
  1905. ((Entity*)spawn)->SetMountColor(&mount_color);
  1906. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1907. }
  1908. return 0;
  1909. }
  1910. int EQ2Emu_lua_GetMount(lua_State* state) {
  1911. if (!lua_interface)
  1912. return 0;
  1913. Spawn* spawn = lua_interface->GetSpawn(state);
  1914. if (spawn && spawn->IsEntity()) {
  1915. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1916. return 1;
  1917. }
  1918. return 0;
  1919. }
  1920. int EQ2Emu_lua_GetRace(lua_State* state) {
  1921. if (!lua_interface)
  1922. return 0;
  1923. Spawn* spawn = lua_interface->GetSpawn(state);
  1924. if (spawn)
  1925. {
  1926. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1927. lua_interface->SetInt32Value(state, spawn->GetRace());
  1928. return 1;
  1929. }
  1930. return 0;
  1931. }
  1932. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1933. if (!lua_interface)
  1934. return 0;
  1935. Spawn* spawn = lua_interface->GetSpawn(state);
  1936. if (spawn) {
  1937. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1938. return 1;
  1939. }
  1940. return 0;
  1941. }
  1942. int EQ2Emu_lua_GetClass(lua_State* state) {
  1943. Spawn* spawn = lua_interface->GetSpawn(state);
  1944. if (spawn) {
  1945. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1946. return 1;
  1947. }
  1948. return 0;
  1949. }
  1950. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1951. Spawn* spawn = lua_interface->GetSpawn(state);
  1952. if (spawn) {
  1953. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1954. return 1;
  1955. }
  1956. return 0;
  1957. }
  1958. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1959. if (!lua_interface)
  1960. return 0;
  1961. Spawn* spawn = lua_interface->GetSpawn(state);
  1962. float value = lua_interface->GetFloatValue(state, 2);
  1963. lua_interface->ResetFunctionStack(state);
  1964. if (spawn) {
  1965. spawn->SetSpeed(value);
  1966. if(spawn->IsEntity())
  1967. ((Entity*)spawn)->SetSpeed(value);
  1968. if (spawn->IsPlayer()) {
  1969. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1970. if (client) {
  1971. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1972. if (packet) {
  1973. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1974. packet->setDataByName("speed", value);
  1975. packet->setDataByName("size", 0.51);
  1976. EQ2Packet* app = packet->serialize();
  1977. client->QueuePacket(app);
  1978. safe_delete(packet);
  1979. }
  1980. }
  1981. }
  1982. }
  1983. return 0;
  1984. }
  1985. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1986. if (!lua_interface)
  1987. return 0;
  1988. Spawn* spawn = lua_interface->GetSpawn(state);
  1989. const int16 type = lua_interface->GetInt16Value(state, 2);
  1990. const float value = lua_interface->GetFloatValue(state, 3);
  1991. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1992. int64 class_req = 0;
  1993. int32 class_id = 0;
  1994. vector<int16> faction_req;
  1995. vector<int16> race_req;
  1996. int32 i = 0;
  1997. int8 f = 0;
  1998. int8 r = 0;
  1999. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2000. if (class_id < 100) {
  2001. class_req += pow(2.0, double(class_id - 1));
  2002. }
  2003. else if (class_id > 100 && class_id < 1000) {
  2004. race_req.push_back(class_id);
  2005. r++;
  2006. }
  2007. else {
  2008. faction_req.push_back(class_id);
  2009. f++;
  2010. }
  2011. i++;
  2012. }
  2013. if (value != 0 && type >= 0) {
  2014. if (luaspell && luaspell->spell && luaspell->caster) {
  2015. ZoneServer* zone = luaspell->caster->GetZone();
  2016. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2017. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2018. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2019. if (target) {
  2020. if (target->IsPlayer()) {
  2021. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2022. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2023. if (((Player*)target)->GetGroupMemberInfo())
  2024. ((Player*)target)->UpdateGroupMemberInfo();
  2025. ((Player*)target)->SetCharSheetChanged(true);
  2026. }
  2027. else if (target->IsNPC())
  2028. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2029. else
  2030. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2031. }
  2032. }
  2033. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2034. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2035. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2036. }
  2037. else if (spawn && spawn->IsEntity()) {
  2038. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2039. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2040. if (spawn->IsPlayer())
  2041. ((Player*)spawn)->SetCharSheetChanged(true);
  2042. }
  2043. else
  2044. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2045. }
  2046. else
  2047. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2048. return 0;
  2049. }
  2050. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2051. if (!lua_interface)
  2052. return 0;
  2053. Spawn* spawn = lua_interface->GetSpawn(state);
  2054. int16 type = lua_interface->GetInt16Value(state, 2);
  2055. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2056. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2057. if (!spawn) {
  2058. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2059. return 0;
  2060. }
  2061. if (!spawn->IsEntity()) {
  2062. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2063. return 0;
  2064. }
  2065. if (value == 0) {
  2066. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2067. return 0;
  2068. }
  2069. if (!luaspell || !luaspell->spell) {
  2070. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2071. return 0;
  2072. }
  2073. int32 class_req = 0;
  2074. vector<int16> faction_req;
  2075. vector<int16> race_req;
  2076. int32 class_id = 0;
  2077. int32 i = 0;
  2078. int8 f = 0;
  2079. int8 r = 0;
  2080. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2081. if (class_id < 100) {
  2082. class_req += pow(2.0, double(class_id - 1));
  2083. }
  2084. else if (class_id > 100 && class_id < 1000) {
  2085. race_req.push_back(class_id);
  2086. r++;
  2087. }
  2088. else {
  2089. faction_req.push_back(class_id);
  2090. f++;
  2091. }
  2092. i++;
  2093. }
  2094. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2095. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2096. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2097. if (spawn->IsPlayer())
  2098. ((Player*)spawn)->SetCharSheetChanged(true);
  2099. return 0;
  2100. }
  2101. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2102. if (!lua_interface)
  2103. return 0;
  2104. Spawn* spawn = lua_interface->GetSpawn(state);
  2105. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2106. if (!spawn) {
  2107. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2108. return 0;
  2109. }
  2110. if (!spawn->IsEntity()) {
  2111. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2112. return 0;
  2113. }
  2114. if (!luaspell || !luaspell->spell) {
  2115. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2116. return 0;
  2117. }
  2118. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2119. if (spawn->IsPlayer())
  2120. ((Player*)spawn)->SetCharSheetChanged(true);
  2121. return 0;
  2122. }
  2123. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2124. if (!lua_interface)
  2125. return 0;
  2126. Spawn* spawn = lua_interface->GetSpawn(state);
  2127. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2128. if (luaspell && luaspell->spell) {
  2129. ZoneServer* zone = luaspell->caster->GetZone();
  2130. Spawn* target = 0;
  2131. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2132. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2133. target = zone->GetSpawnByID(luaspell->targets[i]);
  2134. if (target && target->IsEntity()) {
  2135. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2136. if (target->IsPlayer())
  2137. ((Player*)target)->SetCharSheetChanged(true);
  2138. }
  2139. }
  2140. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2141. }
  2142. else if (spawn && spawn->IsEntity()) {
  2143. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2144. if (spawn->IsPlayer())
  2145. ((Player*)spawn)->SetCharSheetChanged(true);
  2146. }
  2147. return 0;
  2148. }
  2149. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2150. if (!lua_interface)
  2151. return 0;
  2152. Spawn* spawn = lua_interface->GetSpawn(state);
  2153. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2154. float value = lua_interface->GetFloatValue(state, 3);
  2155. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2156. if (value != 0) {
  2157. int32 spell_id = 0;
  2158. if (luaspell && luaspell->spell && luaspell->caster) {
  2159. spell_id = luaspell->spell->GetSpellID();
  2160. ZoneServer* zone = luaspell->caster->GetZone();
  2161. Spawn* target = 0;
  2162. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2163. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2164. target = zone->GetSpawnByID(luaspell->targets[i]);
  2165. if (target && target->Alive()) {
  2166. if (target->IsPlayer()) {
  2167. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2168. Client* client = target->GetZone()->GetClientBySpawn(target);
  2169. if (client) {
  2170. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2171. if (packet)
  2172. client->QueuePacket(packet);
  2173. }
  2174. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2175. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2176. }
  2177. else if (target->IsNPC()) {
  2178. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2179. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2180. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2181. }
  2182. else
  2183. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2184. }
  2185. }
  2186. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2187. }
  2188. else if (spawn) {
  2189. if (spawn->IsPlayer()) {
  2190. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2191. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2192. if (client) {
  2193. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2194. if (packet)
  2195. client->QueuePacket(packet);
  2196. }
  2197. }
  2198. else if (spawn->IsNPC())
  2199. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2200. else
  2201. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2202. }
  2203. }
  2204. else
  2205. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2206. return 0;
  2207. }
  2208. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2209. if (!lua_interface)
  2210. return 0;
  2211. Spawn* spawn = lua_interface->GetSpawn(state);
  2212. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2213. if (spawn && spawn->IsPlayer()) {
  2214. int32 spell_id = 0;
  2215. if (luaspell && luaspell->spell) {
  2216. spell_id = luaspell->spell->GetSpellID();
  2217. ZoneServer* zone = luaspell->caster->GetZone();
  2218. Spawn* target = 0;
  2219. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2220. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2221. target = zone->GetSpawnByID(luaspell->targets[i]);
  2222. if (target) {
  2223. if (target->IsPlayer()) {
  2224. ((Player*)target)->RemoveSkillBonus(spell_id);
  2225. Client* client = target->GetZone()->GetClientBySpawn(target);
  2226. if (client) {
  2227. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2228. if (packet)
  2229. client->QueuePacket(packet);
  2230. }
  2231. }
  2232. else if (target->IsNPC())
  2233. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2234. else
  2235. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2236. }
  2237. }
  2238. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2239. }
  2240. else if (spawn) {
  2241. if (spawn->IsPlayer()) {
  2242. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2243. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2244. if (client) {
  2245. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2246. if (packet)
  2247. client->QueuePacket(packet);
  2248. }
  2249. }
  2250. else if (spawn->IsNPC())
  2251. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2252. else
  2253. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2254. }
  2255. }
  2256. return 0;
  2257. }
  2258. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2259. if (!lua_interface)
  2260. return 0;
  2261. Spawn* spawn = lua_interface->GetSpawn(state);
  2262. int8 type = lua_interface->GetInt32Value(state, 2);
  2263. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2264. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2265. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2266. ZoneServer* zone = luaspell->caster->GetZone();
  2267. Spawn* target = 0;
  2268. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2269. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2270. target = zone->GetSpawnByID(luaspell->targets[i]);
  2271. if (target && target->IsEntity()) {
  2272. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2273. ((Entity*)target)->AddMezSpell(luaspell);
  2274. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2275. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2276. if (target->IsNPC())
  2277. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2278. }
  2279. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2280. ((Entity*)target)->AddStifleSpell(luaspell);
  2281. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2282. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2283. if (target->IsNPC())
  2284. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2285. }
  2286. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2287. ((Entity*)target)->AddDazeSpell(luaspell);
  2288. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2289. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2290. if (target->IsNPC())
  2291. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2292. }
  2293. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2294. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2295. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2296. ((Entity*)target)->AddStunSpell(luaspell);
  2297. if (target->IsNPC())
  2298. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2299. }
  2300. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2301. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2302. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2303. ((Entity*)target)->AddRootSpell(luaspell);
  2304. if (target->IsNPC())
  2305. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2306. }
  2307. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2308. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2309. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2310. ((Entity*)target)->AddFearSpell(luaspell);
  2311. if (target->IsNPC())
  2312. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2313. }
  2314. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2315. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2316. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2317. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2318. }
  2319. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2320. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2321. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2322. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2323. }
  2324. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2325. ((Entity*)target)->AddSnareSpell(luaspell);
  2326. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2327. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2328. if (target->IsNPC())
  2329. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2330. }
  2331. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2332. ((Entity*)target)->AddFlightSpell(luaspell);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2335. }
  2336. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2337. ((Entity*)target)->AddGlideSpell(luaspell);
  2338. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2339. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2340. }
  2341. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2342. ((Entity*)target)->AddSafefallSpell(luaspell);
  2343. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2344. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2345. }
  2346. else
  2347. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2348. }
  2349. else
  2350. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2351. }
  2352. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2353. }
  2354. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2355. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2356. ((Entity*)spawn)->AddMezSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2359. }
  2360. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2361. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2362. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2363. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2364. }
  2365. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2366. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2367. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2368. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2369. }
  2370. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2371. ((Entity*)spawn)->AddStunSpell(luaspell);
  2372. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2373. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2374. }
  2375. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2376. ((Entity*)spawn)->AddRootSpell(luaspell);
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2379. }
  2380. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2381. ((Entity*)spawn)->AddFearSpell(luaspell);
  2382. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2383. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2384. }
  2385. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2386. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2387. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2388. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2391. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2392. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2393. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2394. }
  2395. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2396. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2397. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2398. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2399. }
  2400. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2401. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2402. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2403. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2404. }
  2405. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2406. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2407. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2408. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2409. }
  2410. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2411. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2414. }
  2415. else
  2416. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2417. }
  2418. else
  2419. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2420. return 0;
  2421. }
  2422. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2423. if (!lua_interface)
  2424. return 0;
  2425. Spawn* spawn = lua_interface->GetSpawn(state);
  2426. int8 type = lua_interface->GetInt8Value(state, 2);
  2427. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2428. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2429. if (spawn && spawn->IsEntity()) {
  2430. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2431. ZoneServer* zone = luaspell->caster->GetZone();
  2432. Spawn* target = 0;
  2433. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2434. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2435. target = zone->GetSpawnByID(luaspell->targets[i]);
  2436. if (target) {
  2437. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2438. ((Entity*)target)->RemoveMezSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2440. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2442. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2443. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2444. ((Entity*)target)->RemoveStunSpell(luaspell);
  2445. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2446. ((Entity*)target)->RemoveRootSpell(luaspell);
  2447. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2448. ((Entity*)target)->RemoveFearSpell(luaspell);
  2449. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2450. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2451. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2452. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2453. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2454. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2455. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2456. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2457. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2458. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2459. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2460. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2461. else
  2462. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2463. }
  2464. }
  2465. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2466. }
  2467. else if (only_remove_spawn) {
  2468. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2469. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2470. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2471. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2472. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2473. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2474. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2475. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2476. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2477. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2478. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2479. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2480. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2481. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2482. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2483. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2484. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2485. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2486. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2487. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2488. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2489. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2490. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2491. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2492. else
  2493. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2494. }
  2495. }
  2496. return 0;
  2497. }
  2498. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2499. if (!lua_interface)
  2500. return 0;
  2501. Spawn* spawn = lua_interface->GetSpawn(state);
  2502. int8 type = lua_interface->GetInt8Value(state, 2);
  2503. bool hasEffect = false;
  2504. if (!spawn)
  2505. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2506. else if (!spawn->IsEntity())
  2507. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2508. else if (type < CONTROL_MAX_EFFECTS)
  2509. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2510. else
  2511. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2512. lua_interface->SetBooleanValue(state, hasEffect);
  2513. return 1;
  2514. }
  2515. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2516. if (!lua_interface)
  2517. return 0;
  2518. Spawn* spawn = lua_interface->GetSpawn(state);
  2519. float distance = 0.0f;
  2520. if (!spawn)
  2521. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2522. else if (!spawn->IsNPC())
  2523. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2524. else
  2525. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2526. lua_interface->SetFloatValue(state, distance);
  2527. return 1;
  2528. }
  2529. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2530. if (!lua_interface)
  2531. return 0;
  2532. Spawn* spawn = lua_interface->GetSpawn(state);
  2533. float distance = 0.0f;
  2534. if (!spawn)
  2535. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2536. else if (!spawn->IsNPC())
  2537. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2538. else
  2539. distance = ((NPC*)spawn)->GetAggroRadius();
  2540. lua_interface->SetFloatValue(state, distance);
  2541. return 1;
  2542. }
  2543. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2544. if (!lua_interface)
  2545. return 0;
  2546. Spawn* spawn = lua_interface->GetSpawn(state);
  2547. float distance = lua_interface->GetFloatValue(state, 2);
  2548. bool override = lua_interface->GetBooleanValue(state, 3);
  2549. bool result = false;
  2550. lua_interface->ResetFunctionStack(state);
  2551. if (!spawn)
  2552. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2553. else if (!spawn->IsNPC())
  2554. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2555. else
  2556. {
  2557. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2558. result = true;
  2559. }
  2560. lua_interface->SetBooleanValue(state, result);
  2561. return 1;
  2562. }
  2563. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2564. if (!lua_interface)
  2565. return 0;
  2566. Spawn* spawn = lua_interface->GetSpawn(state);
  2567. int16 value = lua_interface->GetInt16Value(state, 2);
  2568. if (spawn && spawn->IsEntity()) {
  2569. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2570. if (spawn->IsPlayer())
  2571. ((Player*)spawn)->SetCharSheetChanged(true);
  2572. }
  2573. return 0;
  2574. }
  2575. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2576. if (!lua_interface)
  2577. return 0;
  2578. Spawn* spawn = lua_interface->GetSpawn(state);
  2579. int16 value = lua_interface->GetInt16Value(state, 2);
  2580. if (spawn && spawn->IsEntity()) {
  2581. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2582. if (spawn->IsPlayer())
  2583. ((Player*)spawn)->SetCharSheetChanged(true);
  2584. }
  2585. return 0;
  2586. }
  2587. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2588. if (!lua_interface)
  2589. return 0;
  2590. Spawn* spawn = lua_interface->GetSpawn(state);
  2591. int16 value = lua_interface->GetInt16Value(state, 2);
  2592. if (spawn && spawn->IsEntity()) {
  2593. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2594. if (spawn->IsPlayer())
  2595. ((Player*)spawn)->SetCharSheetChanged(true);
  2596. }
  2597. return 0;
  2598. }
  2599. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2600. if (!lua_interface)
  2601. return 0;
  2602. Spawn* spawn = lua_interface->GetSpawn(state);
  2603. int16 value = lua_interface->GetInt16Value(state, 2);
  2604. if (spawn && spawn->IsEntity()) {
  2605. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2606. if (spawn->IsPlayer())
  2607. ((Player*)spawn)->SetCharSheetChanged(true);
  2608. }
  2609. return 0;
  2610. }
  2611. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2612. if (!lua_interface)
  2613. return 0;
  2614. Spawn* spawn = lua_interface->GetSpawn(state);
  2615. int16 value = lua_interface->GetInt16Value(state, 2);
  2616. if (spawn && spawn->IsEntity()) {
  2617. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2618. if (spawn->IsPlayer())
  2619. ((Player*)spawn)->SetCharSheetChanged(true);
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. int8 value = lua_interface->GetInt8Value(state, 2);
  2628. if (spawn && spawn->IsEntity()) {
  2629. ((Entity*)spawn)->SetDeity(value);
  2630. if (spawn->IsPlayer())
  2631. ((Player*)spawn)->SetCharSheetChanged(true);
  2632. }
  2633. lua_interface->ResetFunctionStack(state);
  2634. return 0;
  2635. }
  2636. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2637. if (!lua_interface)
  2638. return 0;
  2639. Spawn* spawn = lua_interface->GetSpawn(state);
  2640. if (spawn && spawn->IsEntity()) {
  2641. int8 deity = ((Entity*)spawn)->GetDeity();
  2642. lua_interface->SetInt32Value(state, deity);
  2643. return 1;
  2644. }
  2645. return 0;
  2646. }
  2647. int EQ2Emu_lua_SetInt(lua_State* state) {
  2648. if (!lua_interface)
  2649. return 0;
  2650. Spawn* spawn = lua_interface->GetSpawn(state);
  2651. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2652. if (spawn && spawn->IsEntity()) {
  2653. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2654. if (spawn->IsPlayer())
  2655. ((Player*)spawn)->SetCharSheetChanged(true);
  2656. }
  2657. return 0;
  2658. }
  2659. int EQ2Emu_lua_SetWis(lua_State* state) {
  2660. if (!lua_interface)
  2661. return 0;
  2662. Spawn* spawn = lua_interface->GetSpawn(state);
  2663. float value = lua_interface->GetFloatValue(state, 2);
  2664. if (spawn && spawn->IsEntity()) {
  2665. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2666. if (spawn->IsPlayer())
  2667. ((Player*)spawn)->SetCharSheetChanged(true);
  2668. }
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_SetSta(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Spawn* spawn = lua_interface->GetSpawn(state);
  2675. float value = lua_interface->GetFloatValue(state, 2);
  2676. if (spawn && spawn->IsEntity()) {
  2677. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2678. if (spawn->IsPlayer())
  2679. ((Player*)spawn)->SetCharSheetChanged(true);
  2680. }
  2681. return 0;
  2682. }
  2683. int EQ2Emu_lua_SetStr(lua_State* state) {
  2684. if (!lua_interface)
  2685. return 0;
  2686. Spawn* spawn = lua_interface->GetSpawn(state);
  2687. float value = lua_interface->GetFloatValue(state, 2);
  2688. if (spawn && spawn->IsEntity()) {
  2689. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2690. if (spawn->IsPlayer())
  2691. ((Player*)spawn)->SetCharSheetChanged(true);
  2692. }
  2693. return 0;
  2694. }
  2695. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2696. if (!lua_interface)
  2697. return 0;
  2698. Spawn* spawn = lua_interface->GetSpawn(state);
  2699. float value = lua_interface->GetFloatValue(state, 2);
  2700. if (spawn && spawn->IsEntity()) {
  2701. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2702. if (spawn->IsPlayer())
  2703. ((Player*)spawn)->SetCharSheetChanged(true);
  2704. }
  2705. return 0;
  2706. }
  2707. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2708. if (!lua_interface)
  2709. return 0;
  2710. Spawn* spawn = lua_interface->GetSpawn(state);
  2711. if (spawn) {
  2712. lua_interface->SetInt32Value(state, spawn->GetHP());
  2713. return 1;
  2714. }
  2715. return 0;
  2716. }
  2717. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2718. if (!lua_interface)
  2719. return 0;
  2720. Spawn* spawn = lua_interface->GetSpawn(state);
  2721. if (spawn) {
  2722. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2723. return 1;
  2724. }
  2725. return 0;
  2726. }
  2727. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2728. if (!lua_interface)
  2729. return 0;
  2730. Spawn* spawn = lua_interface->GetSpawn(state);
  2731. if (spawn) {
  2732. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2733. return 1;
  2734. }
  2735. return 0;
  2736. }
  2737. int EQ2Emu_lua_GetName(lua_State* state) {
  2738. if (!lua_interface)
  2739. return 0;
  2740. Spawn* spawn = lua_interface->GetSpawn(state);
  2741. if (spawn) {
  2742. lua_interface->SetStringValue(state, spawn->GetName());
  2743. return 1;
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2748. Spawn* spawn = lua_interface->GetSpawn(state);
  2749. if (spawn) {
  2750. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2751. return 1;
  2752. }
  2753. return 0;
  2754. }
  2755. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2756. if (!lua_interface)
  2757. return 0;
  2758. Spawn* spawn = lua_interface->GetSpawn(state);
  2759. if (spawn) {
  2760. lua_interface->SetInt32Value(state, spawn->GetPower());
  2761. return 1;
  2762. }
  2763. return 0;
  2764. }
  2765. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2766. if (!lua_interface)
  2767. return 0;
  2768. Spawn* spawn = lua_interface->GetSpawn(state);
  2769. if (spawn) {
  2770. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2771. return 1;
  2772. }
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. if (spawn) {
  2780. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2781. return 1;
  2782. }
  2783. return 0;
  2784. }
  2785. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2786. if (!lua_interface)
  2787. return 0;
  2788. Spawn* spawn = lua_interface->GetSpawn(state);
  2789. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2790. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2791. if (spawn && spawn2) {
  2792. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2793. lua_interface->SetFloatValue(state, distance);
  2794. return 1;
  2795. }
  2796. return 0;
  2797. }
  2798. int EQ2Emu_lua_GetX(lua_State* state) {
  2799. if (!lua_interface)
  2800. return 0;
  2801. Spawn* spawn = lua_interface->GetSpawn(state);
  2802. if (spawn) {
  2803. lua_interface->SetFloatValue(state, spawn->GetX());
  2804. return 1;
  2805. }
  2806. return 0;
  2807. }
  2808. int EQ2Emu_lua_GetY(lua_State* state) {
  2809. if (!lua_interface)
  2810. return 0;
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. if (spawn) {
  2813. lua_interface->SetFloatValue(state, spawn->GetY());
  2814. return 1;
  2815. }
  2816. return 0;
  2817. }
  2818. int EQ2Emu_lua_GetZ(lua_State* state) {
  2819. if (!lua_interface)
  2820. return 0;
  2821. Spawn* spawn = lua_interface->GetSpawn(state);
  2822. if (spawn) {
  2823. lua_interface->SetFloatValue(state, spawn->GetZ());
  2824. return 1;
  2825. }
  2826. return 0;
  2827. }
  2828. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2829. if (!lua_interface)
  2830. return 0;
  2831. Spawn* spawn = lua_interface->GetSpawn(state);
  2832. if (spawn) {
  2833. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. if (spawn) {
  2843. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2844. return 1;
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn && spawn->IsEntity()) {
  2863. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetInt(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. if (spawn && spawn->IsEntity()) {
  2873. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2874. return 1;
  2875. }
  2876. return 0;
  2877. }
  2878. int EQ2Emu_lua_GetWis(lua_State* state) {
  2879. if (!lua_interface)
  2880. return 0;
  2881. Spawn* spawn = lua_interface->GetSpawn(state);
  2882. if (spawn && spawn->IsEntity()) {
  2883. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2884. return 1;
  2885. }
  2886. return 0;
  2887. }
  2888. int EQ2Emu_lua_GetSta(lua_State* state) {
  2889. if (!lua_interface)
  2890. return 0;
  2891. Spawn* spawn = lua_interface->GetSpawn(state);
  2892. if (spawn && spawn->IsEntity()) {
  2893. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2894. return 1;
  2895. }
  2896. return 0;
  2897. }
  2898. int EQ2Emu_lua_GetStr(lua_State* state) {
  2899. if (!lua_interface)
  2900. return 0;
  2901. Spawn* spawn = lua_interface->GetSpawn(state);
  2902. if (spawn && spawn->IsEntity()) {
  2903. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2904. return 1;
  2905. }
  2906. return 0;
  2907. }
  2908. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2909. if (!lua_interface)
  2910. return 0;
  2911. Spawn* spawn = lua_interface->GetSpawn(state);
  2912. if (spawn && spawn->IsEntity()) {
  2913. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2914. return 1;
  2915. }
  2916. return 0;
  2917. }
  2918. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2919. if (!lua_interface)
  2920. return 0;
  2921. Spawn* spawn = lua_interface->GetSpawn(state);
  2922. if (spawn && spawn->IsEntity()) {
  2923. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2924. return 1;
  2925. }
  2926. return 0;
  2927. }
  2928. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2929. if (!lua_interface)
  2930. return 0;
  2931. Spawn* spawn = lua_interface->GetSpawn(state);
  2932. if (spawn && spawn->IsEntity()) {
  2933. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2934. return 1;
  2935. }
  2936. return 0;
  2937. }
  2938. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2939. if (!lua_interface)
  2940. return 0;
  2941. Spawn* spawn = lua_interface->GetSpawn(state);
  2942. if (spawn && spawn->IsEntity()) {
  2943. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2944. return 1;
  2945. }
  2946. return 0;
  2947. }
  2948. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2949. if (!lua_interface)
  2950. return 0;
  2951. Spawn* spawn = lua_interface->GetSpawn(state);
  2952. if (spawn && spawn->IsEntity()) {
  2953. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2954. return 1;
  2955. }
  2956. return 0;
  2957. }
  2958. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2959. if (!lua_interface)
  2960. return 0;
  2961. Spawn* spawn = lua_interface->GetSpawn(state);
  2962. if (spawn && spawn->IsEntity()) {
  2963. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2964. return 1;
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Spawn* player = lua_interface->GetSpawn(state);
  2972. if (!player || !player->IsPlayer()) {
  2973. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2974. return 0;
  2975. }
  2976. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2977. if (quest_id <= 0) {
  2978. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2979. return 0;
  2980. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2981. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2982. return 0;
  2983. }
  2984. int32 step = lua_interface->GetInt32Value(state, 3);
  2985. if (step > 0) {
  2986. Client* client = player->GetZone()->GetClientBySpawn(player);
  2987. if (client)
  2988. client->AddPendingQuestUpdate(quest_id, step);
  2989. } else {
  2990. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2991. }
  2992. return 0;
  2993. }
  2994. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2995. Spawn* player = lua_interface->GetSpawn(state);
  2996. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2997. int32 step = lua_interface->GetInt32Value(state, 3);
  2998. int32 progress = lua_interface->GetInt32Value(state, 4);
  2999. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3000. Client* client = player->GetZone()->GetClientBySpawn(player);
  3001. if (client)
  3002. client->AddPendingQuestUpdate(quest_id, step, progress);
  3003. }
  3004. return 0;
  3005. }
  3006. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3007. if (!lua_interface)
  3008. return 0;
  3009. Spawn* player = lua_interface->GetSpawn(state);
  3010. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3011. if (player && player->IsPlayer() && quest_id > 0) {
  3012. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Spawn* player = lua_interface->GetSpawn(state);
  3021. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3022. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3023. if (player && player->IsPlayer() && quest_id > 0) {
  3024. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3025. return 1;
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Spawn* player = lua_interface->GetSpawn(state);
  3033. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3034. if (player && player->IsPlayer() && quest_id > 0) {
  3035. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3041. if (!lua_interface)
  3042. return 0;
  3043. Quest* quest = lua_interface->GetQuest(state);
  3044. string name = lua_interface->GetStringValue(state, 2);
  3045. string type = lua_interface->GetStringValue(state, 3);
  3046. string zone = lua_interface->GetStringValue(state, 4);
  3047. int16 level = lua_interface->GetInt16Value(state, 5);
  3048. string description = lua_interface->GetStringValue(state, 6);
  3049. bool load = true;
  3050. if (!quest) {
  3051. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3052. load = false;
  3053. }
  3054. if (load && name.length() == 0) {
  3055. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3056. load = false;
  3057. }
  3058. if (load && type.length() == 0) {
  3059. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3060. load = false;
  3061. }
  3062. if (load && zone.length() == 0) {
  3063. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3064. load = false;
  3065. }
  3066. if (load && description.length() == 0) {
  3067. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3068. load = false;
  3069. }
  3070. if (load && level == 0) {
  3071. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3072. load = false;
  3073. }
  3074. if (load)
  3075. quest->RegisterQuest(name, type, zone, level, description);
  3076. return 0;
  3077. }
  3078. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3079. if (!lua_interface)
  3080. return 0;
  3081. Quest* quest = lua_interface->GetQuest(state);
  3082. if (quest) {
  3083. int8 level = lua_interface->GetInt16Value(state, 2);
  3084. quest->SetPrereqLevel(level);
  3085. }
  3086. return 0;
  3087. }
  3088. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3089. if (!lua_interface)
  3090. return 0;
  3091. Quest* quest = lua_interface->GetQuest(state);
  3092. if (quest) {
  3093. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3094. quest->AddPrereqQuest(quest_id);
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Quest* quest = lua_interface->GetQuest(state);
  3102. if (quest) {
  3103. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3104. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3105. if (quantity == 0)
  3106. quantity = 1;
  3107. Item* master_item = master_item_list.GetItem(item_id);
  3108. if (master_item) {
  3109. Item* item = new Item(master_item);
  3110. item->details.count = quantity;
  3111. quest->AddPrereqItem(item);
  3112. }
  3113. }
  3114. return 0;
  3115. }
  3116. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3117. if (!lua_interface)
  3118. return 0;
  3119. Spawn* player = lua_interface->GetSpawn(state);
  3120. if(!player || !player->IsPlayer()) {
  3121. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3122. return 0;
  3123. }
  3124. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3125. if (quest_id > 0) {
  3126. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3127. return 1;
  3128. } else {
  3129. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3130. }
  3131. return 0;
  3132. }
  3133. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Quest* quest = lua_interface->GetQuest(state);
  3137. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3138. if (quest && spawn_id > 0)
  3139. quest->SetQuestReturnNPC(spawn_id);
  3140. return 0;
  3141. }
  3142. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3143. if (!lua_interface)
  3144. return 0;
  3145. Spawn* spawn = lua_interface->GetSpawn(state);
  3146. if (!spawn) {
  3147. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3148. return 0;
  3149. }
  3150. int32 time = lua_interface->GetInt32Value(state, 2);
  3151. if (time <= 0) {
  3152. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3153. return 0;
  3154. }
  3155. string function = lua_interface->GetStringValue(state, 3);
  3156. if (function.length() == 0) {
  3157. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3158. return 0;
  3159. }
  3160. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3161. Spawn* player = lua_interface->GetSpawn(state, 5);
  3162. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3163. if ( time < 10)
  3164. time = 10;
  3165. timer->timer = Timer::GetCurrentTime2() + time;
  3166. timer->function = function;
  3167. timer->spawn = spawn->GetID();
  3168. timer->player = player ? player->GetID() : 0;
  3169. if (max_count == 0)
  3170. max_count = 1;
  3171. timer->max_count = max_count;
  3172. timer->current_count = 0;
  3173. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3174. return 0;
  3175. }
  3176. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3177. if (!lua_interface)
  3178. return 0;
  3179. Spawn* player = lua_interface->GetSpawn(state);
  3180. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3181. if (player && player->IsPlayer() && quest_id > 0) {
  3182. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3183. return 1;
  3184. }
  3185. return 0;
  3186. }
  3187. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3188. if (!lua_interface)
  3189. return 0;
  3190. Spawn* player = lua_interface->GetSpawn(state);
  3191. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3192. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3193. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3194. if (quest)
  3195. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3196. return 1;
  3197. }
  3198. return 0;
  3199. }
  3200. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3201. if (!lua_interface)
  3202. return 0;
  3203. Spawn* player = lua_interface->GetSpawn(state);
  3204. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3205. if (player && player->IsPlayer() && quest_id > 0) {
  3206. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3207. return 1;
  3208. }
  3209. return 0;
  3210. }
  3211. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3212. if (!lua_interface)
  3213. return 0;
  3214. Spawn* npc = lua_interface->GetSpawn(state);
  3215. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3216. if (npc && !npc->IsPlayer() && quest_id > 0)
  3217. npc->AddProvidedQuest(quest_id);
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Spawn* npc = lua_interface->GetSpawn(state);
  3224. Spawn* player = lua_interface->GetSpawn(state, 2);
  3225. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3226. bool forced = lua_interface->GetBooleanValue(state, 4);
  3227. /* NPC is allowed to be null */
  3228. if (player && player->IsPlayer() && quest_id > 0) {
  3229. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3230. if (master_quest) {
  3231. Client* client = player->GetZone()->GetClientBySpawn(player);
  3232. if (!client) {
  3233. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3234. }
  3235. Quest* quest = new Quest(master_quest);
  3236. if (!quest) {
  3237. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3238. }
  3239. if (client && quest) {
  3240. if (npc)
  3241. quest->SetQuestGiver(npc->GetDatabaseID());
  3242. else
  3243. quest->SetQuestGiver(0);
  3244. client->AddPendingQuest(quest, forced);
  3245. }
  3246. }
  3247. else {
  3248. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3249. }
  3250. }
  3251. else {
  3252. 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);
  3253. }
  3254. return 0;
  3255. }
  3256. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3257. if (!lua_interface)
  3258. return 0;
  3259. Quest* quest = lua_interface->GetQuest(state);
  3260. if (quest) {
  3261. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3262. quest->AddPrereqClass(class_id);
  3263. }
  3264. return 0;
  3265. }
  3266. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3267. if (!lua_interface)
  3268. return 0;
  3269. Quest* quest = lua_interface->GetQuest(state);
  3270. if (quest) {
  3271. int8 race = lua_interface->GetInt8Value(state, 2);
  3272. quest->AddPrereqRace(race);
  3273. }
  3274. return 0;
  3275. }
  3276. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3277. if (!lua_interface)
  3278. return 0;
  3279. Quest* quest = lua_interface->GetQuest(state);
  3280. if (quest) {
  3281. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3282. quest->AddPrereqModelType(model_type);
  3283. }
  3284. return 0;
  3285. }
  3286. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3287. if (!lua_interface)
  3288. return 0;
  3289. Quest* quest = lua_interface->GetQuest(state);
  3290. if (!quest) {
  3291. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3292. return 0;
  3293. }
  3294. int8 level = lua_interface->GetInt8Value(state, 2);
  3295. quest->SetPrereqTSLevel(level);
  3296. return 0;
  3297. }
  3298. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3299. if (!lua_interface)
  3300. return 0;
  3301. Quest* quest = lua_interface->GetQuest(state);
  3302. if (!quest) {
  3303. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3304. return 0;
  3305. }
  3306. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3307. quest->AddPrereqTradeskillClass(class_id);
  3308. return 0;
  3309. }
  3310. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3311. if (!lua_interface)
  3312. return 0;
  3313. Quest* quest = lua_interface->GetQuest(state);
  3314. if (quest) {
  3315. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3316. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3317. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3318. quest->AddPrereqFaction(faction_id, min, max);
  3319. }
  3320. return 0;
  3321. }
  3322. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3323. if (!lua_interface)
  3324. return 0;
  3325. Quest* quest = lua_interface->GetQuest(state);
  3326. if (quest) {
  3327. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3328. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3329. if (quantity == 0)
  3330. quantity = 1;
  3331. Item* master_item = master_item_list.GetItem(item_id);
  3332. if (master_item) {
  3333. Item* item = new Item(master_item);
  3334. item->details.count = quantity;
  3335. quest->AddSelectableRewardItem(item);
  3336. }
  3337. }
  3338. return 0;
  3339. }
  3340. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3341. if (!lua_interface)
  3342. return 0;
  3343. Quest* quest = lua_interface->GetQuest(state);
  3344. if (quest) {
  3345. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3346. vector<Item*>* items = quest->GetRewardItems();
  3347. if (items) {
  3348. vector<Item*>::iterator itr;
  3349. for (itr = items->begin(); itr != items->end(); itr++) {
  3350. if (*itr && (*itr)->details.item_id == item_id) {
  3351. lua_interface->SetBooleanValue(state, true);
  3352. return 1;
  3353. }
  3354. }
  3355. }
  3356. }
  3357. lua_interface->SetBooleanValue(state, false);
  3358. return 1;
  3359. }
  3360. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Quest* quest = lua_interface->GetQuest(state);
  3364. if (quest) {
  3365. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3366. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3367. if (quantity == 0)
  3368. quantity = 1;
  3369. Item* master_item = master_item_list.GetItem(item_id);
  3370. if (master_item) {
  3371. Item* item = new Item(master_item);
  3372. item->details.count = quantity;
  3373. quest->AddRewardItem(item);
  3374. }
  3375. }
  3376. return 0;
  3377. }
  3378. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3379. if (!lua_interface)
  3380. return 0;
  3381. Quest* quest = lua_interface->GetQuest(state);
  3382. if (quest) {
  3383. int32 copper = lua_interface->GetInt32Value(state, 2);
  3384. int32 silver = lua_interface->GetInt32Value(state, 3);
  3385. int32 gold = lua_interface->GetInt32Value(state, 4);
  3386. int32 plat = lua_interface->GetInt32Value(state, 5);
  3387. quest->AddRewardCoins(copper, silver, gold, plat);
  3388. }
  3389. return 0;
  3390. }
  3391. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3392. if (!lua_interface)
  3393. return 0;
  3394. Quest* quest = lua_interface->GetQuest(state);
  3395. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3396. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3397. if (quest && faction_id > 0 && amount != 0)
  3398. quest->AddRewardFaction(faction_id, amount);
  3399. return 0;
  3400. }
  3401. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3402. if (!lua_interface)
  3403. return 0;
  3404. Quest* quest = lua_interface->GetQuest(state);
  3405. if (quest) {
  3406. int32 status = lua_interface->GetInt32Value(state, 2);
  3407. quest->SetRewardStatus(status);
  3408. }
  3409. return 0;
  3410. }
  3411. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3412. if (!lua_interface)
  3413. return 0;
  3414. Quest* quest = lua_interface->GetQuest(state);
  3415. if (quest) {
  3416. int32 status = lua_interface->GetInt32Value(state, 2);
  3417. quest->SetStatusTmpReward(status);
  3418. }
  3419. return 0;
  3420. }
  3421. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3422. if (!lua_interface)
  3423. return 0;
  3424. Quest* quest = lua_interface->GetQuest(state);
  3425. if (quest) {
  3426. int64 coins = lua_interface->GetInt64Value(state, 2);
  3427. quest->SetCoinTmpReward(coins);
  3428. }
  3429. return 0;
  3430. }
  3431. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3432. if (!lua_interface)
  3433. return 0;
  3434. Quest* quest = lua_interface->GetQuest(state);
  3435. if (quest) {
  3436. string comment = lua_interface->GetStringValue(state, 2);
  3437. quest->SetRewardComment(comment);
  3438. }
  3439. return 0;
  3440. }
  3441. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3442. if (!lua_interface)
  3443. return 0;
  3444. Quest* quest = lua_interface->GetQuest(state);
  3445. if (quest) {
  3446. int32 exp = lua_interface->GetInt32Value(state, 2);
  3447. quest->SetRewardXP(exp);
  3448. }
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3452. Quest* quest = lua_interface->GetQuest(state);
  3453. if (quest) {
  3454. int32 step = lua_interface->GetInt32Value(state, 2);
  3455. string description = lua_interface->GetStringValue(state, 3);
  3456. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3457. float percentage = lua_interface->GetFloatValue(state, 5);
  3458. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3459. const char* taskgroup = 0;
  3460. if (str_taskgroup.length() > 0)
  3461. taskgroup = str_taskgroup.c_str();
  3462. int16 icon = lua_interface->GetInt16Value(state, 7);
  3463. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3464. int32 id = 0;
  3465. vector<int32>* ids = 0;
  3466. int i = 0;
  3467. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3468. if (ids == 0)
  3469. ids = new vector<int32>;
  3470. ids->push_back(id);
  3471. i++;
  3472. }
  3473. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3474. if (quest_step && icon && quantity > 0)
  3475. quest_step->SetIcon(icon);
  3476. if (quest->GetPlayer()) {
  3477. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3478. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3479. }
  3480. }
  3481. return 0;
  3482. }
  3483. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3484. {
  3485. if (!lua_interface)
  3486. return 0;
  3487. Quest* quest = lua_interface->GetQuest(state);
  3488. if (quest) {
  3489. int32 step = lua_interface->GetInt32Value(state, 2);
  3490. string description = lua_interface->GetStringValue(state, 3);
  3491. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3492. float percentage = lua_interface->GetFloatValue(state, 5);
  3493. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3494. int16 icon = lua_interface->GetInt16Value(state, 7);
  3495. const char* taskgroup = 0;
  3496. if (str_taskgroup.length() > 0)
  3497. taskgroup = str_taskgroup.c_str();
  3498. int32 id = 0;
  3499. vector<int32>* ids = 0;
  3500. int i = 0;
  3501. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3502. if (ids == 0)
  3503. ids = new vector<int32>;
  3504. ids->push_back(id);
  3505. i++;
  3506. }
  3507. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3508. if (quest_step && icon > 0 && quantity > 0)
  3509. quest_step->SetIcon(icon);
  3510. if (quest->GetPlayer()) {
  3511. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3512. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3513. }
  3514. safe_delete(ids);
  3515. }
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3519. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3520. }
  3521. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3522. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3523. }
  3524. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3525. if (!lua_interface)
  3526. return 0;
  3527. Quest* quest = lua_interface->GetQuest(state);
  3528. if (quest) {
  3529. int32 step = lua_interface->GetInt32Value(state, 2);
  3530. string description = lua_interface->GetStringValue(state, 3);
  3531. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3532. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3533. int16 icon = lua_interface->GetInt16Value(state, 6);
  3534. const char* taskgroup = 0;
  3535. if (str_taskgroup.length() > 0)
  3536. taskgroup = str_taskgroup.c_str();
  3537. int32 npc_id = 0;
  3538. vector<int32>* ids = 0;
  3539. int i = 0;
  3540. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3541. if (ids == 0)
  3542. ids = new vector<int32>;
  3543. ids->push_back(npc_id);
  3544. i++;
  3545. }
  3546. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3547. if (quest_step && icon > 0)
  3548. quest_step->SetIcon(icon);
  3549. if (quest->GetPlayer()) {
  3550. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3551. if(client)
  3552. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3553. }
  3554. safe_delete(ids);
  3555. }
  3556. return 0;
  3557. }
  3558. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3559. if (!lua_interface)
  3560. return 0;
  3561. Quest* quest = lua_interface->GetQuest(state);
  3562. if (quest) {
  3563. int32 step = lua_interface->GetInt32Value(state, 2);
  3564. string description = lua_interface->GetStringValue(state, 3);
  3565. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3566. float percentage = lua_interface->GetFloatValue(state, 5);
  3567. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3568. int16 icon = lua_interface->GetInt16Value(state, 7);
  3569. const char* taskgroup = 0;
  3570. if (str_taskgroup.length() > 0)
  3571. taskgroup = str_taskgroup.c_str();
  3572. int32 item_id = 0;
  3573. vector<int32>* ids = 0;
  3574. int i = 0;
  3575. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3576. if (ids == 0)
  3577. ids = new vector<int32>;
  3578. ids->push_back(item_id);
  3579. i++;
  3580. }
  3581. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3582. if (quest_step && icon > 0 && quantity > 0)
  3583. quest_step->SetIcon(icon);
  3584. if (quest->GetPlayer()) {
  3585. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3586. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3587. }
  3588. safe_delete(ids);
  3589. }
  3590. return 0;
  3591. }
  3592. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3593. if (!lua_interface)
  3594. return 0;
  3595. Quest* quest = lua_interface->GetQuest(state);
  3596. if (quest) {
  3597. int32 step = lua_interface->GetInt32Value(state, 2);
  3598. string description = lua_interface->GetStringValue(state, 3);
  3599. float max_variation = lua_interface->GetFloatValue(state, 4);
  3600. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3601. int16 icon = lua_interface->GetInt16Value(state, 6);
  3602. const char* taskgroup = 0;
  3603. if (str_taskgroup.length() > 0)
  3604. taskgroup = str_taskgroup.c_str();
  3605. vector<Location>* locations = 0;
  3606. int8 i = 7;
  3607. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3608. while (true) {
  3609. Location loc;
  3610. loc.x = lua_interface->GetFloatValue(state, i);
  3611. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3612. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3613. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3614. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3615. break;
  3616. if (locations == 0)
  3617. locations = new vector<Location>;
  3618. locations->push_back(loc);
  3619. i += 4;
  3620. }
  3621. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3622. if (quest_step && icon > 0)
  3623. quest_step->SetIcon(icon);
  3624. if (quest->GetPlayer()) {
  3625. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3626. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3627. }
  3628. }
  3629. return 0;
  3630. }
  3631. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3632. if (!lua_interface)
  3633. return 0;
  3634. Quest* quest = lua_interface->GetQuest(state);
  3635. if (quest) {
  3636. int32 step = lua_interface->GetInt32Value(state, 2);
  3637. string description = lua_interface->GetStringValue(state, 3);
  3638. float max_variation = lua_interface->GetFloatValue(state, 4);
  3639. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3640. int16 icon = lua_interface->GetInt16Value(state, 6);
  3641. const char* taskgroup = 0;
  3642. if (str_taskgroup.length() > 0)
  3643. taskgroup = str_taskgroup.c_str();
  3644. vector<Location>* locations = 0;
  3645. int8 i = 7;
  3646. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3647. while (true) {
  3648. Location loc;
  3649. loc.x = lua_interface->GetFloatValue(state, i);
  3650. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3651. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3652. loc.zone_id = 0;
  3653. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3654. break;
  3655. if (locations == 0)
  3656. locations = new vector<Location>;
  3657. locations->push_back(loc);
  3658. i += 3;
  3659. }
  3660. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3661. if (quest_step && icon > 0)
  3662. quest_step->SetIcon(icon);
  3663. if (quest->GetPlayer()) {
  3664. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3665. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3666. }
  3667. }
  3668. return 0;
  3669. }
  3670. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3671. if (!lua_interface)
  3672. return 0;
  3673. Quest* quest = lua_interface->GetQuest(state);
  3674. if (quest) {
  3675. int32 step = lua_interface->GetInt32Value(state, 2);
  3676. string description = lua_interface->GetStringValue(state, 3);
  3677. float max_variation = lua_interface->GetFloatValue(state, 4);
  3678. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3679. int16 icon = lua_interface->GetInt16Value(state, 6);
  3680. const char* taskgroup = 0;
  3681. if (str_taskgroup.length() > 0)
  3682. taskgroup = str_taskgroup.c_str();
  3683. vector<Location>* locations = 0;
  3684. int i = 7;
  3685. while (true) {
  3686. Location loc;
  3687. loc.x = lua_interface->GetFloatValue(state, i);
  3688. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3689. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3690. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3691. break;
  3692. if (locations == 0)
  3693. locations = new vector<Location>;
  3694. locations->push_back(loc);
  3695. i += 3;
  3696. }
  3697. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3698. if (quest_step && icon > 0)
  3699. quest_step->SetIcon(icon);
  3700. if (quest->GetPlayer()) {
  3701. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3702. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3703. }
  3704. }
  3705. return 0;
  3706. }
  3707. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3708. Quest* quest = lua_interface->GetQuest(state);
  3709. if (quest) {
  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. float percentage = lua_interface->GetFloatValue(state, 5);
  3714. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3715. int16 icon = lua_interface->GetInt16Value(state, 7);
  3716. const char* taskgroup = 0;
  3717. if (str_taskgroup.length() > 0)
  3718. taskgroup = str_taskgroup.c_str();
  3719. int32 spell_id = 0;
  3720. vector<int32>* ids = 0;
  3721. int i = 0;
  3722. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3723. if (ids == 0)
  3724. ids = new vector<int32>;
  3725. ids->push_back(spell_id);
  3726. i++;
  3727. }
  3728. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3729. if (quest_step && icon > 0 && quantity > 0)
  3730. quest_step->SetIcon(icon);
  3731. if (quest->GetPlayer()) {
  3732. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3733. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3734. }
  3735. safe_delete(ids);
  3736. }
  3737. return 0;
  3738. }
  3739. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3740. if (!lua_interface)
  3741. return 0;
  3742. Quest* quest = lua_interface->GetQuest(state);
  3743. if (quest) {
  3744. int32 step = lua_interface->GetInt32Value(state, 2);
  3745. string description = lua_interface->GetStringValue(state, 3);
  3746. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3747. float percentage = lua_interface->GetFloatValue(state, 5);
  3748. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3749. int16 icon = lua_interface->GetInt16Value(state, 7);
  3750. const char* taskgroup = 0;
  3751. if (str_taskgroup.length() > 0)
  3752. taskgroup = str_taskgroup.c_str();
  3753. int32 item_id = 0;
  3754. vector<int32>* ids = 0;
  3755. int i = 0;
  3756. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3757. if (ids == 0)
  3758. ids = new vector<int32>;
  3759. ids->push_back(item_id);
  3760. i++;
  3761. }
  3762. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3763. if (quest_step && icon > 0 && quantity > 0)
  3764. quest_step->SetIcon(icon);
  3765. if (quest->GetPlayer()) {
  3766. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3767. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3768. }
  3769. safe_delete(ids);
  3770. }
  3771. return 0;
  3772. }
  3773. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3774. if (!lua_interface)
  3775. return 0;
  3776. Quest* quest = lua_interface->GetQuest(state);
  3777. if (quest) {
  3778. int32 step = lua_interface->GetInt32Value(state, 2);
  3779. string description = lua_interface->GetStringValue(state, 3);
  3780. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3781. float percentage = lua_interface->GetFloatValue(state, 5);
  3782. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3783. int16 icon = lua_interface->GetInt16Value(state, 7);
  3784. const char* taskgroup = 0;
  3785. if (str_taskgroup.length() > 0)
  3786. taskgroup = str_taskgroup.c_str();
  3787. int32 item_id = 0;
  3788. vector<int32>* ids = 0;
  3789. int i = 0;
  3790. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3791. if (ids == 0)
  3792. ids = new vector<int32>;
  3793. ids->push_back(item_id);
  3794. i++;
  3795. }
  3796. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3797. if (quest_step && icon > 0 && quantity > 0)
  3798. quest_step->SetIcon(icon);
  3799. if (quest->GetPlayer()) {
  3800. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3801. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3802. }
  3803. safe_delete(ids);
  3804. }
  3805. return 0;
  3806. }
  3807. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3808. if (!lua_interface)
  3809. return 0;
  3810. Quest* quest = lua_interface->GetQuest(state);
  3811. if (quest) {
  3812. string action = lua_interface->GetStringValue(state, 2);
  3813. if (action.length() > 0)
  3814. quest->SetCompleteAction(action);
  3815. }
  3816. return 0;
  3817. }
  3818. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3819. if (!lua_interface)
  3820. return 0;
  3821. Quest* quest = lua_interface->GetQuest(state);
  3822. if (quest) {
  3823. int32 step = lua_interface->GetInt32Value(state, 2);
  3824. string action = lua_interface->GetStringValue(state, 3);
  3825. if (step > 0 && action.length() > 0)
  3826. quest->AddCompleteAction(step, action);
  3827. }
  3828. return 0;
  3829. }
  3830. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3831. if (!lua_interface)
  3832. return 0;
  3833. Quest* quest = lua_interface->GetQuest(state);
  3834. if (quest) {
  3835. int32 step = lua_interface->GetInt32Value(state, 2);
  3836. string action = lua_interface->GetStringValue(state, 3);
  3837. if (step > 0 && action.length() > 0)
  3838. quest->AddProgressAction(step, action);
  3839. }
  3840. return 0;
  3841. }
  3842. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3843. if (!lua_interface)
  3844. return 0;
  3845. Quest* quest = lua_interface->GetQuest(state);
  3846. string description = lua_interface->GetStringValue(state, 2);
  3847. if (quest && description.length() > 0)
  3848. quest->SetDescription(description);
  3849. return 0;
  3850. }
  3851. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3852. if (!lua_interface)
  3853. return 0;
  3854. Quest* quest = lua_interface->GetQuest(state);
  3855. string description = lua_interface->GetStringValue(state, 2);
  3856. if (quest && description.length() > 0)
  3857. quest->SetCompletedDescription(description);
  3858. return 0;
  3859. }
  3860. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3861. if (!lua_interface)
  3862. return 0;
  3863. Quest* quest = lua_interface->GetQuest(state);
  3864. int32 step = lua_interface->GetInt32Value(state, 2);
  3865. string description = lua_interface->GetStringValue(state, 3);
  3866. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3867. if (quest && step > 0 && description.length() > 0) {
  3868. quest->SetTaskGroupDescription(step, description, display_bullets);
  3869. /* if (quest->GetPlayer()) {
  3870. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3871. if (client)
  3872. client->SendQuestUpdateStep(quest, step, false);
  3873. }*/
  3874. }
  3875. return 0;
  3876. }
  3877. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3878. if (!lua_interface)
  3879. return 0;
  3880. Quest* quest = lua_interface->GetQuest(state);
  3881. int32 step = lua_interface->GetInt32Value(state, 2);
  3882. string description = lua_interface->GetStringValue(state, 3);
  3883. if (quest && step > 0 && description.length() > 0) {
  3884. quest->SetStepDescription(step, description);
  3885. /*if (quest->GetPlayer()) {
  3886. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3887. if (client)
  3888. client->SendQuestUpdateStepImmediately(quest, step);
  3889. }*/
  3890. }
  3891. return 0;
  3892. }
  3893. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3894. Quest* quest = lua_interface->GetQuest(state);
  3895. string zone = lua_interface->GetStringValue(state, 2);
  3896. if (quest && zone.length() > 0)
  3897. quest->SetZone(zone);
  3898. return 0;
  3899. }
  3900. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3901. if (!lua_interface)
  3902. return 0;
  3903. Quest* quest = lua_interface->GetQuest(state);
  3904. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3905. lua_interface->ResetFunctionStack(state);
  3906. if (quest && spawn) {
  3907. if (spawn->IsPlayer()) {
  3908. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3909. if (client)
  3910. {
  3911. client->AddPendingQuestAcceptReward(quest);
  3912. client->AddPendingQuestReward(quest);
  3913. }
  3914. }
  3915. }
  3916. return 0;
  3917. }
  3918. int EQ2Emu_lua_Harvest(lua_State* state) {
  3919. if (!lua_interface)
  3920. return 0;
  3921. Spawn* player = lua_interface->GetSpawn(state);
  3922. Spawn* node = lua_interface->GetSpawn(state, 2);
  3923. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3924. Client* client = player->GetZone()->GetClientBySpawn(player);
  3925. if (client) {
  3926. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3927. ((GroundSpawn*)node)->ProcessHarvest(client);
  3928. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  3929. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  3930. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  3931. }
  3932. }
  3933. }
  3934. else if (player && player->IsPlayer()) {
  3935. Client* client = player->GetZone()->GetClientBySpawn(player);
  3936. if (client)
  3937. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3938. }
  3939. return 0;
  3940. }
  3941. int EQ2Emu_lua_Bind(lua_State* state) {
  3942. if (!lua_interface)
  3943. return 0;
  3944. Spawn* spawn = lua_interface->GetSpawn(state);
  3945. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3946. float x = lua_interface->GetFloatValue(state, 3);
  3947. float y = lua_interface->GetFloatValue(state, 4);
  3948. float z = lua_interface->GetFloatValue(state, 5);
  3949. float h = lua_interface->GetFloatValue(state, 6);
  3950. if (!spawn) {
  3951. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3952. return 0;
  3953. }
  3954. if (!spawn->IsPlayer()) {
  3955. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3956. return 0;
  3957. }
  3958. if (zone_id == 0) {
  3959. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3960. if (!client) {
  3961. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3962. return 0;
  3963. }
  3964. if (!client->Bind())
  3965. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3966. }
  3967. else {
  3968. Player* player = (Player*)spawn;
  3969. player->GetPlayerInfo()->SetBindZone(zone_id);
  3970. player->GetPlayerInfo()->SetBindX(x);
  3971. player->GetPlayerInfo()->SetBindY(y);
  3972. player->GetPlayerInfo()->SetBindZ(z);
  3973. player->GetPlayerInfo()->SetBindHeading(h);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_Gate(lua_State* state) {
  3978. if (!lua_interface)
  3979. return 0;
  3980. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  3981. Spawn* spawn = lua_interface->GetSpawn(state);
  3982. if (spawn) {
  3983. if (spawn->IsPlayer()) {
  3984. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3985. if (client) {
  3986. if (!client->Gate((spell != nullptr) ? true : false))
  3987. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3988. }
  3989. }
  3990. }
  3991. return 0;
  3992. }
  3993. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3994. if (!lua_interface)
  3995. return 0;
  3996. bool ret = false;
  3997. Spawn* spawn = lua_interface->GetSpawn(state);
  3998. if (spawn) {
  3999. if (spawn->IsPlayer()) {
  4000. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4001. if (client)
  4002. ret = client->BindAllowed();
  4003. }
  4004. }
  4005. lua_interface->SetBooleanValue(state, ret);
  4006. return 1;
  4007. }
  4008. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4009. if (!lua_interface)
  4010. return 0;
  4011. bool ret = false;
  4012. Spawn* spawn = lua_interface->GetSpawn(state);
  4013. if (spawn) {
  4014. if (spawn->IsPlayer()) {
  4015. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4016. if (client)
  4017. ret = client->GateAllowed();
  4018. }
  4019. }
  4020. lua_interface->SetBooleanValue(state, ret);
  4021. return 1;
  4022. }
  4023. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4024. Spawn* spawn = lua_interface->GetSpawn(state);
  4025. if (spawn) {
  4026. lua_interface->SetBooleanValue(state, spawn->Alive());
  4027. return 1;
  4028. }
  4029. return 0;
  4030. }
  4031. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4032. if (!lua_interface)
  4033. return 0;
  4034. Spawn* spawn = lua_interface->GetSpawn(state);
  4035. if (spawn && spawn->IsEntity()) {
  4036. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4037. return 1;
  4038. }
  4039. return 0;
  4040. }
  4041. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4042. Spawn* spawn = lua_interface->GetSpawn(state);
  4043. string message = lua_interface->GetStringValue(state, 2);
  4044. string color_str = lua_interface->GetStringValue(state, 3);
  4045. int8 color = CHANNEL_NARRATIVE;
  4046. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4047. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4048. if (client) {
  4049. if (color_str.length() > 0) {
  4050. // leave for backwards compat, but all future should just use the number
  4051. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4052. color = CHANNEL_COLOR_RED;
  4053. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4054. color = CHANNEL_COLOR_YELLOW;
  4055. else
  4056. {
  4057. // use a number to specify the channel as per Commands/Commands.h defines
  4058. color = (int8)atoul(color_str.c_str());
  4059. }
  4060. }
  4061. client->SimpleMessage(color, message.c_str());
  4062. }
  4063. }
  4064. return 0;
  4065. }
  4066. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4067. Spawn* spawn = lua_interface->GetSpawn(state);
  4068. string message = lua_interface->GetStringValue(state, 2);
  4069. int8 red = lua_interface->GetInt8Value(state, 3);
  4070. int8 green = lua_interface->GetInt8Value(state, 4);
  4071. int8 blue = lua_interface->GetInt8Value(state, 5);
  4072. if (!spawn) {
  4073. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4074. return 0;
  4075. }
  4076. int32 words = ::CountWordsInString(message.c_str());
  4077. if (words < 5)
  4078. words = 5;
  4079. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4080. if (client)
  4081. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4082. return 0;
  4083. }
  4084. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4085. Spawn* spawn = lua_interface->GetSpawn(state);
  4086. int8 param = lua_interface->GetInt8Value(state, 2);
  4087. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4088. int8 value = lua_interface->GetInt8Value(state, 4);
  4089. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4090. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4091. if (client) {
  4092. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4093. switch (param) {
  4094. case 1: {
  4095. packet->setDataByName("parameter1", param_value);
  4096. break;
  4097. }
  4098. case 2: {
  4099. packet->setDataByName("parameter2", param_value);
  4100. break;
  4101. }
  4102. case 3: {
  4103. packet->setDataByName("parameter3", param_value);
  4104. break;
  4105. }
  4106. case 4: {
  4107. packet->setDataByName("parameter4", param_value);
  4108. break;
  4109. }
  4110. case 5: {
  4111. packet->setDataByName("parameter5", param_value);
  4112. break;
  4113. }
  4114. }
  4115. packet->setDataByName("value", value);
  4116. client->QueuePacket(packet->serialize());
  4117. safe_delete(packet);
  4118. }
  4119. }
  4120. return 0;
  4121. }
  4122. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4123. Spawn* spawn = lua_interface->GetSpawn(state);
  4124. if (spawn && spawn->IsPlayer()) {
  4125. if (((Player*)spawn)->GetIsTracking())
  4126. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4127. else
  4128. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4129. }
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4133. Spawn* player = lua_interface->GetSpawn(state);
  4134. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4135. string name = lua_interface->GetStringValue(state, 3);
  4136. float distance = lua_interface->GetFloatValue(state, 4);
  4137. string command = lua_interface->GetStringValue(state, 5);
  4138. string error_text = lua_interface->GetStringValue(state, 6);
  4139. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4140. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4141. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4142. if (spawn) {
  4143. if (distance == 0)
  4144. distance = 10.0f;
  4145. if (command.length() == 0)
  4146. command = name;
  4147. if (command.length() < 1 && name.length() < 1)
  4148. {
  4149. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4150. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4151. spawn->RemovePrimaryCommands();
  4152. }
  4153. else
  4154. {
  4155. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4156. }
  4157. }
  4158. return 0;
  4159. }
  4160. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4161. if (!lua_interface)
  4162. return 0;
  4163. Spawn* player = lua_interface->GetSpawn(state);
  4164. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4165. int16 tier = lua_interface->GetInt16Value(state, 3);
  4166. if (player && player->IsPlayer()) {
  4167. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4168. return 1;
  4169. }
  4170. return 0;
  4171. }
  4172. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4173. if (!lua_interface)
  4174. return 0;
  4175. Spawn* player = lua_interface->GetSpawn(state);
  4176. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4177. int16 tier = lua_interface->GetInt16Value(state, 3);
  4178. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4179. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4180. bool add_to_hotbar = true;
  4181. if (num_args > 4) {
  4182. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4183. }
  4184. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4185. if (player && spell && player->IsPlayer()) {
  4186. Client* client = player->GetClient();
  4187. if (client) {
  4188. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4189. {
  4190. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4191. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4192. client->GetPlayer()->UnlockSpell(spell);
  4193. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4194. }
  4195. else
  4196. {
  4197. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4198. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4199. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4200. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4201. client->GetPlayer()->UnlockSpell(spell);
  4202. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4203. }
  4204. //if (client ) {
  4205. // ((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);
  4206. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4207. if (outapp)
  4208. client->QueuePacket(outapp);
  4209. }
  4210. }
  4211. return 0;
  4212. }
  4213. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4214. if (!lua_interface)
  4215. return 0;
  4216. Spawn* player = lua_interface->GetSpawn(state);
  4217. if (player && player->IsPlayer()) {
  4218. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4219. return 1;
  4220. }
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_Attack(lua_State* state) {
  4224. if (lua_interface) {
  4225. Spawn* npc = lua_interface->GetSpawn(state);
  4226. Spawn* player = lua_interface->GetSpawn(state, 2);
  4227. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4228. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4229. }
  4230. return 0;
  4231. }
  4232. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4233. if (lua_interface) {
  4234. Spawn* target = lua_interface->GetSpawn(state);
  4235. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4236. if (target && target->GetZone())
  4237. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4238. }
  4239. return 0;
  4240. }
  4241. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4242. Spawn* player;
  4243. if (lua_interface) {
  4244. player = lua_interface->GetSpawn(state);
  4245. if (player && player->IsPlayer()) {
  4246. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4247. return 1;
  4248. }
  4249. }
  4250. return 0;
  4251. }
  4252. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4253. Spawn* player;
  4254. Client* client;
  4255. if (lua_interface) {
  4256. player = lua_interface->GetSpawn(state);
  4257. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4258. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4259. client->HandInCollections();
  4260. }
  4261. return 0;
  4262. }
  4263. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4264. Spawn* widget;
  4265. if (lua_interface) {
  4266. widget = lua_interface->GetSpawn(state);
  4267. if (widget && widget->IsWidget())
  4268. ((Widget*)widget)->HandleUse(nullptr, "");
  4269. }
  4270. return 0;
  4271. }
  4272. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4273. Spawn* spawn = 0;
  4274. int32 primary_list = 0;
  4275. int32 secondary_list = 0;
  4276. if (lua_interface) {
  4277. spawn = lua_interface->GetSpawn(state);
  4278. primary_list = lua_interface->GetInt32Value(state, 2);
  4279. secondary_list = lua_interface->GetInt32Value(state, 3);
  4280. if (!spawn->IsNPC()) {
  4281. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4282. return 0;
  4283. }
  4284. NPC* npc = (NPC*)spawn;
  4285. npc->SetPrimarySpellList(primary_list);
  4286. npc->SetSecondarySpellList(secondary_list);
  4287. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4288. }
  4289. return 0;
  4290. }
  4291. int EQ2Emu_lua_GetPet(lua_State* state) {
  4292. if (!lua_interface)
  4293. return 0;
  4294. Spawn* spawn = lua_interface->GetSpawn(state);
  4295. if (spawn) {
  4296. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4297. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4298. return 1;
  4299. }
  4300. }
  4301. return 0;
  4302. }
  4303. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4304. if (!lua_interface)
  4305. return 0;
  4306. Spawn* spawn = lua_interface->GetSpawn(state);
  4307. if (spawn) {
  4308. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4309. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4310. return 1;
  4311. }
  4312. }
  4313. return 0;
  4314. }
  4315. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4316. if (!lua_interface)
  4317. return 0;
  4318. Spawn* spawn = lua_interface->GetSpawn(state);
  4319. if (spawn) {
  4320. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4321. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4322. return 1;
  4323. }
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4328. if (!lua_interface)
  4329. return 0;
  4330. Spawn* spawn = lua_interface->GetSpawn(state);
  4331. if (spawn) {
  4332. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4333. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4334. return 1;
  4335. }
  4336. }
  4337. return 0;
  4338. }
  4339. int EQ2Emu_lua_Charm(lua_State* state) {
  4340. if (!lua_interface)
  4341. return 0;
  4342. Spawn* owner = lua_interface->GetSpawn(state);
  4343. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4344. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4345. if (!luaspell) {
  4346. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4347. return 0;
  4348. }
  4349. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4350. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4351. pet->SetPet(true);
  4352. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4353. ((NPC*)pet)->SetOwner((Entity*)owner);
  4354. // If owner is player and player does not have a summoned pet set the players charsheet
  4355. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4356. Player* player = (Player*)owner;
  4357. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4358. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4359. player->GetInfoStruct()->set_pet_movement(2);
  4360. player->GetInfoStruct()->set_pet_behavior(3);
  4361. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4362. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4363. // Make sure the values get sent to the client
  4364. player->SetCharSheetChanged(true);
  4365. }
  4366. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4367. pet->SetSpawnScript("");
  4368. // Set faction to the same as the owner
  4369. pet->SetFactionID(owner->GetFactionID());
  4370. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4371. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4372. // Clear hate list
  4373. ((NPC*)pet)->Brain()->ClearHate();
  4374. // Set the brain to a pet brain
  4375. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4376. }
  4377. return 0;
  4378. }
  4379. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4380. if (!lua_interface)
  4381. return 0;
  4382. Spawn* spawn = lua_interface->GetSpawn(state);
  4383. if (!spawn) {
  4384. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4385. return 0;
  4386. }
  4387. vector<Spawn*> groupMembers;
  4388. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4389. groupMembers = *spawn->GetSpawnGroup();
  4390. }
  4391. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4392. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4393. deque<GroupMemberInfo*>::iterator itr;
  4394. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4395. if (group)
  4396. {
  4397. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4398. deque<GroupMemberInfo*>* members = group->GetMembers();
  4399. GroupMemberInfo* info = 0;
  4400. for (itr = members->begin(); itr != members->end(); itr++) {
  4401. info = *itr;
  4402. if (info->client)
  4403. groupMembers.push_back(info->client->GetPlayer());
  4404. }
  4405. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4406. }
  4407. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4408. }
  4409. else
  4410. return 0;
  4411. lua_createtable(state, groupMembers.size(), 0);
  4412. int newTable = lua_gettop(state);
  4413. for (int32 i = 0; i < groupMembers.size(); i++) {
  4414. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4415. lua_rawseti(state, newTable, i + 1);
  4416. }
  4417. return 1;
  4418. }
  4419. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4420. if (!lua_interface)
  4421. return 0;
  4422. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4423. lua_interface->SetOptionWindowValue(state, option_window);
  4424. return 1;
  4425. }
  4426. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4427. if (!lua_interface)
  4428. return 0;
  4429. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4430. if (option_window) {
  4431. OptionWindowOption option_window_option;
  4432. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4433. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4434. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4435. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4436. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4437. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4438. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4439. option_window->push_back(option_window_option);
  4440. }
  4441. return 0;
  4442. }
  4443. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4444. if (!lua_interface)
  4445. return 0;
  4446. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4447. Spawn* player = lua_interface->GetSpawn(state, 2);
  4448. string window_title = lua_interface->GetStringValue(state, 3);
  4449. string cancel_command = lua_interface->GetStringValue(state, 4);
  4450. Client* client = player->GetZone()->GetClientBySpawn(player);
  4451. if (option_window && window_title.length() > 0 && client) {
  4452. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4453. if (!packet)
  4454. return 0;
  4455. packet->setDataByName("title_text", window_title.c_str());
  4456. if (cancel_command.length() > 0)
  4457. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4458. packet->setArrayLengthByName("num_selections", option_window->size());
  4459. vector<OptionWindowOption>::iterator itr;
  4460. int8 i = 0;
  4461. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4462. OptionWindowOption opt = *itr;
  4463. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4464. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4465. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4466. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4467. if (opt.optionCommand.length() > 0)
  4468. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4469. if (opt.optionConfirmTitle.length() > 0)
  4470. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4471. i++;
  4472. }
  4473. client->QueuePacket(packet->serialize());
  4474. safe_delete(option_window);
  4475. safe_delete(packet);
  4476. }
  4477. return 0;
  4478. }
  4479. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4480. if (!lua_interface)
  4481. return 0;
  4482. Spawn* spawn = lua_interface->GetSpawn(state);
  4483. if (spawn) {
  4484. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4485. return 1;
  4486. }
  4487. else
  4488. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4489. return 0;
  4490. }
  4491. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4492. if (!lua_interface)
  4493. return 0;
  4494. Spawn* spawn = lua_interface->GetSpawn(state);
  4495. if (spawn) {
  4496. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4497. return 1;
  4498. }
  4499. else
  4500. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4501. return 0;
  4502. }
  4503. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4504. if (!lua_interface)
  4505. return 0;
  4506. Spawn* spawn = lua_interface->GetSpawn(state);
  4507. if (spawn) {
  4508. int8 class_id = spawn->GetTradeskillClass();
  4509. // Need to add 42 for the offset in the array
  4510. class_id += 44;
  4511. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4512. return 1;
  4513. }
  4514. else
  4515. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4516. return 0;
  4517. }
  4518. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4519. if (!lua_interface)
  4520. return 0;
  4521. Spawn* spawn = lua_interface->GetSpawn(state);
  4522. int16 level = lua_interface->GetInt8Value(state, 2);
  4523. if (spawn) {
  4524. if (spawn->IsPlayer())
  4525. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4526. else
  4527. spawn->SetTSLevel(level);
  4528. }
  4529. else
  4530. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4531. return 0;
  4532. }
  4533. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4534. if (!lua_interface)
  4535. return 0;
  4536. Spawn* spawn = lua_interface->GetSpawn(state);
  4537. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4538. if (spawn) {
  4539. spawn->SetAttackable(attackable);
  4540. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4541. }
  4542. return 0;
  4543. }
  4544. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4545. // Check to see if we have a valid lua_interface
  4546. if (!lua_interface)
  4547. return 0;
  4548. // Get the spawn that is getting the pet
  4549. Spawn* spawn = lua_interface->GetSpawn(state);
  4550. // Get the DB ID of the pet
  4551. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4552. // The max level the pet can gain
  4553. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4554. // Get the spell that this command was called from
  4555. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4556. // Check to make sure the spawn pointer is valid
  4557. if (!spawn) {
  4558. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4559. return 0;
  4560. }
  4561. // Check to make sure the spawn is an entity
  4562. if (!spawn->IsEntity()) {
  4563. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4564. return 0;
  4565. }
  4566. // Check to make sure the spawn doesn't already have a pet of this type
  4567. if (((Entity*)spawn)->GetPet()) {
  4568. if (spawn->IsPlayer()) {
  4569. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4570. if (client)
  4571. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4572. }
  4573. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4574. return 0;
  4575. }
  4576. // Check to see if the DB ID for the pet is set
  4577. if (pet_id == 0) {
  4578. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4579. return 0;
  4580. }
  4581. // Check to see if the pointer to the spell is valid
  4582. if (!luaspell) {
  4583. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4584. return 0;
  4585. }
  4586. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4587. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4588. if (!pet) {
  4589. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4590. return 0;
  4591. }
  4592. // Check to make sure the pet is an npc
  4593. if (!pet->IsNPC()) {
  4594. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4595. return 0;
  4596. }
  4597. // Spawn the pet at the same location as the owner
  4598. pet->SetX(spawn->GetX());
  4599. pet->SetY(spawn->GetY());
  4600. pet->SetZ(spawn->GetZ());
  4601. pet->SetLocation(spawn->GetLocation());
  4602. pet->SetHeading(spawn->GetHeading());
  4603. spawn->GetZone()->AddSpawn(pet);
  4604. /*
  4605. const char* spawn_script = world.GetSpawnScript(pet_id);
  4606. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4607. spawn->SetSpawnScript(string(spawn_script));
  4608. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4609. }*/
  4610. // Get a random pet name
  4611. string random_pet_name;
  4612. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4613. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4614. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4615. // If player set various values for the char sheet (pet window)
  4616. if (spawn->IsPlayer()) {
  4617. Player* player = (Player*)spawn;
  4618. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4619. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4620. player->GetInfoStruct()->set_pet_movement(2);
  4621. player->GetInfoStruct()->set_pet_behavior(3);
  4622. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4623. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4624. // Make sure the values get sent to the client
  4625. player->SetCharSheetChanged(true);
  4626. }
  4627. // Set the pets name
  4628. pet->SetName(random_pet_name.c_str());
  4629. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4630. if (max_level > 0)
  4631. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4632. else
  4633. pet->SetLevel(spawn->GetLevel());
  4634. // Set the max level this pet can reach
  4635. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4636. // Set the faction of the pet to the same faction as the owner
  4637. pet->SetFactionID(spawn->GetFactionID());
  4638. // Set the spawn as a pet
  4639. pet->SetPet(true);
  4640. // Give a pointer of the owner to the pet
  4641. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4642. // Give a pointer of the pet to the owner
  4643. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4644. // Set the pet type
  4645. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4646. // Set the spell id used to create this pet
  4647. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4648. // Set the spell tier used to create this pet
  4649. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4650. // Set the pets spawn type to 6
  4651. pet->SetSpawnType(6);
  4652. // Set the pets brain
  4653. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4654. // Check to see if the pet has a subtitle
  4655. if (strlen(pet->GetSubTitle()) > 0) {
  4656. // Add the players name to the front of the sub title
  4657. string pet_subtitle;
  4658. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4659. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4660. // Set the pets subtitle to the new one
  4661. pet->SetSubTitle(pet_subtitle.c_str());
  4662. }
  4663. // Add the "Pet Options" entity command to the pet
  4664. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4665. // Set the pet as the return value for this function
  4666. lua_interface->SetSpawnValue(state, pet);
  4667. return 1;
  4668. }
  4669. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4670. if (!lua_interface)
  4671. return 0;
  4672. Spawn* spawn = lua_interface->GetSpawn(state);
  4673. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4674. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4675. if (!spawn) {
  4676. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4677. return 0;
  4678. }
  4679. if (!spawn->IsEntity()) {
  4680. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4681. return 0;
  4682. }
  4683. if (((Entity*)spawn)->GetDeityPet()) {
  4684. if (spawn->IsPlayer()) {
  4685. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4686. if (client)
  4687. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4688. }
  4689. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4690. return 0;
  4691. }
  4692. if (pet_id == 0) {
  4693. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4694. return 0;
  4695. }
  4696. if (!luaspell) {
  4697. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4698. return 0;
  4699. }
  4700. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4701. if (!pet) {
  4702. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4703. return 0;
  4704. }
  4705. if (!pet->IsNPC()) {
  4706. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4707. return 0;
  4708. }
  4709. pet->SetX(spawn->GetX());
  4710. pet->SetY(spawn->GetY());
  4711. pet->SetZ(spawn->GetZ());
  4712. pet->SetLocation(spawn->GetLocation());
  4713. pet->SetHeading(spawn->GetHeading());
  4714. spawn->GetZone()->AddSpawn(pet);
  4715. string random_pet_name;
  4716. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4717. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4718. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4719. pet->SetName(random_pet_name.c_str());
  4720. pet->SetLevel(spawn->GetLevel());
  4721. pet->SetFactionID(spawn->GetFactionID());
  4722. pet->SetPet(true);
  4723. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4724. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4725. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4726. pet->SetSpawnType(6);
  4727. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4728. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4729. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4730. if (strlen(pet->GetSubTitle()) > 0) {
  4731. string pet_subtitle;
  4732. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4733. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4734. pet->SetSubTitle(pet_subtitle.c_str());
  4735. }
  4736. // deity and cosmetic pets are not attackable
  4737. pet->SetAttackable(false);
  4738. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4739. lua_interface->SetSpawnValue(state, pet);
  4740. return 1;
  4741. }
  4742. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4743. if (!lua_interface)
  4744. return 0;
  4745. Spawn* spawn = lua_interface->GetSpawn(state);
  4746. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4747. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4748. if (!spawn) {
  4749. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4750. return 0;
  4751. }
  4752. if (!spawn->IsEntity()) {
  4753. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4754. return 0;
  4755. }
  4756. if (((Entity*)spawn)->GetCosmeticPet()) {
  4757. if (spawn->IsPlayer()) {
  4758. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4759. if (client)
  4760. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4761. }
  4762. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4763. return 0;
  4764. }
  4765. if (pet_id == 0) {
  4766. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4767. return 0;
  4768. }
  4769. if (!luaspell) {
  4770. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4771. return 0;
  4772. }
  4773. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4774. if (!pet) {
  4775. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4776. return 0;
  4777. }
  4778. if (!pet->IsNPC()) {
  4779. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4780. return 0;
  4781. }
  4782. pet->SetX(spawn->GetX());
  4783. pet->SetY(spawn->GetY());
  4784. pet->SetZ(spawn->GetZ());
  4785. pet->SetLocation(spawn->GetLocation());
  4786. pet->SetHeading(spawn->GetHeading());
  4787. spawn->GetZone()->AddSpawn(pet);
  4788. string random_pet_name;
  4789. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4790. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4791. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4792. pet->SetName(random_pet_name.c_str());
  4793. pet->SetLevel(spawn->GetLevel());
  4794. pet->SetFactionID(spawn->GetFactionID());
  4795. pet->SetPet(true);
  4796. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4797. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4798. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4799. pet->SetSpawnType(6);
  4800. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4801. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4802. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4803. if (strlen(pet->GetSubTitle()) > 0) {
  4804. string pet_subtitle;
  4805. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4806. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4807. pet->SetSubTitle(pet_subtitle.c_str());
  4808. }
  4809. pet->SetAttackable(false);
  4810. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4811. lua_interface->SetSpawnValue(state, pet);
  4812. return 1;
  4813. }
  4814. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4815. if (!lua_interface)
  4816. return 0;
  4817. Spawn* spawn = lua_interface->GetSpawn(state);
  4818. if (!spawn) {
  4819. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4820. return 0;
  4821. }
  4822. if (!spawn->IsPet()) {
  4823. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4824. return 0;
  4825. }
  4826. if (!((NPC*)spawn)->IsDismissing())
  4827. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4828. return 0;
  4829. }
  4830. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4831. if (!lua_interface)
  4832. return 0;
  4833. Quest* quest = lua_interface->GetQuest(state);
  4834. if (!quest) {
  4835. 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));
  4836. return 0;
  4837. }
  4838. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4839. if (feather_color > 0)
  4840. quest->SetFeatherColor(feather_color);
  4841. return 0;
  4842. }
  4843. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4844. if (!lua_interface)
  4845. return 0;
  4846. Spawn* spawn = lua_interface->GetSpawn(state);
  4847. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4848. if (!spawn) {
  4849. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4850. return 0;
  4851. }
  4852. if (!spawn2) {
  4853. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4854. return 0;
  4855. }
  4856. spawn->RemoveSpawnAccess(spawn2);
  4857. return 0;
  4858. }
  4859. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4860. if (!lua_interface)
  4861. return 0;
  4862. ZoneServer* zone = lua_interface->GetZone(state);
  4863. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4864. if (!zone) {
  4865. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4866. return 0;
  4867. }
  4868. if (location_id == 0) {
  4869. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4870. return 0;
  4871. }
  4872. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4873. if (!location) {
  4874. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4875. return 0;
  4876. }
  4877. Spawn* spawn = 0;
  4878. if (location->entities[0]) {
  4879. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4880. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4881. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4882. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4883. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4884. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4885. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4886. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4887. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4888. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4889. if(spawn && spawn->IsOmittedByDBFlag())
  4890. {
  4891. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  4892. safe_delete(spawn);
  4893. spawn = 0;
  4894. return 0;
  4895. }
  4896. if (spawn) {
  4897. const char* script = 0;
  4898. for (int x = 0; x < 3; x++) {
  4899. switch (x) {
  4900. case 0:
  4901. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4902. break;
  4903. case 1:
  4904. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4905. break;
  4906. case 2:
  4907. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4908. break;
  4909. }
  4910. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4911. spawn->SetSpawnScript(string(script));
  4912. break;
  4913. }
  4914. }
  4915. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4916. lua_interface->SetSpawnValue(state, spawn);
  4917. return 1;
  4918. }
  4919. else {
  4920. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  4921. safe_delete(spawn);
  4922. }
  4923. }
  4924. return 0;
  4925. }
  4926. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4927. if (!lua_interface)
  4928. return 0;
  4929. Spawn* caster = lua_interface->GetSpawn(state);
  4930. Spawn* target = lua_interface->GetSpawn(state, 2);
  4931. int32 id = lua_interface->GetInt32Value(state, 3);
  4932. string command = lua_interface->GetStringValue(state, 4);
  4933. if (!caster) {
  4934. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4935. return 0;
  4936. }
  4937. if (!target) {
  4938. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4939. return 0;
  4940. }
  4941. if (!caster->IsPlayer()) {
  4942. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4943. return 0;
  4944. }
  4945. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4946. if (!entity_command) {
  4947. 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());
  4948. return 0;
  4949. }
  4950. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4951. if (!client) {
  4952. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4953. return 0;
  4954. }
  4955. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4956. return 0;
  4957. }
  4958. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4959. if (!lua_interface)
  4960. return 0;
  4961. Spawn* spawn = lua_interface->GetSpawn(state);
  4962. if (!spawn) {
  4963. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4964. return 0;
  4965. }
  4966. if (!spawn->IsNPC()) {
  4967. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4968. return 0;
  4969. }
  4970. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4971. return 0;
  4972. }
  4973. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4974. if (!lua_interface)
  4975. return 0;
  4976. Spawn* spawn = lua_interface->GetSpawn(state);
  4977. int16 tick = lua_interface->GetInt16Value(state, 2);
  4978. if (!spawn) {
  4979. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4980. return 0;
  4981. }
  4982. if (!spawn->IsNPC()) {
  4983. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4984. return 0;
  4985. }
  4986. if (tick < 20) {
  4987. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4988. return 0;
  4989. }
  4990. ((NPC*)spawn)->Brain()->SetTick(tick);
  4991. return 0;
  4992. }
  4993. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4994. if (!lua_interface)
  4995. return 0;
  4996. Spawn* spawn = lua_interface->GetSpawn(state);
  4997. Spawn* target = lua_interface->GetSpawn(state, 2);
  4998. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4999. if (!spawn) {
  5000. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5001. return 0;
  5002. }
  5003. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5004. spawn->SetFollowTarget(target, follow_distance);
  5005. return 0;
  5006. }
  5007. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5008. if (!lua_interface)
  5009. return 0;
  5010. Spawn* spawn = lua_interface->GetSpawn(state);
  5011. if (!spawn) {
  5012. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5013. return 0;
  5014. }
  5015. Spawn* target = spawn->GetFollowTarget();
  5016. if (target) {
  5017. lua_interface->SetSpawnValue(state, target);
  5018. return 1;
  5019. }
  5020. return 0;
  5021. }
  5022. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5023. if (!lua_interface)
  5024. return 0;
  5025. Spawn* spawn = lua_interface->GetSpawn(state);
  5026. if (!spawn) {
  5027. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5028. return 0;
  5029. }
  5030. if (spawn->following)
  5031. spawn->following = false;
  5032. else
  5033. spawn->following = true;
  5034. return 0;
  5035. }
  5036. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5037. if (!lua_interface)
  5038. return 0;
  5039. Spawn* spawn = lua_interface->GetSpawn(state);
  5040. if (!spawn) {
  5041. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5042. return 0;
  5043. }
  5044. lua_interface->SetBooleanValue(state, spawn->following);
  5045. return 1;
  5046. }
  5047. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5048. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5049. // I will attempt to explain how this function works for future refrence
  5050. // Fist lets make sure lua_interface is valid, if not return out
  5051. if (!lua_interface)
  5052. return 0;
  5053. // Next we grab the first 2 params same as we usually would
  5054. Spawn* spawn = lua_interface->GetSpawn(state);
  5055. string var = lua_interface->GetStringValue(state, 2);
  5056. // 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
  5057. // 1 = Spawn
  5058. // 2 = Zone
  5059. // 3 = Item
  5060. // 4 = Quest
  5061. // 5 = String
  5062. // 6 = nil (null)
  5063. int8 dataType = 0;
  5064. // Define pointers for each potential type
  5065. Spawn* spawnVal = 0;
  5066. ZoneServer* zone = 0;
  5067. Item* item = 0;
  5068. Quest* quest = 0;
  5069. string val;
  5070. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5071. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5072. // options window are also light user data be we do not handle those.
  5073. // We check with lua_islightuserdata(lua_State*, index)
  5074. if (lua_islightuserdata(state, 3)) {
  5075. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5076. // and convert it to LUAUserData*
  5077. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5078. // Check to make sure the data we got is valid, if not give an error
  5079. if (!data || !data->IsCorrectlyInitialized()) {
  5080. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5081. }
  5082. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5083. else if (data->IsSpawn()) {
  5084. spawnVal = data->spawn;
  5085. dataType = 1;
  5086. }
  5087. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5088. else if (data->IsZone()) {
  5089. zone = data->zone;
  5090. dataType = 2;
  5091. }
  5092. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5093. else if (data->IsItem()) {
  5094. item = data->item;
  5095. dataType = 3;
  5096. }
  5097. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5098. else if (data->IsQuest()) {
  5099. quest = data->quest;
  5100. dataType = 4;
  5101. }
  5102. }
  5103. // Wasn't light user data, check if it is nil(null)
  5104. else if (lua_isnil(state, 3)) {
  5105. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5106. dataType = 6;
  5107. }
  5108. // Wasn't light user data or nil (null), must be a string
  5109. else {
  5110. // Set the string and dataType variable
  5111. val = lua_interface->GetStringValue(state, 3);
  5112. dataType = 5;
  5113. }
  5114. // We now have all the params, lets check to make sure they are valid
  5115. if (!spawn) {
  5116. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5117. return 0;
  5118. }
  5119. if (var.length() == 0) {
  5120. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5121. return 0;
  5122. }
  5123. if (dataType == 0) {
  5124. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5125. return 0;
  5126. }
  5127. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5128. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5129. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5130. switch (dataType) {
  5131. case 1:
  5132. // 1 = Spawn
  5133. spawn->AddTempVariable(var, spawnVal);
  5134. break;
  5135. case 2:
  5136. // 2 = Zone
  5137. spawn->AddTempVariable(var, zone);
  5138. break;
  5139. case 3:
  5140. // 3 = Item
  5141. spawn->AddTempVariable(var, item);
  5142. break;
  5143. case 4:
  5144. // 4 = Quest
  5145. spawn->AddTempVariable(var, quest);
  5146. break;
  5147. case 5:
  5148. // 5 = String
  5149. spawn->AddTempVariable(var, val);
  5150. break;
  5151. case 6:
  5152. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5153. spawn->DeleteTempVariable(var);
  5154. break;
  5155. }
  5156. // And we are done so return out
  5157. return 0;
  5158. }
  5159. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5160. if (!lua_interface)
  5161. return 0;
  5162. Spawn* spawn = lua_interface->GetSpawn(state);
  5163. string var = lua_interface->GetStringValue(state, 2);
  5164. if (!spawn) {
  5165. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. if (var.length() == 0) {
  5169. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5170. return 0;
  5171. }
  5172. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5173. int8 type = spawn->GetTempVariableType(var);
  5174. Spawn* spawn2 = 0;
  5175. ZoneServer* zone = 0;
  5176. Item* item = 0;
  5177. Quest* quest = 0;
  5178. // Set the lua function return value based on the type of data the variable contains
  5179. switch (type) {
  5180. case 1:
  5181. spawn2 = spawn->GetTempVariableSpawn(var);
  5182. if (!spawn2)
  5183. return 0;
  5184. lua_interface->SetSpawnValue(state, spawn2);
  5185. break;
  5186. case 2:
  5187. zone = spawn->GetTempVariableZone(var);
  5188. if (!zone)
  5189. return 0;
  5190. lua_interface->SetZoneValue(state, zone);
  5191. break;
  5192. case 3:
  5193. item = spawn->GetTempVariableItem(var);
  5194. if (!item)
  5195. return 0;
  5196. lua_interface->SetItemValue(state, item);
  5197. break;
  5198. case 4:
  5199. quest = spawn->GetTempVariableQuest(var);
  5200. if (!quest)
  5201. return 0;
  5202. lua_interface->SetQuestValue(state, quest);
  5203. break;
  5204. case 5:
  5205. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5206. break;
  5207. default:
  5208. // Not a valid type then the variable was not set so return out
  5209. return 0;
  5210. }
  5211. // Return value was set so return out
  5212. return 1;
  5213. }
  5214. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5215. {
  5216. if (!lua_interface)
  5217. return 0;
  5218. Quest* quest = lua_interface->GetQuest(state);
  5219. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5220. string description = lua_interface->GetStringValue(state, 3);
  5221. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5222. if (!quest) {
  5223. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5224. lua_interface->SetBooleanValue(state, false);
  5225. return 1;
  5226. }
  5227. if (!spawn) {
  5228. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5229. lua_interface->SetBooleanValue(state, false);
  5230. return 1;
  5231. }
  5232. if (!spawn->IsPlayer()) {
  5233. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5234. lua_interface->SetBooleanValue(state, false);
  5235. return 1;
  5236. }
  5237. if (item_id == 0) {
  5238. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5239. lua_interface->SetBooleanValue(state, false);
  5240. return 1;
  5241. }
  5242. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5243. if (!client) {
  5244. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5245. lua_interface->SetBooleanValue(state, false);
  5246. return 1;
  5247. }
  5248. Item* item = master_item_list.GetItem(item_id);
  5249. if (!item) {
  5250. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5251. lua_interface->SetBooleanValue(state, false);
  5252. return 1;
  5253. }
  5254. Item* firstItem = new Item(item);
  5255. quest->AddTmpRewardItem(firstItem);
  5256. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5257. bool itemsAddedSuccessfully = true;
  5258. if(num_args > 4)
  5259. {
  5260. for(int8 n=5;n<num_args+1;n++)
  5261. {
  5262. int32 new_item = lua_interface->GetInt32Value(state, n);
  5263. Item* tmpItem = master_item_list.GetItem(new_item);
  5264. if(tmpItem)
  5265. {
  5266. Item* newTmpItem = new Item(tmpItem);
  5267. quest->AddTmpRewardItem(newTmpItem);
  5268. }
  5269. else
  5270. itemsAddedSuccessfully = false;
  5271. }
  5272. }
  5273. client->AddPendingQuestAcceptReward(quest);
  5274. client->DisplayQuestComplete(quest, true, description);
  5275. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5276. return 1;
  5277. }
  5278. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5279. if (!lua_interface)
  5280. return 0;
  5281. Quest* quest = lua_interface->GetQuest(state);
  5282. if (!quest) {
  5283. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. quest->SetRepeatable(true);
  5287. return 0;
  5288. }
  5289. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5290. if (!lua_interface)
  5291. return 0;
  5292. Spawn* spawn = lua_interface->GetSpawn(state);
  5293. if (!spawn) {
  5294. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5295. return 0;
  5296. }
  5297. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5298. string ret = classes.GetClassNameCase(base_class);
  5299. if (ret.length() > 0) {
  5300. lua_interface->SetStringValue(state, ret.c_str());
  5301. return 1;
  5302. }
  5303. return 0;
  5304. }
  5305. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5306. if (!lua_interface)
  5307. return 0;
  5308. Spawn* player = lua_interface->GetSpawn(state);
  5309. if (player && player->IsPlayer()) {
  5310. Client* client = player->GetClient();
  5311. if (client)
  5312. client->SendWaypoints();
  5313. }
  5314. return 0;
  5315. }
  5316. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5317. if (!lua_interface)
  5318. return 0;
  5319. Spawn* player = lua_interface->GetSpawn(state);
  5320. string name = lua_interface->GetStringValue(state, 2);
  5321. int32 type = lua_interface->GetInt32Value(state, 3);
  5322. if (type == 0)
  5323. type = 2;
  5324. if (name.length() > 0) {
  5325. if (player && player->IsPlayer()) {
  5326. Client* client = player->GetClient();
  5327. if (client)
  5328. client->AddWaypoint(name, type);
  5329. }
  5330. }
  5331. return 0;
  5332. }
  5333. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. Spawn* player = lua_interface->GetSpawn(state);
  5337. string name = lua_interface->GetStringValue(state, 2);
  5338. if (name.length() > 0) {
  5339. if (player && player->IsPlayer()) {
  5340. Client* client = player->GetClient();
  5341. if (client)
  5342. client->RemoveWaypoint(name);
  5343. }
  5344. }
  5345. return 0;
  5346. }
  5347. int EQ2Emu_lua_AddWard(lua_State* state) {
  5348. if (!lua_interface)
  5349. return 0;
  5350. int32 damage = lua_interface->GetInt32Value(state);
  5351. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5352. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5353. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5354. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5355. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5356. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5357. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5358. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5359. bool ward_was_added = false;
  5360. ZoneServer* zone = spell->caster->GetZone();
  5361. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5362. for (int32 i = 0; i < spell->targets.size(); i++) {
  5363. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5364. if (!target)
  5365. continue;
  5366. if (target->IsEntity()) {
  5367. // If the ward is already active remove it
  5368. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5369. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5370. // Create new ward info
  5371. WardInfo* ward = new WardInfo;
  5372. ward->Spell = spell;
  5373. ward->BaseDamage = damage;
  5374. ward->DamageLeft = damage;
  5375. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5376. ward->keepWard = keepWard;
  5377. ward->WardType = wardType;
  5378. if (damageAbsorptionPercent > 100)
  5379. damageAbsorptionPercent = 100;
  5380. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5381. if (damageAbsorptionMaxHealthPercent > 100)
  5382. damageAbsorptionMaxHealthPercent = 100;
  5383. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5384. ward->RedirectDamagePercent = redirectDamagePercent;
  5385. ward->LastRedirectDamage = 0;
  5386. ward->LastAbsorbedDamage = 0;
  5387. ward->HitCount = 0;
  5388. spell->num_triggers = maxHitCount;
  5389. spell->had_triggers = true;
  5390. spell->cancel_after_all_triggers = false;
  5391. ward->MaxHitCount = maxHitCount;
  5392. if (wardType == WARD_TYPE_MAGICAL)
  5393. ward->DamageType = damageTypes;
  5394. // Add the ward to the entity
  5395. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5396. ward_was_added = true;
  5397. }
  5398. }
  5399. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5400. if (ward_was_added && spell->caster->IsPlayer()) {
  5401. spell->had_dmg_remaining = true;
  5402. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5403. }
  5404. return 0;
  5405. }
  5406. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5407. if (!lua_interface)
  5408. return 0;
  5409. int32 amount = lua_interface->GetInt32Value(state);
  5410. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5411. WardInfo* ward = 0;
  5412. ZoneServer* zone = spell->caster->GetZone();
  5413. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5414. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5415. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5416. ward = target->GetWard(spell->spell->GetSpellID());
  5417. if (target && ward) {
  5418. ward->DamageLeft += amount;
  5419. if (ward->DamageLeft > ward->BaseDamage)
  5420. ward->DamageLeft = ward->BaseDamage;
  5421. for (int32 i = 0; i < spell->targets.size(); i++) {
  5422. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5423. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5424. }
  5425. }
  5426. }
  5427. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5428. if (ward && spell->caster->IsPlayer())
  5429. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5430. return 0;
  5431. }
  5432. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5433. if (!lua_interface)
  5434. return 0;
  5435. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5436. if (!spell) {
  5437. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5438. return 0;
  5439. }
  5440. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5441. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5442. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5443. if (ward) {
  5444. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5445. return 1;
  5446. }
  5447. }
  5448. return 0;
  5449. }
  5450. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5451. if (!lua_interface)
  5452. return 0;
  5453. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5454. if (!spell) {
  5455. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5456. return 0;
  5457. }
  5458. string type = lua_interface->GetStringValue(state, 2);
  5459. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5460. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5461. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5462. if (ward) {
  5463. if (boost::iequals(type, "damageleft"))
  5464. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5465. else if (boost::iequals(type, "basedamage"))
  5466. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5467. else if (boost::iequals(type, "keepward"))
  5468. lua_interface->SetBooleanValue(state, ward->keepWard);
  5469. else if (boost::iequals(type, "wardtype"))
  5470. lua_interface->SetInt32Value(state, ward->WardType);
  5471. else if (boost::iequals(type, "dmgabsorptionpct"))
  5472. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5473. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5474. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5475. else if (boost::iequals(type, "redirectdamagepercent"))
  5476. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5477. else if (boost::iequals(type, "lastredirectdamage"))
  5478. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5479. else if (boost::iequals(type, "lastabsorbeddamage"))
  5480. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5481. else if (boost::iequals(type, "hitcount"))
  5482. lua_interface->SetInt32Value(state, ward->HitCount);
  5483. else if (boost::iequals(type, "maxhitcount"))
  5484. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5485. else
  5486. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5487. return 1;
  5488. }
  5489. }
  5490. return 0;
  5491. }
  5492. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5493. if (!lua_interface)
  5494. return 0;
  5495. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5496. ZoneServer* zone = spell->caster->GetZone();
  5497. Spawn* target = 0;
  5498. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5499. for (int32 i = 0; i < spell->targets.size(); i++) {
  5500. target = zone->GetSpawnByID(spell->targets.at(i));
  5501. if (target && target->IsEntity()) {
  5502. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5503. }
  5504. }
  5505. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5506. return 0;
  5507. }
  5508. int EQ2Emu_lua_Interrupt(lua_State* state)
  5509. {
  5510. if (!lua_interface)
  5511. return 0;
  5512. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5513. Spawn* target = lua_interface->GetSpawn(state, 2);
  5514. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5515. if (!caster)
  5516. {
  5517. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5518. return 0;
  5519. }
  5520. if (!target)
  5521. {
  5522. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5523. return 0;
  5524. }
  5525. if (!spell) {
  5526. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5527. return 0;
  5528. }
  5529. if (!target->IsEntity() && !spell)
  5530. {
  5531. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5532. return 0;
  5533. }
  5534. if (!target && spell) {
  5535. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5536. for (int8 i = 0; i < spell->targets.size(); i++) {
  5537. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5538. if (!target || !target->IsEntity())
  5539. continue;
  5540. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5541. }
  5542. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5543. }
  5544. else
  5545. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5546. return 0;
  5547. }
  5548. int EQ2Emu_lua_Stealth(lua_State* state) {
  5549. if (!lua_interface)
  5550. return 0;
  5551. int8 type = lua_interface->GetInt8Value(state);
  5552. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5553. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5554. if (!spell) {
  5555. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5556. return 0;
  5557. }
  5558. ZoneServer* zone = spell->caster->GetZone();
  5559. if (spawn) {
  5560. if (spawn->IsEntity()) {
  5561. if (type == 1) {
  5562. ((Entity*)spawn)->AddStealthSpell(spell);
  5563. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5564. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5565. }
  5566. else if (type == 2) {
  5567. ((Entity*)spawn)->AddInvisSpell(spell);
  5568. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5569. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5570. }
  5571. return 0;
  5572. }
  5573. else {
  5574. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5575. return 0;
  5576. }
  5577. }
  5578. else {
  5579. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5580. for (int32 i = 0; i < spell->targets.size(); i++) {
  5581. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5582. if (!spawn || !spawn->IsEntity())
  5583. continue;
  5584. if (type == 1) {
  5585. ((Entity*)spawn)->AddStealthSpell(spell);
  5586. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5587. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5588. }
  5589. else if (type == 2) {
  5590. ((Entity*)spawn)->AddInvisSpell(spell);
  5591. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5592. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5593. }
  5594. else {
  5595. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5596. break;
  5597. }
  5598. }
  5599. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5600. }
  5601. return 0;
  5602. }
  5603. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5604. if (!lua_interface)
  5605. return 0;
  5606. Spawn* spawn = lua_interface->GetSpawn(state);
  5607. if (!spawn) {
  5608. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5609. return 0;
  5610. }
  5611. if (spawn->IsEntity()) {
  5612. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5613. return 1;
  5614. }
  5615. else
  5616. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5617. return 0;
  5618. }
  5619. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5620. if (!lua_interface)
  5621. return 0;
  5622. Spawn* spawn = lua_interface->GetSpawn(state);
  5623. if (!spawn) {
  5624. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5625. return 0;
  5626. }
  5627. if (spawn->IsEntity()) {
  5628. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5629. return 1;
  5630. }
  5631. else
  5632. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5633. return 0;
  5634. }
  5635. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5636. if (!lua_interface)
  5637. return 0;
  5638. Spawn* player = lua_interface->GetSpawn(state);
  5639. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5640. lua_interface->ResetFunctionStack(state);
  5641. if (!player->IsPlayer()) {
  5642. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5643. return 0;
  5644. }
  5645. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5646. return 1;
  5647. }
  5648. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5649. if (!lua_interface)
  5650. return 0;
  5651. Spawn* player = lua_interface->GetSpawn(state);
  5652. int8 slot = lua_interface->GetInt8Value(state, 2);
  5653. lua_interface->ResetFunctionStack(state);
  5654. if (!player) {
  5655. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5656. return 0;
  5657. }
  5658. if (!player->IsPlayer()) {
  5659. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5660. return 0;
  5661. }
  5662. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5663. if (!item) {
  5664. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5665. return 0;
  5666. }
  5667. lua_interface->SetItemValue(state, item);
  5668. return 1;
  5669. }
  5670. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5671. if (!lua_interface)
  5672. return 0;
  5673. Spawn* player = lua_interface->GetSpawn(state);
  5674. int32 id = lua_interface->GetInt32Value(state, 2);
  5675. lua_interface->ResetFunctionStack(state);
  5676. if (!player) {
  5677. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5678. return 0;
  5679. }
  5680. if (!player->IsPlayer()) {
  5681. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5682. return 0;
  5683. }
  5684. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5685. if (!item) {
  5686. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5687. return 0;
  5688. }
  5689. lua_interface->SetItemValue(state, item);
  5690. return 1;
  5691. }
  5692. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5693. if (!lua_interface)
  5694. return 0;
  5695. Spawn* spawn = lua_interface->GetSpawn(state);
  5696. int8 slot = lua_interface->GetInt8Value(state, 2);
  5697. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5698. lua_interface->ResetFunctionStack(state);
  5699. if (!spawn) {
  5700. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. if (!spawn->IsEntity()) {
  5704. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5705. return 0;
  5706. }
  5707. Item* item = master_item_list.GetItem(item_id);
  5708. if (!item) {
  5709. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5710. return 0;
  5711. }
  5712. Item* copy = new Item(item);
  5713. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5714. if(result)
  5715. {
  5716. ((Entity*)spawn)->SetEquipment(copy, slot);
  5717. spawn->vis_changed = true;
  5718. if(spawn->IsPlayer())
  5719. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5720. }
  5721. else
  5722. {
  5723. safe_delete(copy);
  5724. }
  5725. lua_interface->SetBooleanValue(state, result);
  5726. return 1;
  5727. }
  5728. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5729. if (!lua_interface)
  5730. return 0;
  5731. Spawn* spawn = lua_interface->GetSpawn(state);
  5732. int8 slot = lua_interface->GetInt8Value(state, 2);
  5733. Item* item = lua_interface->GetItem(state, 3);
  5734. lua_interface->ResetFunctionStack(state);
  5735. if (!spawn) {
  5736. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5737. return 0;
  5738. }
  5739. if (!spawn->IsEntity()) {
  5740. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5741. return 0;
  5742. }
  5743. if (!item) {
  5744. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5745. return 0;
  5746. }
  5747. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5748. if(result)
  5749. {
  5750. ((Entity*)spawn)->SetEquipment(item, slot);
  5751. spawn->vis_changed = true;
  5752. if(spawn->IsPlayer())
  5753. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5754. }
  5755. lua_interface->SetBooleanValue(state, result);
  5756. return 1;
  5757. }
  5758. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5759. if (!lua_interface)
  5760. return 0;
  5761. Spawn* spawn = lua_interface->GetSpawn(state);
  5762. int8 slot = lua_interface->GetInt8Value(state, 2);
  5763. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5764. lua_interface->ResetFunctionStack(state);
  5765. if (!spawn) {
  5766. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. if (!spawn->IsEntity()) {
  5770. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5771. return 0;
  5772. }
  5773. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5774. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5775. spawn->vis_changed = true;
  5776. if(spawn->IsPlayer())
  5777. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5778. lua_interface->SetBooleanValue(state, true);
  5779. return 1;
  5780. }
  5781. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5782. if (!lua_interface)
  5783. return 0;
  5784. Spawn* spawn = lua_interface->GetSpawn(state);
  5785. int8 slot = lua_interface->GetInt8Value(state, 2);
  5786. int16 type = lua_interface->GetInt16Value(state, 3);
  5787. int8 r = lua_interface->GetInt8Value(state, 4);
  5788. int8 g = lua_interface->GetInt8Value(state, 5);
  5789. int8 b = lua_interface->GetInt8Value(state, 6);
  5790. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5791. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5792. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5793. lua_interface->ResetFunctionStack(state);
  5794. if (!spawn) {
  5795. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5796. return 0;
  5797. }
  5798. if (!spawn->IsEntity()) {
  5799. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5800. return 0;
  5801. }
  5802. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5803. spawn->vis_changed = true;
  5804. lua_interface->SetBooleanValue(state, true);
  5805. return 1;
  5806. }
  5807. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5808. if (!lua_interface)
  5809. return 0;
  5810. Spawn* player = lua_interface->GetSpawn(state);
  5811. int32 id = lua_interface->GetInt32Value(state, 2);
  5812. int8 count = lua_interface->GetInt8Value(state, 3);
  5813. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5814. lua_interface->ResetFunctionStack(state);
  5815. if (!player) {
  5816. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5817. return 0;
  5818. }
  5819. if (!player->IsPlayer()) {
  5820. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5821. return 0;
  5822. }
  5823. if (!count)
  5824. count = 1;
  5825. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5826. if (!item) {
  5827. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5828. return 0;
  5829. }
  5830. lua_interface->SetItemValue(state, item);
  5831. return 1;
  5832. }
  5833. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5834. if (!lua_interface)
  5835. return 0;
  5836. Spawn* spawn = lua_interface->GetSpawn(state);
  5837. int32 anim = lua_interface->GetInt32Value(state, 2);
  5838. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5839. int8 type = lua_interface->GetInt8Value(state, 4);
  5840. if (!spawn) {
  5841. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5842. return 0;
  5843. }
  5844. if (spawn2) {
  5845. if (spawn2->IsPlayer()) {
  5846. if (type != 1 && type != 2)
  5847. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5848. else
  5849. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5850. return 0;
  5851. }
  5852. else {
  5853. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. }
  5857. else
  5858. spawn->GetZone()->PlayAnimation(spawn, anim);
  5859. return 0;
  5860. }
  5861. int EQ2Emu_lua_IsPet(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. Spawn* spawn = lua_interface->GetSpawn(state);
  5865. if (!spawn) {
  5866. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5870. return 1;
  5871. }
  5872. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5873. if (!lua_interface)
  5874. return 0;
  5875. Spawn* spawn = lua_interface->GetSpawn(state);
  5876. if (!spawn) {
  5877. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5878. return 0;
  5879. }
  5880. if (!spawn->IsNPC()) {
  5881. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5882. return 0;
  5883. }
  5884. if (((NPC*)spawn)->GetOwner()) {
  5885. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5886. return 1;
  5887. }
  5888. return 0;
  5889. }
  5890. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5891. if (!lua_interface)
  5892. return 0;
  5893. Spawn* spawn = lua_interface->GetSpawn(state);
  5894. Spawn* target = lua_interface->GetSpawn(state, 2);
  5895. if (!spawn) {
  5896. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. if (!spawn) {
  5900. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5901. return 0;
  5902. }
  5903. spawn->SetTarget(target);
  5904. return 0;
  5905. }
  5906. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5907. if (!lua_interface)
  5908. return 0;
  5909. Spawn* spawn = lua_interface->GetSpawn(state);
  5910. bool val = lua_interface->GetBooleanValue(state, 2);
  5911. if (!spawn) {
  5912. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. if (!spawn->IsEntity()) {
  5916. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5917. return 0;
  5918. }
  5919. ((Entity*)spawn)->InCombat(val);
  5920. if (val) {
  5921. spawn->ClearRunningLocations();
  5922. spawn->CalculateRunningLocation(true);
  5923. }
  5924. return 0;
  5925. }
  5926. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5927. if (!lua_interface)
  5928. return 0;
  5929. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5930. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5931. if (!spawn1) {
  5932. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5933. return 0;
  5934. }
  5935. if (!spawn2) {
  5936. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5937. return 0;
  5938. }
  5939. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5940. return 1;
  5941. }
  5942. int EQ2Emu_lua_Runback(lua_State* state) {
  5943. if (!lua_interface)
  5944. return 0;
  5945. Spawn* spawn = lua_interface->GetSpawn(state);
  5946. if (!spawn) {
  5947. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5948. return 0;
  5949. }
  5950. if (!spawn->IsNPC()) {
  5951. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5952. return 0;
  5953. }
  5954. ((NPC*)spawn)->Runback();
  5955. return 0;
  5956. }
  5957. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5958. if (!lua_interface)
  5959. return 0;
  5960. Spawn* spawn = lua_interface->GetSpawn(state);
  5961. if (!spawn) {
  5962. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5963. return 0;
  5964. }
  5965. if (!spawn->IsNPC()) {
  5966. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5970. return 1;
  5971. }
  5972. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5973. if (!lua_interface)
  5974. return 0;
  5975. Spawn* spawn = lua_interface->GetSpawn(state);
  5976. if (!spawn) {
  5977. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. if (!spawn->IsEntity()) {
  5981. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5982. return 0;
  5983. }
  5984. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5985. return 1;
  5986. }
  5987. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5988. if (!lua_interface)
  5989. return 0;
  5990. Spawn* spawn = lua_interface->GetSpawn(state);
  5991. if (!spawn) {
  5992. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5993. return 0;
  5994. }
  5995. if (!spawn->IsEntity()) {
  5996. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5997. return 0;
  5998. }
  5999. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6000. return 1;
  6001. }
  6002. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6003. if (!lua_interface)
  6004. return 0;
  6005. Spawn* spawn = lua_interface->GetSpawn(state);
  6006. if (!spawn) {
  6007. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6008. return 0;
  6009. }
  6010. if (!spawn->IsEntity()) {
  6011. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6012. return 0;
  6013. }
  6014. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6015. return 1;
  6016. }
  6017. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6018. if (!lua_interface)
  6019. return 0;
  6020. Spawn* spawn = lua_interface->GetSpawn(state);
  6021. if (!spawn) {
  6022. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. if (!spawn->IsEntity()) {
  6026. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6027. return 0;
  6028. }
  6029. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6030. return 1;
  6031. }
  6032. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6033. if (!lua_interface)
  6034. return 0;
  6035. Spawn* spawn = lua_interface->GetSpawn(state);
  6036. Spawn* target = lua_interface->GetSpawn(state, 2);
  6037. float distance = lua_interface->GetFloatValue(state, 3);
  6038. if (!spawn) {
  6039. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6040. return 0;
  6041. }
  6042. if (!target) {
  6043. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6044. return 0;
  6045. }
  6046. if (!spawn->IsNPC()) {
  6047. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6048. return 0;
  6049. }
  6050. if (!target->IsEntity()) {
  6051. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6052. return 0;
  6053. }
  6054. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6055. return 1;
  6056. }
  6057. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. Spawn* spawn = lua_interface->GetSpawn(state);
  6061. Spawn* target = lua_interface->GetSpawn(state, 2);
  6062. float distance = lua_interface->GetFloatValue(state, 3);
  6063. if (!spawn) {
  6064. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. if (!target) {
  6068. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6069. return 0;
  6070. }
  6071. if (!spawn->IsNPC()) {
  6072. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. if (!target->IsEntity()) {
  6076. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6077. return 0;
  6078. }
  6079. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6080. return 0;
  6081. }
  6082. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6083. if (!lua_interface)
  6084. return 0;
  6085. Spawn* spawn = lua_interface->GetSpawn(state);
  6086. if (!spawn) {
  6087. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6088. return 0;
  6089. }
  6090. if (!spawn->IsNPC()) {
  6091. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6092. return 0;
  6093. }
  6094. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6095. return 1;
  6096. }
  6097. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6098. if (!lua_interface)
  6099. return 0;
  6100. Spawn* spawn = lua_interface->GetSpawn(state);
  6101. if (!spawn) {
  6102. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6103. return 0;
  6104. }
  6105. if (!spawn->IsNPC()) {
  6106. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6107. return 0;
  6108. }
  6109. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6110. return 1;
  6111. }
  6112. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6113. if (!lua_interface)
  6114. return 0;
  6115. Spawn* spawn = lua_interface->GetSpawn(state);
  6116. if (!spawn) {
  6117. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6118. return 0;
  6119. }
  6120. if (!spawn->IsNPC()) {
  6121. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6122. return 0;
  6123. }
  6124. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6125. if (hated) {
  6126. lua_interface->SetSpawnValue(state, hated);
  6127. return 1;
  6128. }
  6129. return 0;
  6130. }
  6131. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6132. if (!lua_interface)
  6133. return 0;
  6134. Spawn* spawn = lua_interface->GetSpawn(state);
  6135. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6136. if (!spawn) {
  6137. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. if (!spawn->IsNPC()) {
  6141. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6142. return 0;
  6143. }
  6144. if (!hated) {
  6145. ((NPC*)spawn)->Brain()->ClearHate();
  6146. return 0;
  6147. }
  6148. else
  6149. {
  6150. if (!hated->IsEntity()) {
  6151. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6152. return 0;
  6153. }
  6154. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6155. return 0;
  6156. }
  6157. return 0;
  6158. }
  6159. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6160. if (!lua_interface)
  6161. return 0;
  6162. Spawn* spawn = lua_interface->GetSpawn(state);
  6163. if (!spawn) {
  6164. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6165. return 0;
  6166. }
  6167. if (!spawn->IsNPC()) {
  6168. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6169. return 0;
  6170. }
  6171. ((NPC*)spawn)->Brain()->ClearEncounter();
  6172. return 0;
  6173. }
  6174. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6175. if (!lua_interface)
  6176. return 0;
  6177. Spawn* spawn = lua_interface->GetSpawn(state);
  6178. if (!spawn) {
  6179. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. if (!spawn->IsNPC()) {
  6183. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6184. return 0;
  6185. }
  6186. // Temp list to store hate list
  6187. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6188. if (encounterList->size() == 0) {
  6189. safe_delete(encounterList);
  6190. return 0;
  6191. }
  6192. lua_createtable(state, encounterList->size(), 0);
  6193. int newTable = lua_gettop(state);
  6194. for (int32 i = 0; i < encounterList->size(); i++) {
  6195. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6196. if (temp)
  6197. lua_interface->SetSpawnValue(state, temp);
  6198. lua_rawseti(state, newTable, i + 1);
  6199. }
  6200. safe_delete(encounterList);
  6201. return 1;
  6202. }
  6203. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6204. if (!lua_interface)
  6205. return 0;
  6206. Spawn* spawn = lua_interface->GetSpawn(state);
  6207. if (!spawn) {
  6208. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6209. return 0;
  6210. }
  6211. if (!spawn->IsNPC()) {
  6212. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6213. return 0;
  6214. }
  6215. // Temp list to store hate list
  6216. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6217. if (hateList->size() == 0) {
  6218. safe_delete(hateList);
  6219. return 0;
  6220. }
  6221. lua_createtable(state, hateList->size(), 0);
  6222. int newTable = lua_gettop(state);
  6223. for (int32 i = 0; i < hateList->size(); i++) {
  6224. lua_interface->SetSpawnValue(state, hateList->at(i));
  6225. lua_rawseti(state, newTable, i + 1);
  6226. }
  6227. safe_delete(hateList);
  6228. return 1;
  6229. }
  6230. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6231. if (!lua_interface)
  6232. return 0;
  6233. Spawn* spawn = lua_interface->GetSpawn(state);
  6234. if (!spawn) {
  6235. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (spawn->IsPlayer()) {
  6239. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6240. lua_interface->SetBooleanValue(state, true);
  6241. else
  6242. lua_interface->SetBooleanValue(state, false);
  6243. return 1;
  6244. }
  6245. else {
  6246. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6247. return 1;
  6248. }
  6249. }
  6250. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6251. if (!lua_interface)
  6252. return 0;
  6253. Quest* quest = lua_interface->GetQuest(state);
  6254. if (!quest) {
  6255. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6256. return 0;
  6257. }
  6258. quest->SetCompletedFlag(true);
  6259. return 0;
  6260. }
  6261. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6262. if (!lua_interface)
  6263. return 0;
  6264. Spawn* spawn = lua_interface->GetSpawn(state);
  6265. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6266. int8 tier = lua_interface->GetInt8Value(state, 3);
  6267. if (!spawn) {
  6268. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6269. return 0;
  6270. }
  6271. if (!spawn->IsEntity()) {
  6272. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6273. return 0;
  6274. }
  6275. if (spellID == 0) {
  6276. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6277. return 0;
  6278. }
  6279. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6280. if (effect) {
  6281. if (tier > 0) {
  6282. // If a tier was passed chec to see if it is the same as the effect
  6283. if (tier == effect->tier)
  6284. lua_interface->SetBooleanValue(state, true);
  6285. else
  6286. lua_interface->SetBooleanValue(state, false);
  6287. return 1;
  6288. }
  6289. else {
  6290. // Have an effect but no tier was passed so return true
  6291. lua_interface->SetBooleanValue(state, true);
  6292. }
  6293. return 1;
  6294. }
  6295. // no effect so return false
  6296. lua_interface->SetBooleanValue(state, false);
  6297. return 1;
  6298. }
  6299. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6300. if (!lua_interface)
  6301. return 0;
  6302. Spawn* spawn = lua_interface->GetSpawn(state);
  6303. int32 id = lua_interface->GetInt32Value(state, 2);
  6304. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6305. Spawn* spawn2 = 0;
  6306. vector<Spawn*> list;
  6307. if (!spawn) {
  6308. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6309. return 0;
  6310. }
  6311. //If zone not provided, use spawn's zone
  6312. if (!zone)
  6313. zone = spawn->GetZone();
  6314. list = zone->GetSpawnsByID(id);
  6315. if (list.size() == 0) {
  6316. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. vector<Spawn*>::iterator itr = list.begin();
  6320. for (int8 i = 0; i < list.size(); i++) {
  6321. spawn2 = itr[i];
  6322. if (spawn2)
  6323. spawn2->AddAllowAccessSpawn(spawn);
  6324. }
  6325. return 0;
  6326. }
  6327. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6328. if (!lua_interface)
  6329. return 0;
  6330. Spawn* spawn = lua_interface->GetSpawn(state);
  6331. int32 id = lua_interface->GetInt32Value(state, 2);
  6332. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6333. Spawn* spawn2 = 0;
  6334. if (!spawn) {
  6335. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. //If zone not provided, use spawn's zone
  6339. if (!zone)
  6340. zone = spawn->GetZone();
  6341. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6342. vector<Spawn*>::iterator itr = list.begin();
  6343. if (list.size() == 0) {
  6344. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6345. return 0;
  6346. }
  6347. for (int8 i = 0; i < list.size(); i++) {
  6348. spawn2 = itr[i];
  6349. if (spawn2)
  6350. spawn2->RemoveSpawnAccess(spawn);
  6351. }
  6352. return 0;
  6353. }
  6354. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6355. if (!lua_interface)
  6356. return 0;
  6357. Quest* quest = lua_interface->GetQuest(state);
  6358. if (!quest) {
  6359. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6360. return 0;
  6361. }
  6362. quest->SetYellowName(true);
  6363. return 0;
  6364. }
  6365. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6366. if (!lua_interface)
  6367. return 0;
  6368. Spawn* spawn = lua_interface->GetSpawn(state);
  6369. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6370. if (!spawn) {
  6371. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6372. return 0;
  6373. }
  6374. if (!spawn->IsPlayer()) {
  6375. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6379. return 1;
  6380. }
  6381. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6382. if (!lua_interface)
  6383. return 0;
  6384. Spawn* spawn = lua_interface->GetSpawn(state);
  6385. if (!spawn) {
  6386. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6387. return 0;
  6388. }
  6389. if (!spawn->IsPlayer()) {
  6390. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6391. return 0;
  6392. }
  6393. ZoneServer* zone = spawn->GetZone();
  6394. if (!zone) {
  6395. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6396. return 0;
  6397. }
  6398. Instance_Type iType = zone->GetInstanceType();
  6399. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6400. iType == GROUP_LOCKOUT_INSTANCE ||
  6401. iType == RAID_LOCKOUT_INSTANCE ||
  6402. iType == SOLO_PERSIST_INSTANCE ||
  6403. iType == GROUP_PERSIST_INSTANCE ||
  6404. iType == RAID_PERSIST_INSTANCE) {
  6405. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6406. if (data) {
  6407. // Check to see if the timer has already been set, if it has return out.
  6408. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6409. return 0;
  6410. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6411. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6412. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6413. if (client) {
  6414. string time_msg = "";
  6415. int32 time = data->success_lockout_time;
  6416. int16 hour;
  6417. int8 min;
  6418. int8 sec;
  6419. hour = time / 3600;
  6420. time = time % 3600;
  6421. min = time / 60;
  6422. time = time % 60;
  6423. sec = time;
  6424. if (hour > 0) {
  6425. char temp[10];
  6426. sprintf(temp, " %i", hour);
  6427. time_msg.append(temp);
  6428. time_msg.append(" hour");
  6429. time_msg.append((hour > 1) ? "s" : "");
  6430. }
  6431. if (min > 0) {
  6432. char temp[5];
  6433. sprintf(temp, " %i", min);
  6434. time_msg.append(temp);
  6435. time_msg.append(" minute");
  6436. time_msg.append((min > 1) ? "s" : "");
  6437. }
  6438. // Only add seconds if minutes and hours are 0
  6439. if (hour == 0 && min == 0 && sec > 0) {
  6440. char temp[5];
  6441. sprintf(temp, " %i", sec);
  6442. time_msg.append(temp);
  6443. time_msg.append(" second");
  6444. time_msg.append((sec > 1) ? "s" : "");
  6445. }
  6446. 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());
  6447. }
  6448. }
  6449. else
  6450. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6451. }
  6452. else
  6453. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6454. return 0;
  6455. }
  6456. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6457. if (!lua_interface)
  6458. return 0;
  6459. Spawn* spawn = lua_interface->GetSpawn(state);
  6460. if (!spawn) {
  6461. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. if (!spawn->IsPlayer()) {
  6465. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6466. return 0;
  6467. }
  6468. ZoneServer* zone = spawn->GetZone();
  6469. if (!zone) {
  6470. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. Instance_Type iType = zone->GetInstanceType();
  6474. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6475. iType == GROUP_LOCKOUT_INSTANCE ||
  6476. iType == RAID_LOCKOUT_INSTANCE ||
  6477. iType == SOLO_PERSIST_INSTANCE ||
  6478. iType == GROUP_PERSIST_INSTANCE ||
  6479. iType == RAID_PERSIST_INSTANCE) {
  6480. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6481. if (data) {
  6482. // Check to see if the timer has already been set, if it has return out.
  6483. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6484. return 0;
  6485. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6486. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6487. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6488. if (client) {
  6489. string time_msg = "";
  6490. int32 time = data->failure_lockout_time;
  6491. int16 hour;
  6492. int8 min;
  6493. int8 sec;
  6494. hour = time / 3600;
  6495. time = time % 3600;
  6496. min = time / 60;
  6497. time = time % 60;
  6498. sec = time;
  6499. if (hour > 0) {
  6500. char temp[10];
  6501. sprintf(temp, " %i", hour);
  6502. time_msg.append(temp);
  6503. time_msg.append(" hour");
  6504. time_msg.append((hour > 1) ? "s" : "");
  6505. }
  6506. if (min > 0) {
  6507. char temp[5];
  6508. sprintf(temp, " %i", min);
  6509. time_msg.append(temp);
  6510. time_msg.append(" minute");
  6511. time_msg.append((min > 1) ? "s" : "");
  6512. }
  6513. // Only add seconds if minutes and hours are 0
  6514. if (hour == 0 && min == 0 && sec > 0) {
  6515. char temp[5];
  6516. sprintf(temp, " %i", sec);
  6517. time_msg.append(temp);
  6518. time_msg.append(" second");
  6519. time_msg.append((sec > 1) ? "s" : "");
  6520. }
  6521. 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());
  6522. }
  6523. }
  6524. else
  6525. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6526. }
  6527. else
  6528. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6532. if (!lua_interface)
  6533. return 0;
  6534. Spawn* spawn = lua_interface->GetSpawn(state);
  6535. if (!spawn) {
  6536. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6537. return 0;
  6538. }
  6539. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6540. return 1;
  6541. }
  6542. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6543. if (!lua_interface)
  6544. return 0;
  6545. Spawn* player = lua_interface->GetSpawn(state);
  6546. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6547. if (!player) {
  6548. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. if (!player->IsPlayer()) {
  6552. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6553. return 0;
  6554. }
  6555. if (!ground) {
  6556. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6557. return 0;
  6558. }
  6559. if (!ground->IsGroundSpawn()) {
  6560. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6561. return 0;
  6562. }
  6563. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6564. if (!groundspawn_entries) {
  6565. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6566. return 0;
  6567. }
  6568. Skill* skill = 0;
  6569. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6570. if (collection_skill == "Collecting")
  6571. skill = ((Player*)player)->GetSkillByName("Gathering");
  6572. else
  6573. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6574. if (!skill) {
  6575. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6576. return 0;
  6577. }
  6578. vector<GroundSpawnEntry*>::iterator itr;
  6579. GroundSpawnEntry* entry = 0;
  6580. bool can_harvest = false;
  6581. sint32 min_skill = -1;
  6582. int16 totalSkill = skill->current_val;
  6583. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6584. if(skillID != 0xFFFFFFFF)
  6585. {
  6586. ((Entity*)player)->MStats.lock();
  6587. totalSkill += ((Entity*)player)->stats[skillID];
  6588. ((Entity*)player)->MStats.unlock();
  6589. }
  6590. // first, iterate through groundspawn_entries, discard tables player cannot use
  6591. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6592. {
  6593. entry = *itr;
  6594. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6595. min_skill = entry->min_skill_level;
  6596. // if player lacks skill, skip table
  6597. if (entry->min_skill_level > totalSkill)
  6598. continue;
  6599. // if bonus, but player lacks level, skip table
  6600. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6601. continue;
  6602. can_harvest = true;
  6603. break;
  6604. }
  6605. lua_interface->SetBooleanValue(state, can_harvest);
  6606. // If false, send the message to the client
  6607. if (!can_harvest) {
  6608. Client* client = player->GetZone()->GetClientBySpawn(player);
  6609. if (client) {
  6610. string msg = "You do not have enough skill to ";
  6611. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6612. msg.append("gather");
  6613. else if (collection_skill == "Mining")
  6614. msg.append("mine");
  6615. else if (collection_skill == "Trapping")
  6616. msg.append("trap");
  6617. else if (collection_skill == "Foresting")
  6618. msg.append("forest");
  6619. else if (collection_skill == "Fishing")
  6620. msg.append("catch");
  6621. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6622. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6623. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6624. }
  6625. }
  6626. return 1;
  6627. }
  6628. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6629. if (!lua_interface)
  6630. return 0;
  6631. Spawn* player = lua_interface->GetSpawn(state);
  6632. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6633. if (!player) {
  6634. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6635. return 0;
  6636. }
  6637. if (!player->IsPlayer()) {
  6638. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6642. lua_interface->SetBooleanValue(state, ret);
  6643. return 1;
  6644. }
  6645. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6646. // Check to see if we have a valid lua_interface
  6647. if (!lua_interface)
  6648. return 0;
  6649. // Get the spawn that is getting the pet
  6650. Spawn* spawn = lua_interface->GetSpawn(state);
  6651. Spawn* target = lua_interface->GetSpawn(state, 2);
  6652. // Get the DB ID of the pet
  6653. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6654. float x = lua_interface->GetFloatValue(state, 4);
  6655. float y = lua_interface->GetFloatValue(state, 5);
  6656. float z = lua_interface->GetFloatValue(state, 6);
  6657. // Get the spell that this command was called from
  6658. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6659. // Check to make sure the spawn pointer is valid
  6660. if (!spawn) {
  6661. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6662. return 0;
  6663. }
  6664. // Check to make sure the spawn is an entity
  6665. if (!spawn->IsEntity()) {
  6666. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. if (!target) {
  6670. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6671. return 0;
  6672. }
  6673. if (!target->IsEntity()) {
  6674. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6675. return 0;
  6676. }
  6677. // Check to see if the DB ID for the pet is set
  6678. if (pet_id == 0) {
  6679. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. // Check to see if the pointer to the spell is valid
  6683. if (!luaspell) {
  6684. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6688. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6689. if (!pet) {
  6690. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6691. return 0;
  6692. }
  6693. // Check to make sure the pet is an npc
  6694. if (!pet->IsNPC()) {
  6695. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6696. return 0;
  6697. }
  6698. if (x == 0)
  6699. x = spawn->GetX();
  6700. if (y == 0)
  6701. y = spawn->GetY();
  6702. if (z == 0)
  6703. z = spawn->GetZ();
  6704. // Spawn the pet at the same location as the owner
  6705. pet->SetX(x);
  6706. pet->SetY(y);
  6707. pet->SetZ(z);
  6708. pet->SetLocation(spawn->GetLocation());
  6709. pet->SetHeading(spawn->GetHeading());
  6710. spawn->GetZone()->AddSpawn(pet);
  6711. /*
  6712. const char* spawn_script = world.GetSpawnScript(pet_id);
  6713. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6714. spawn->SetSpawnScript(string(spawn_script));
  6715. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6716. }*/
  6717. // Get a random pet name
  6718. string random_pet_name;
  6719. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6720. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6721. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6722. // Set the pets name
  6723. pet->SetName(random_pet_name.c_str());
  6724. // Set the level of the pet to the owners level
  6725. pet->SetLevel(spawn->GetLevel());
  6726. // Set the faction of the pet to the same faction as the owner
  6727. pet->SetFactionID(spawn->GetFactionID());
  6728. // Set the spawn as a pet
  6729. pet->SetPet(true);
  6730. // Give a pointer of the owner to the pet
  6731. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6732. // Set the pet type
  6733. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6734. // Set the spell id used to create this pet
  6735. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6736. // Set the spell tier used to create this pet
  6737. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6738. // Set the pets spawn type to 6
  6739. pet->SetSpawnType(6);
  6740. // Set the pets brain
  6741. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6742. // Check to see if the pet has a subtitle
  6743. if (strlen(pet->GetSubTitle()) > 0) {
  6744. // Add the players name to the front of the sub title
  6745. string pet_subtitle;
  6746. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6747. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6748. // Set the pets subtitle to the new one
  6749. pet->SetSubTitle(pet_subtitle.c_str());
  6750. }
  6751. // Set the pet as the return value for this function
  6752. lua_interface->SetSpawnValue(state, pet);
  6753. return 1;
  6754. }
  6755. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6756. if (!lua_interface)
  6757. return 0;
  6758. Spawn* spawn = lua_interface->GetSpawn(state);
  6759. Spawn* player = lua_interface->GetSpawn(state, 2);
  6760. float max_distance = lua_interface->GetFloatValue(state, 3);
  6761. string type = lua_interface->GetStringValue(state, 4);
  6762. if (!spawn || (spawn && spawn->IsPlayer())) {
  6763. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6764. return 0;
  6765. }
  6766. if (!player || (player && !player->IsPlayer())) {
  6767. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6768. return 0;
  6769. }
  6770. Client* client = 0;
  6771. if (player->GetZone())
  6772. client = player->GetZone()->GetClientBySpawn(player);
  6773. if (!client) {
  6774. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. //Set max_distance to default if not set or not proper value
  6778. if (max_distance <= 0)
  6779. max_distance = 500;
  6780. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6781. if (packet) {
  6782. float unknown2_3 = 0;
  6783. int8 placement_mode = 0;
  6784. if (type == "wall") {
  6785. placement_mode = 2;
  6786. unknown2_3 = 150;
  6787. }
  6788. else if (type == "ceiling")
  6789. placement_mode = 1;
  6790. packet->setDataByName("placement_mode", placement_mode);
  6791. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6792. packet->setDataByName("model_type", spawn->GetModelType());
  6793. packet->setDataByName("unknown", 1); //size
  6794. packet->setDataByName("unknown2", 1); //size 2
  6795. packet->setDataByName("unknown2", .5, 1); //size 3
  6796. packet->setDataByName("unknown2", 3, 2);
  6797. packet->setDataByName("unknown2", unknown2_3, 3);
  6798. packet->setDataByName("max_distance", max_distance);
  6799. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6800. client->QueuePacket(packet->serialize());
  6801. safe_delete(packet);
  6802. }
  6803. return 0;
  6804. }
  6805. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6806. if (!lua_interface)
  6807. return 0;
  6808. Item* item = lua_interface->GetItem(state);
  6809. if (!item) {
  6810. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6811. return 0;
  6812. }
  6813. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6814. return 1;
  6815. }
  6816. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6817. if (!lua_interface)
  6818. return 0;
  6819. Spawn* spawn = lua_interface->GetSpawn(state);
  6820. if (!spawn) {
  6821. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6822. return 0;
  6823. }
  6824. if (spawn->GetZone())
  6825. spawn->GetZone()->AddTransportSpawn(spawn);
  6826. return 0;
  6827. }
  6828. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6829. if (!lua_interface)
  6830. return 0;
  6831. Spawn* spawn = lua_interface->GetSpawn(state);
  6832. if (!spawn) {
  6833. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6837. return 1;
  6838. }
  6839. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6840. if (!lua_interface)
  6841. return 0;
  6842. Skill* skill = lua_interface->GetSkill(state);
  6843. if (!skill) {
  6844. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. lua_interface->SetInt32Value(state, skill->current_val);
  6848. return 1;
  6849. }
  6850. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6851. if (!lua_interface)
  6852. return 0;
  6853. Skill* skill = lua_interface->GetSkill(state);
  6854. if (!skill) {
  6855. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6856. return 0;
  6857. }
  6858. lua_interface->SetInt32Value(state, skill->max_val);
  6859. return 1;
  6860. }
  6861. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6862. if (!lua_interface)
  6863. return 0;
  6864. Skill* skill = lua_interface->GetSkill(state);
  6865. if (!skill) {
  6866. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6867. return 0;
  6868. }
  6869. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6870. return 1;
  6871. }
  6872. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6873. if (!lua_interface)
  6874. return 0;
  6875. Skill* skill = lua_interface->GetSkill(state);
  6876. int16 value = lua_interface->GetInt16Value(state, 2);
  6877. if (!skill) {
  6878. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6879. return 0;
  6880. }
  6881. skill->max_val = value;
  6882. if (skill->max_val < skill->current_val)
  6883. skill->current_val = skill->max_val;
  6884. return 0;
  6885. }
  6886. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6887. if (!lua_interface)
  6888. return 0;
  6889. Skill* skill = lua_interface->GetSkill(state);
  6890. int16 value = lua_interface->GetInt16Value(state, 2);
  6891. if (!skill) {
  6892. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6893. return 0;
  6894. }
  6895. if (value > skill->max_val)
  6896. skill->current_val = skill->max_val;
  6897. else
  6898. skill->current_val = value;
  6899. return 0;
  6900. }
  6901. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6902. if (!lua_interface)
  6903. return 0;
  6904. Spawn* player = lua_interface->GetSpawn(state);
  6905. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6906. if (skill_id > 0 && player && player->IsPlayer()) {
  6907. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6908. return 1;
  6909. }
  6910. return 0;
  6911. }
  6912. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6913. if (!lua_interface)
  6914. return 0;
  6915. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6916. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6917. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6918. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6919. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6920. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6921. if (player_spawn && player_spawn->IsPlayer()) {
  6922. Player* player = (Player*)player_spawn;
  6923. bool added = false;
  6924. if (!player->skill_list.HasSkill(skill_id)) {
  6925. player->AddSkill(skill_id, current_val, max_val, true);
  6926. added = true;
  6927. }
  6928. 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
  6929. Client* client = player->GetClient();
  6930. if (client) {
  6931. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6932. if (packet)
  6933. client->QueuePacket(packet);
  6934. }
  6935. }
  6936. if (added) {
  6937. lua_interface->SetBooleanValue(state, true);
  6938. return 1;
  6939. }
  6940. }
  6941. else {
  6942. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6943. }
  6944. }
  6945. else {
  6946. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6947. }
  6948. lua_interface->SetBooleanValue(state, false);
  6949. return 1;
  6950. }
  6951. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6952. if (!lua_interface)
  6953. return 0;
  6954. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6955. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6956. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6957. if (skill_id > 0) {
  6958. if (player_spawn && player_spawn->IsPlayer()) {
  6959. Player* player = (Player*)player_spawn;
  6960. if (player->skill_list.HasSkill(skill_id)) {
  6961. player->RemovePlayerSkill(skill_id);
  6962. if (!more_to_remove) {
  6963. Client* client = player->GetClient();
  6964. if (client) {
  6965. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6966. if (packet)
  6967. client->QueuePacket(packet);
  6968. }
  6969. }
  6970. }
  6971. }
  6972. else {
  6973. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6974. }
  6975. }
  6976. else {
  6977. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6978. }
  6979. return 0;
  6980. }
  6981. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6982. if (!lua_interface)
  6983. return 0;
  6984. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6985. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6986. int16 amount = lua_interface->GetInt8Value(state, 3);
  6987. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6988. if (amount > 0 && skill_type < 100) {
  6989. if (player_spawn && player_spawn->IsPlayer()) {
  6990. Player* player = (Player*)player_spawn;
  6991. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6992. if (!more_to_increase) {
  6993. Client* client = player->GetClient();
  6994. if (client) {
  6995. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6996. if (packet)
  6997. client->QueuePacket(packet);
  6998. }
  6999. }
  7000. }
  7001. else {
  7002. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7003. }
  7004. }
  7005. else {
  7006. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7007. }
  7008. return 0;
  7009. }
  7010. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7011. if (!lua_interface)
  7012. return 0;
  7013. Spawn* spawn = lua_interface->GetSpawn(state);
  7014. string name = lua_interface->GetStringValue(state, 2);
  7015. if (!spawn) {
  7016. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7017. return 0;
  7018. }
  7019. if (!spawn->IsEntity()) {
  7020. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7021. return 0;
  7022. }
  7023. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7024. if (skill) {
  7025. lua_interface->SetSkillValue(state, skill);
  7026. return 1;
  7027. }
  7028. return 0;
  7029. }
  7030. int EQ2Emu_lua_AddProc(lua_State* state) {
  7031. if (!lua_interface)
  7032. return 0;
  7033. Spawn* spawn = lua_interface->GetSpawn(state);
  7034. int8 type = lua_interface->GetInt8Value(state, 2);
  7035. float chance = lua_interface->GetFloatValue(state, 3);
  7036. Item* item = lua_interface->GetItem(state, 4);
  7037. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7038. LuaSpell* spell = 0;
  7039. if (!spawn && (!spell || !use_all_spelltargets)) {
  7040. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7041. return 0;
  7042. }
  7043. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7044. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. if (!item)
  7048. spell = lua_interface->GetCurrentSpell(state);
  7049. if (!item && !spell) {
  7050. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. if (spell && use_all_spelltargets) {
  7054. Spawn* target;
  7055. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7056. for (int8 i = 0; i < spell->targets.size(); i++) {
  7057. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7058. if (!target || !target->IsEntity())
  7059. continue;
  7060. ((Entity*)target)->AddProc(type, chance, item, spell);
  7061. }
  7062. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7063. }
  7064. else
  7065. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7066. return 0;
  7067. }
  7068. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7069. if (!lua_interface)
  7070. return 0;
  7071. Spawn* spawn = lua_interface->GetSpawn(state);
  7072. Item* item = lua_interface->GetItem(state, 2);
  7073. LuaSpell* spell = 0;
  7074. if (!spawn) {
  7075. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7076. return 0;
  7077. }
  7078. if (!spawn->IsEntity()) {
  7079. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7080. return 0;
  7081. }
  7082. if (!item)
  7083. spell = lua_interface->GetCurrentSpell(state);
  7084. if (!item && !spell) {
  7085. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. if (spell) {
  7089. Spawn* target;
  7090. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7091. for (int8 i = 0; i < spell->targets.size(); i++) {
  7092. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7093. if (!target || !target->IsEntity())
  7094. continue;
  7095. ((Entity*)target)->RemoveProc(item, spell);
  7096. }
  7097. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7098. spell->caster->RemoveProc(item, spell);
  7099. }
  7100. else
  7101. ((Entity*)spawn)->RemoveProc(item, spell);
  7102. return 0;
  7103. }
  7104. int EQ2Emu_lua_Knockback(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7108. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7109. int32 duration = lua_interface->GetInt32Value(state, 3);
  7110. float vertical = lua_interface->GetFloatValue(state, 4);
  7111. float horizontal = lua_interface->GetFloatValue(state, 5);
  7112. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7113. if (!target_spawn) {
  7114. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7115. return 0;
  7116. }
  7117. if (!spawn) {
  7118. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7119. return 0;
  7120. }
  7121. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7122. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7123. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7124. if (packet) {
  7125. packet->setDataByName("target_x", target_spawn->GetX());
  7126. packet->setDataByName("target_y", target_spawn->GetY());
  7127. packet->setDataByName("target_z", target_spawn->GetZ());
  7128. packet->setDataByName("vertical_movement", vertical);
  7129. packet->setDataByName("horizontal_movement", horizontal);
  7130. if (use_heading)
  7131. packet->setDataByName("use_player_heading", 1);
  7132. client->QueuePacket(packet->serialize());
  7133. }
  7134. safe_delete(packet);
  7135. }
  7136. return 0;
  7137. }
  7138. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7139. if (!lua_interface)
  7140. return 0;
  7141. Spawn* spawn = lua_interface->GetSpawn(state);
  7142. if (!spawn) {
  7143. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7144. return 0;
  7145. }
  7146. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7147. return 1;
  7148. }
  7149. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7150. if (!lua_interface)
  7151. return 0;
  7152. Spawn* caster = lua_interface->GetSpawn(state);
  7153. Spawn* target = lua_interface->GetSpawn(state, 2);
  7154. string name = lua_interface->GetStringValue(state, 3);
  7155. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7156. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7157. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7158. string success_msg = lua_interface->GetStringValue(state, 7);
  7159. string effect_msg = lua_interface->GetStringValue(state, 8);
  7160. if (!caster) {
  7161. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7162. return 0;
  7163. }
  7164. if (!caster->IsEntity()) {
  7165. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7166. return 0;
  7167. }
  7168. if (!target) {
  7169. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7170. return 0;
  7171. }
  7172. if (!target->IsEntity()) {
  7173. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7174. return 0;
  7175. }
  7176. if (name.length() == 0) {
  7177. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7178. return 0;
  7179. }
  7180. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7181. return 0;
  7182. }
  7183. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7184. if (!lua_interface)
  7185. return 0;
  7186. string name = lua_interface->GetStringValue(state);
  7187. if (name.length() == 0) {
  7188. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7189. return 0;
  7190. }
  7191. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7192. if (!skill) {
  7193. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7194. return 0;
  7195. }
  7196. lua_interface->SetInt32Value(state, skill->skill_id);
  7197. return 1;
  7198. }
  7199. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7200. if (!lua_interface)
  7201. return 0;
  7202. Spawn* spawn = lua_interface->GetSpawn(state);
  7203. if (!spawn) {
  7204. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7205. return 0;
  7206. }
  7207. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7208. return 1;
  7209. }
  7210. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7211. if (!lua_interface)
  7212. return 0;
  7213. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7214. if (!luaspell) {
  7215. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7216. return 0;
  7217. }
  7218. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7219. return 1;
  7220. }
  7221. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7222. if (!lua_interface)
  7223. return 0;
  7224. Spawn* spawn = lua_interface->GetSpawn(state);
  7225. Spawn* target = lua_interface->GetSpawn(state, 2);
  7226. if (!spawn) {
  7227. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7228. return 0;
  7229. }
  7230. if (!spawn->IsEntity()) {
  7231. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7232. return 0;
  7233. }
  7234. if (!target) {
  7235. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7236. return 0;
  7237. }
  7238. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7239. return 1;
  7240. }
  7241. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7242. if (!lua_interface)
  7243. return 0;
  7244. Spawn* spawn = lua_interface->GetSpawn(state);
  7245. Spawn* target = lua_interface->GetSpawn(state, 2);
  7246. if (!spawn) {
  7247. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. if (!spawn->IsEntity()) {
  7251. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7252. return 0;
  7253. }
  7254. if (!target) {
  7255. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7256. return 0;
  7257. }
  7258. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7259. return 1;
  7260. }
  7261. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7262. if (!lua_interface)
  7263. return 0;
  7264. Item* item = lua_interface->GetItem(state);
  7265. if (!item) {
  7266. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7267. return 0;
  7268. }
  7269. lua_interface->SetInt32Value(state, item->details.count);
  7270. return 1;
  7271. }
  7272. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7273. if (!lua_interface)
  7274. return 0;
  7275. Item* item = lua_interface->GetItem(state);
  7276. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7277. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7278. if (!item) {
  7279. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7280. return 0;
  7281. }
  7282. if (!owner) {
  7283. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7284. return 0;
  7285. }
  7286. if (!owner->IsPlayer()) {
  7287. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7288. return 0;
  7289. }
  7290. if (item->stack_count < new_count) {
  7291. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7292. return 0;
  7293. }
  7294. if (new_count > 0) {
  7295. item->details.count = new_count;
  7296. item->save_needed = true;
  7297. }
  7298. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7299. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7300. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7301. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7302. else
  7303. {
  7304. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7305. return 0;
  7306. }
  7307. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7308. if (!client)
  7309. return 0;
  7310. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7311. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7312. if (app)
  7313. client->QueuePacket(app);
  7314. return 0;
  7315. }
  7316. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7317. if (!lua_interface)
  7318. return 0;
  7319. int32 time = lua_interface->GetInt32Value(state);
  7320. string function = lua_interface->GetStringValue(state, 2);
  7321. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7322. Spawn* target = lua_interface->GetSpawn(state, 4);
  7323. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7324. if (time == 0) {
  7325. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7326. return 0;
  7327. }
  7328. if (function.length() == 0) {
  7329. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7330. return 0;
  7331. }
  7332. if (!spell) {
  7333. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7334. return 0;
  7335. }
  7336. SpellScriptTimer* timer = new SpellScriptTimer;
  7337. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7338. #ifdef WIN32
  7339. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7340. #else
  7341. bzero(timer, sizeof(SpellScriptTimer));
  7342. #endif*/
  7343. timer->caster = 0;
  7344. timer->deleteWhenDone = false;
  7345. timer->target = 0;
  7346. timer->time = Timer::GetCurrentTime2() + time;
  7347. timer->customFunction = function;
  7348. timer->spell = spell;
  7349. if (caster)
  7350. timer->caster = caster->GetID();
  7351. if (target)
  7352. timer->target = target->GetID();
  7353. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7354. return 0;
  7355. }
  7356. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7357. if (!lua_interface)
  7358. return 0;
  7359. float hp_perc = lua_interface->GetFloatValue(state);
  7360. float power_perc = lua_interface->GetFloatValue(state, 2);
  7361. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7362. Spawn* target = lua_interface->GetSpawn(state, 4);
  7363. string heal_name = lua_interface->GetStringValue(state, 5);
  7364. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7365. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7366. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7367. if (!spell) {
  7368. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7369. return 0;
  7370. }
  7371. Entity* caster = spell->caster;
  7372. if (!caster) {
  7373. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7374. return 0;
  7375. }
  7376. Client* client = 0;
  7377. PendingResurrection* rez = 0;
  7378. ZoneServer* zone = spell->caster->GetZone();
  7379. if (!target) {
  7380. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7381. if (spell->targets.size() > 0) {
  7382. vector<int32> spell_targets = spell->targets;
  7383. for (int8 i = 0; i < spell_targets.size(); i++) {
  7384. target = zone->GetSpawnByID(spell_targets.at(i));
  7385. if (!target)
  7386. continue;
  7387. if (!target->IsPlayer())
  7388. continue;
  7389. client = target->GetZone()->GetClientBySpawn(target);
  7390. if (!client)
  7391. continue;
  7392. rez = client->GetCurrentRez();
  7393. if (rez->active)
  7394. continue;
  7395. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7396. rez->active = true;
  7397. rez->caster = caster;
  7398. rez->expire_timer = new Timer;
  7399. int32 duration = spell->spell->GetSpellDuration();
  7400. rez->expire_timer->Start(duration * 100);
  7401. rez->hp_perc = hp_perc;
  7402. rez->mp_perc = power_perc;
  7403. rez->range = spell->spell->GetSpellData()->range;
  7404. rez->spell_name = spell->spell->GetName();
  7405. if (heal_name.length() > 0)
  7406. rez->heal_name = heal_name;
  7407. else
  7408. rez->heal_name = rez->spell_name;
  7409. rez->no_calcs = no_calcs;
  7410. rez->crit_mod = crit_mod;
  7411. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7412. if (send_window)
  7413. client->SendResurrectionWindow();
  7414. else {
  7415. target->GetZone()->ResurrectSpawn(target, client);
  7416. rez->should_delete = true;
  7417. }
  7418. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7419. }
  7420. }
  7421. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7422. }
  7423. else {
  7424. client = target->GetZone()->GetClientBySpawn(target);
  7425. if (!client)
  7426. return 0;
  7427. rez = client->GetCurrentRez();
  7428. if (rez->active)
  7429. return 0;
  7430. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7431. rez->active = true;
  7432. rez->caster = caster;
  7433. rez->expire_timer = new Timer;
  7434. int32 duration = spell->spell->GetSpellDuration();
  7435. rez->expire_timer->Start(duration * 100);
  7436. rez->hp_perc = hp_perc;
  7437. rez->mp_perc = power_perc;
  7438. rez->range = spell->spell->GetSpellData()->range;
  7439. rez->spell_name = spell->spell->GetName();
  7440. if (heal_name.length() > 0)
  7441. rez->heal_name = heal_name;
  7442. else
  7443. rez->heal_name = rez->spell_name;
  7444. rez->no_calcs = no_calcs;
  7445. rez->crit_mod = crit_mod;
  7446. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7447. if (send_window)
  7448. client->SendResurrectionWindow();
  7449. else {
  7450. target->GetZone()->ResurrectSpawn(target, client);
  7451. rez->should_delete = true;
  7452. }
  7453. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7454. }
  7455. return 0;
  7456. }
  7457. int EQ2Emu_lua_SetVision(lua_State* state) {
  7458. if (!lua_interface)
  7459. return 0;
  7460. Spawn* spawn = lua_interface->GetSpawn(state);
  7461. int8 vision = lua_interface->GetInt8Value(state, 2);
  7462. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7463. if (!spawn) {
  7464. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7465. return 0;
  7466. }
  7467. if (!spawn->IsEntity()) {
  7468. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7469. return 0;
  7470. }
  7471. if (spell && spell->targets.size() > 0) {
  7472. ZoneServer* zone = spell->caster->GetZone();
  7473. for (int8 i = 0; i < spell->targets.size(); i++) {
  7474. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7475. if (target && target->IsEntity()) {
  7476. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7477. if (target->IsPlayer())
  7478. ((Player*)target)->SetCharSheetChanged(true);
  7479. }
  7480. }
  7481. }
  7482. else {
  7483. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7484. if (spawn->IsPlayer())
  7485. ((Player*)spawn)->SetCharSheetChanged(true);
  7486. }
  7487. return 0;
  7488. }
  7489. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7490. if (!lua_interface)
  7491. return 0;
  7492. Spawn* spawn = lua_interface->GetSpawn(state);
  7493. float intensity = lua_interface->GetFloatValue(state, 2);
  7494. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7495. if (!spawn) {
  7496. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7497. return 0;
  7498. }
  7499. if (!spawn->IsEntity()) {
  7500. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7501. return 0;
  7502. }
  7503. if (spell && spell->targets.size() > 0) {
  7504. ZoneServer* zone = spell->caster->GetZone();
  7505. for (int8 i = 0; i < spell->targets.size(); i++) {
  7506. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7507. if (target && target->IsEntity()) {
  7508. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7509. if (target->IsPlayer())
  7510. ((Player*)target)->SetCharSheetChanged(true);
  7511. }
  7512. }
  7513. }
  7514. else {
  7515. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7516. if (spawn->IsPlayer())
  7517. ((Player*)spawn)->SetCharSheetChanged(true);
  7518. }
  7519. return 0;
  7520. }
  7521. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7522. if (!lua_interface)
  7523. return 0;
  7524. Spawn* spawn = lua_interface->GetSpawn(state);
  7525. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7526. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7527. if (!spawn) {
  7528. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7529. return 0;
  7530. }
  7531. if (!spawn->IsEntity()) {
  7532. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7533. return 0;
  7534. }
  7535. if (spell && spell->targets.size() > 0) {
  7536. ZoneServer* zone = spell->caster->GetZone();
  7537. for (int8 i = 0; i < spell->targets.size(); i++) {
  7538. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7539. if (target && target->IsEntity()) {
  7540. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7541. if (target->IsPlayer())
  7542. ((Player*)target)->SetCharSheetChanged(true);
  7543. }
  7544. }
  7545. }
  7546. else {
  7547. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7548. if (spawn->IsPlayer())
  7549. ((Player*)spawn)->SetCharSheetChanged(true);
  7550. }
  7551. return 0;
  7552. }
  7553. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7554. if (!lua_interface)
  7555. return 0;
  7556. Item* item = lua_interface->GetItem(state);
  7557. int8 type = lua_interface->GetInt32Value(state, 2);
  7558. if (!item) {
  7559. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7560. return 0;
  7561. }
  7562. if (type == 1)
  7563. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7564. else if (type == 2)
  7565. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7566. return 1;
  7567. }
  7568. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7569. if (!lua_interface)
  7570. return 0;
  7571. Spawn* target = lua_interface->GetSpawn(state);
  7572. float val = lua_interface->GetFloatValue(state, 2);
  7573. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7574. // Added from Gangrenous post
  7575. if (spell && spell->resisted)
  7576. return 0;
  7577. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7578. if (val > 1.0f)
  7579. val = 1.0f - (val / 100.0f);
  7580. if (spell && spell->spell && spell->targets.size() > 0) {
  7581. ZoneServer* zone = spell->caster->GetZone();
  7582. for (int32 i = 0; i != spell->targets.size(); i++) {
  7583. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7584. if (spawn && spawn->IsEntity()) {
  7585. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7586. if (spawn->IsPlayer())
  7587. ((Player*)spawn)->SetCharSheetChanged(true);
  7588. }
  7589. }
  7590. }
  7591. else {
  7592. if (target && target->IsEntity()) {
  7593. ((Entity*)target)->SetSpeedMultiplier(val);
  7594. if (target->IsPlayer())
  7595. ((Player*)target)->SetCharSheetChanged(true);
  7596. }
  7597. }
  7598. return 0;
  7599. }
  7600. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7601. if (!lua_interface)
  7602. return 0;
  7603. Spawn* spawn = lua_interface->GetSpawn(state);
  7604. int16 model = lua_interface->GetInt16Value(state, 2);
  7605. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7606. if (spell && spell->spell && spell->targets.size() > 0) {
  7607. ZoneServer* zone = spell->caster->GetZone();
  7608. for (int32 i = 0; i < spell->targets.size(); i++) {
  7609. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7610. if (target)
  7611. target->SetIllusionModel(model);
  7612. }
  7613. }
  7614. else {
  7615. if (!spawn) {
  7616. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. spawn->SetIllusionModel(model);
  7620. }
  7621. return 0;
  7622. }
  7623. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7624. if (!lua_interface)
  7625. return 0;
  7626. Spawn* spawn = lua_interface->GetSpawn(state);
  7627. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7628. if (spell && spell->spell && spell->targets.size() > 0) {
  7629. ZoneServer* zone = spell->caster->GetZone();
  7630. for (int32 i = 0; i < spell->targets.size(); i++) {
  7631. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7632. if (target)
  7633. target->SetIllusionModel(0);
  7634. }
  7635. }
  7636. else {
  7637. if (!spawn) {
  7638. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7639. return 0;
  7640. }
  7641. spawn->SetIllusionModel(0);
  7642. }
  7643. return 0;
  7644. }
  7645. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7646. if (!lua_interface)
  7647. return 0;
  7648. Spawn* caster = lua_interface->GetSpawn(state);
  7649. Spawn* target = lua_interface->GetSpawn(state, 2);
  7650. float chance = lua_interface->GetFloatValue(state, 3);
  7651. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7652. if (!caster) {
  7653. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if (!caster->IsEntity()) {
  7657. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7658. return 0;
  7659. }
  7660. if (!target) {
  7661. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7662. return 0;
  7663. }
  7664. if (!target->IsEntity()) {
  7665. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7666. return 0;
  7667. }
  7668. if (chance <= 0) {
  7669. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7670. return 0;
  7671. }
  7672. if (!spell) {
  7673. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7674. return 0;
  7675. }
  7676. if (((Entity*)caster)->GetThreatTransfer()) {
  7677. return 0;
  7678. }
  7679. ThreatTransfer* transfer = new ThreatTransfer;
  7680. transfer->Target = target->GetID();
  7681. transfer->Amount = chance;
  7682. transfer->Spell = spell;
  7683. ((Entity*)caster)->SetThreatTransfer(transfer);
  7684. return 0;
  7685. }
  7686. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7687. if (!lua_interface)
  7688. return 0;
  7689. Spawn* spawn = lua_interface->GetSpawn(state);
  7690. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7691. if (!spawn) {
  7692. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7693. return 0;
  7694. }
  7695. if (!spell) {
  7696. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7700. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7701. ((Entity*)spawn)->SetThreatTransfer(0);
  7702. safe_delete(transfer);
  7703. }
  7704. return 0;
  7705. }
  7706. int EQ2Emu_lua_CureByType(lua_State* state) {
  7707. if (!lua_interface)
  7708. return 0;
  7709. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7710. if (!spell) {
  7711. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7712. return 0;
  7713. }
  7714. int8 cure_count = lua_interface->GetInt8Value(state);
  7715. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7716. string cure_name = lua_interface->GetStringValue(state, 3);
  7717. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7718. Spawn* target = lua_interface->GetSpawn(state, 5);
  7719. if (target) {
  7720. if (!target->IsEntity()) {
  7721. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7722. return 0;
  7723. }
  7724. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7725. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7726. }
  7727. else {
  7728. ZoneServer* zone = spell->caster->GetZone();
  7729. vector<int32> targets = spell->targets;
  7730. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7731. for (int8 i = 0; i < targets.size(); i++) {
  7732. target = zone->GetSpawnByID(targets.at(i));
  7733. if (!target || !target->IsEntity())
  7734. continue;
  7735. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7736. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7737. }
  7738. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7739. }
  7740. return 0;
  7741. }
  7742. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7743. if (!lua_interface)
  7744. return 0;
  7745. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7746. if (!spell) {
  7747. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7748. return 0;
  7749. }
  7750. int8 cure_count = lua_interface->GetInt8Value(state);
  7751. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7752. string cure_name = lua_interface->GetStringValue(state, 3);
  7753. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7754. Spawn* target = lua_interface->GetSpawn(state, 5);
  7755. if (target) {
  7756. if (!target->IsEntity()) {
  7757. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7758. return 0;
  7759. }
  7760. if (((Entity*)target)->GetDetCount() > 0)
  7761. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7762. }
  7763. else {
  7764. ZoneServer* zone = spell->caster->GetZone();
  7765. vector<int32> targets = spell->targets;
  7766. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7767. for (int8 i = 0; i < targets.size(); i++) {
  7768. target = zone->GetSpawnByID(targets.at(i));
  7769. if (!target || !target->IsEntity())
  7770. continue;
  7771. if (((Entity*)target)->GetDetCount() > 0)
  7772. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7773. }
  7774. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7775. }
  7776. return 0;
  7777. }
  7778. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7779. if (!lua_interface)
  7780. return 0;
  7781. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7782. if (!spell) {
  7783. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7784. return 0;
  7785. }
  7786. if (!spell->caster) {
  7787. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7788. return 0;
  7789. }
  7790. if (!spell->caster->GetZone()) {
  7791. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7795. return 0;
  7796. }
  7797. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7798. if (!lua_interface)
  7799. return 0;
  7800. Spawn* spawn = lua_interface->GetSpawn(state);
  7801. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7802. if (!spell) {
  7803. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7804. return 0;
  7805. }
  7806. if (spawn && spawn->IsEntity())
  7807. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7808. else {
  7809. ZoneServer* zone = spell->caster->GetZone();
  7810. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7811. for (int32 i = 0; i < spell->targets.size(); i++) {
  7812. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7813. if (!spawn || !spawn->IsEntity())
  7814. continue;
  7815. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7816. }
  7817. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7818. }
  7819. return 0;
  7820. }
  7821. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7822. if (!lua_interface)
  7823. return 0;
  7824. Spawn* spawn = lua_interface->GetSpawn(state);
  7825. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7826. if (!spell) {
  7827. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7828. return 0;
  7829. }
  7830. if (spawn && spawn->IsEntity())
  7831. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7832. else {
  7833. ZoneServer* zone = spell->caster->GetZone();
  7834. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7835. for (int32 i = 0; i < spell->targets.size(); i++) {
  7836. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7837. if (!spawn || !spawn->IsEntity())
  7838. continue;
  7839. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7840. }
  7841. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7842. }
  7843. return 0;
  7844. }
  7845. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7846. if (!lua_interface)
  7847. return 0;
  7848. Spawn* caster = lua_interface->GetSpawn(state);
  7849. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7850. if (!caster) {
  7851. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7852. return 0;
  7853. }
  7854. if (!caster->IsPlayer()) {
  7855. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7856. return 0;
  7857. }
  7858. Spawn* target = caster->GetTarget();
  7859. if (!target) {
  7860. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7861. return 0;
  7862. }
  7863. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7864. if (!client) {
  7865. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7866. return 0;
  7867. }
  7868. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7869. if (ho) {
  7870. ho->SetTarget(target->GetID());
  7871. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7872. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7873. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7874. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7875. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7876. deque<GroupMemberInfo*>::iterator itr;
  7877. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7878. if (group)
  7879. {
  7880. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7881. deque<GroupMemberInfo*>* members = group->GetMembers();
  7882. for (itr = members->begin(); itr != members->end(); itr++) {
  7883. if ((*itr)->client)
  7884. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7885. }
  7886. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7887. }
  7888. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7889. }
  7890. else
  7891. safe_delete(ho);
  7892. }
  7893. else {
  7894. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7895. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7896. }
  7897. else
  7898. safe_delete(ho);
  7899. }
  7900. }
  7901. return 0;
  7902. }
  7903. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7904. if (!lua_interface)
  7905. return 0;
  7906. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7907. if (!spell) {
  7908. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. int16 triggerCount = lua_interface->GetInt16Value(state);
  7912. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7913. if (!triggerCount) {
  7914. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7915. return 0;
  7916. }
  7917. spell->num_triggers = triggerCount;
  7918. spell->had_triggers = true;
  7919. spell->cancel_after_all_triggers = cancel_after_triggers;
  7920. return 0;
  7921. }
  7922. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7923. if (!lua_interface)
  7924. return 0;
  7925. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7926. if (!spell) {
  7927. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7928. return 0;
  7929. }
  7930. lua_interface->SetInt32Value(state, spell->num_triggers);
  7931. return 1;
  7932. }
  7933. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7934. if (!lua_interface)
  7935. return 0;
  7936. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7937. if (!spell) {
  7938. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. int16 remove_count = lua_interface->GetInt16Value(state);
  7942. if (!remove_count)
  7943. remove_count = 1;
  7944. if (remove_count >= spell->num_triggers) {
  7945. spell->num_triggers = 0;
  7946. if (spell->cancel_after_all_triggers)
  7947. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7948. }
  7949. else {
  7950. spell->num_triggers -= remove_count;
  7951. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7952. }
  7953. return 0;
  7954. }
  7955. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7956. if (!lua_interface)
  7957. return 0;
  7958. Spawn* spawn = lua_interface->GetSpawn(state);
  7959. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7960. if (!spawn) {
  7961. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7962. return 0;
  7963. }
  7964. if (!copy_spawn) {
  7965. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7966. return 0;
  7967. }
  7968. spawn->CopySpawnAppearance(copy_spawn);
  7969. return 0;
  7970. }
  7971. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7972. Spawn* spawn = lua_interface->GetSpawn(state);
  7973. int8 type = lua_interface->GetInt8Value(state, 2);
  7974. if (!spawn) {
  7975. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7976. return 0;
  7977. }
  7978. else if (!spawn->IsEntity()) {
  7979. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7980. return 0;
  7981. }
  7982. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7983. return 1;
  7984. }
  7985. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7986. if (!lua_interface)
  7987. return 0;
  7988. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7989. int8 type = lua_interface->GetInt8Value(state);
  7990. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7991. if (!spell) {
  7992. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7993. return 0;
  7994. }
  7995. if (spawn) {
  7996. if (!spawn->IsEntity()) {
  7997. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7998. return 0;
  7999. }
  8000. Entity* entity = ((Entity*)spawn);
  8001. entity->AddImmunity(spell, type);
  8002. }
  8003. else {
  8004. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8005. for (int8 i = 0; i < spell->targets.size(); i++) {
  8006. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8007. if (!spawn || !spawn->IsEntity())
  8008. continue;
  8009. Entity* entity = ((Entity*)spawn);
  8010. entity->AddImmunity(spell, type);
  8011. }
  8012. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8013. }
  8014. return 0;
  8015. }
  8016. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8017. if (!lua_interface)
  8018. return 0;
  8019. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8020. int8 type = lua_interface->GetInt8Value(state);
  8021. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8022. if (!spell) {
  8023. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8024. return 0;
  8025. }
  8026. if (spawn) {
  8027. if (!spawn->IsEntity()) {
  8028. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. Entity* entity = ((Entity*)spawn);
  8032. entity->RemoveImmunity(spell, type);
  8033. }
  8034. else {
  8035. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8036. for (int8 i = 0; i < spell->targets.size(); i++) {
  8037. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8038. if (!spawn || !spawn->IsEntity())
  8039. continue;
  8040. Entity* entity = ((Entity*)spawn);
  8041. entity->RemoveImmunity(spell, type);
  8042. }
  8043. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8044. }
  8045. return 0;
  8046. }
  8047. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8048. if (!lua_interface)
  8049. return 0;
  8050. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8051. if (!spell) {
  8052. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8053. return 0;
  8054. }
  8055. float snare = lua_interface->GetFloatValue(state);
  8056. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8057. // convert the val to the speed multipler value (100 - val)
  8058. float val = 100.0 - snare;
  8059. val /= 100.0;
  8060. if (spawn) {
  8061. if (!spawn->IsEntity()) {
  8062. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8063. return 0;
  8064. }
  8065. ((Entity*)spawn)->SetSnareValue(spell, val);
  8066. }
  8067. else {
  8068. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8069. for (int8 i = 0; i < spell->targets.size(); i++) {
  8070. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8071. if (!spawn || !spawn->IsEntity())
  8072. continue;
  8073. ((Entity*)spawn)->SetSnareValue(spell, val);
  8074. }
  8075. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8076. }
  8077. return 0;
  8078. }
  8079. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8080. if (!lua_interface)
  8081. return 0;
  8082. Spawn* spawn = lua_interface->GetSpawn(state);
  8083. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8084. if (!spawn) {
  8085. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8086. return 0;
  8087. }
  8088. if (race_id == 0) {
  8089. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8090. return 0;
  8091. }
  8092. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8093. return 1;
  8094. }
  8095. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8096. if (!lua_interface)
  8097. return 0;
  8098. Spawn* spawn = lua_interface->GetSpawn(state);
  8099. if (!spawn) {
  8100. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8101. return 0;
  8102. }
  8103. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8104. return 1;
  8105. }
  8106. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8107. if (!lua_interface)
  8108. return 0;
  8109. Spawn* spawn = lua_interface->GetSpawn(state);
  8110. if (!spawn) {
  8111. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8112. return 0;
  8113. }
  8114. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8115. return 1;
  8116. }
  8117. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8118. if (!lua_interface)
  8119. return 0;
  8120. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8121. if (!spell) {
  8122. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8123. return 0;
  8124. }
  8125. lua_interface->SetStringValue(state, spell->spell->GetName());
  8126. return 1;
  8127. }
  8128. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8129. if (!lua_interface)
  8130. return 0;
  8131. Quest* quest = lua_interface->GetQuest(state);
  8132. if (!quest) {
  8133. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8134. return 0;
  8135. }
  8136. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8137. return 1;
  8138. }
  8139. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8140. if (!lua_interface)
  8141. return 0;
  8142. Quest* quest = lua_interface->GetQuest(state);
  8143. int32 flags = lua_interface->GetInt32Value(state, 2);
  8144. if (!quest) {
  8145. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8146. return 0;
  8147. }
  8148. quest->SetQuestFlags(flags);
  8149. return 0;
  8150. }
  8151. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8152. if (!lua_interface)
  8153. return 0;
  8154. Quest* quest = lua_interface->GetQuest(state);
  8155. Spawn* player = lua_interface->GetSpawn(state, 2);
  8156. int32 step = lua_interface->GetInt32Value(state, 3);
  8157. int32 duration = lua_interface->GetInt32Value(state, 4);
  8158. string action = lua_interface->GetStringValue(state, 5);
  8159. if (!quest) {
  8160. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8161. return 0;
  8162. }
  8163. if (!player) {
  8164. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8165. return 0;
  8166. }
  8167. if (!player->IsPlayer()) {
  8168. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8169. return 0;
  8170. }
  8171. if (step == 0) {
  8172. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8173. return 0;
  8174. }
  8175. if (duration == 0) {
  8176. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8177. return 0;
  8178. }
  8179. if (action.length() == 0) {
  8180. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8181. return 0;
  8182. }
  8183. Client* client = player->GetZone()->GetClientBySpawn(player);
  8184. if (!client) {
  8185. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8186. return 0;
  8187. }
  8188. quest->SetTimerStep(step);
  8189. quest->AddFailedAction(step, action);
  8190. quest->SetStepTimer(duration);
  8191. client->AddQuestTimer(quest->GetQuestID());
  8192. return 0;
  8193. }
  8194. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8195. if (!lua_interface)
  8196. return 0;
  8197. Quest* quest = lua_interface->GetQuest(state);
  8198. Spawn* player = lua_interface->GetSpawn(state, 2);
  8199. if (!quest) {
  8200. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8201. return 0;
  8202. }
  8203. if (!player) {
  8204. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8205. return 0;
  8206. }
  8207. if (!player->IsPlayer()) {
  8208. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8209. return 0;
  8210. }
  8211. Client* client = player->GetZone()->GetClientBySpawn(player);
  8212. if (!client) {
  8213. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8214. return 0;
  8215. }
  8216. quest->SetTimerStep(0);
  8217. quest->SetStepTimer(0);
  8218. client->RemoveQuestTimer(quest->GetQuestID());
  8219. return 0;
  8220. }
  8221. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8222. if (!lua_interface)
  8223. return 0;
  8224. Spawn* player = lua_interface->GetSpawn(state);
  8225. Quest* quest = lua_interface->GetQuest(state, 2);
  8226. int32 step = lua_interface->GetInt32Value(state, 3);
  8227. if (!player) {
  8228. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8229. return 0;
  8230. }
  8231. if (!player->IsPlayer()) {
  8232. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8233. return 0;
  8234. }
  8235. if (!quest) {
  8236. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. if (step == 0) {
  8240. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. Client* client = player->GetZone()->GetClientBySpawn(player);
  8244. if (!client) {
  8245. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8246. return 0;
  8247. }
  8248. if (quest->RemoveQuestStep(step, client)) {
  8249. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8250. client->GetCurrentZone()->SendQuestUpdates(client);
  8251. }
  8252. else
  8253. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8254. return 0;
  8255. }
  8256. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8257. if (!lua_interface)
  8258. return 0;
  8259. Quest* quest = lua_interface->GetQuest(state, 1);
  8260. int32 step = lua_interface->GetInt32Value(state, 2);
  8261. string desc = lua_interface->GetStringValue(state, 3);
  8262. string task_group = lua_interface->GetStringValue(state, 4);
  8263. if (!quest) {
  8264. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8265. return 0;
  8266. }
  8267. if (step == 0) {
  8268. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8269. return 0;
  8270. }
  8271. QuestStep* quest_step = quest->GetQuestStep(step);
  8272. if (!quest_step) {
  8273. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8274. return 0;
  8275. }
  8276. quest_step->SetStepProgress(0);
  8277. quest_step->SetTaskGroup(task_group);
  8278. quest_step->SetDescription(desc);
  8279. return 0;
  8280. }
  8281. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8282. if (!lua_interface)
  8283. return 0;
  8284. Quest* quest = lua_interface->GetQuest(state);
  8285. int32 step = lua_interface->GetInt32Value(state, 2);
  8286. string action = lua_interface->GetStringValue(state, 3);
  8287. if (!quest) {
  8288. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8289. return 0;
  8290. }
  8291. if (step == 0) {
  8292. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8293. return 0;
  8294. }
  8295. if (action.length() == 0) {
  8296. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8297. return 0;
  8298. }
  8299. quest->AddFailedAction(step, action);
  8300. return 0;
  8301. }
  8302. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8303. if (!lua_interface)
  8304. return 0;
  8305. Spawn* player = lua_interface->GetSpawn(state);
  8306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8307. int32 step = lua_interface->GetInt32Value(state, 3);
  8308. if (!player) {
  8309. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. if (!player->IsPlayer()) {
  8313. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. if (quest_id == 0) {
  8317. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (step == 0) {
  8321. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8325. if (!quest) {
  8326. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8327. return 0;
  8328. }
  8329. quest->StepFailed(step);
  8330. return 0;
  8331. }
  8332. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8333. if (!lua_interface)
  8334. return 0;
  8335. Spawn* player = lua_interface->GetSpawn(state);
  8336. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8337. if (!player) {
  8338. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. if (!player->IsPlayer()) {
  8342. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8343. return 0;
  8344. }
  8345. if (quest_id == 0) {
  8346. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8350. if (!quest) {
  8351. lua_interface->SetInt32Value(state, 0);
  8352. return 1;
  8353. }
  8354. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8355. return 1;
  8356. }
  8357. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8358. if (!lua_interface)
  8359. return 0;
  8360. string name = lua_interface->GetStringValue(state);
  8361. string value = lua_interface->GetStringValue(state, 2);
  8362. string comment = lua_interface->GetStringValue(state, 3);
  8363. if (name.length() == 0) {
  8364. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. if (value.length() == 0) {
  8368. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8369. return 0;
  8370. }
  8371. string varname = string("lua_").append(name);
  8372. Variable* var = variables.FindVariable(varname);
  8373. if (var)
  8374. var->SetValue(value.c_str());
  8375. else {
  8376. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8377. variables.AddVariable(var);
  8378. }
  8379. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8380. return 0;
  8381. }
  8382. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8383. if (!lua_interface)
  8384. return 0;
  8385. string name = lua_interface->GetStringValue(state);
  8386. if (name.length() == 0) {
  8387. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8388. return 0;
  8389. }
  8390. string varname = string("lua_").append(name);
  8391. Variable* var = variables.FindVariable(varname);
  8392. if (var)
  8393. lua_interface->SetStringValue(state, var->GetValue());
  8394. else
  8395. lua_interface->SetStringValue(state, "NULL");
  8396. return 1;
  8397. }
  8398. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8399. if (!lua_interface)
  8400. return 0;
  8401. Spawn* player = lua_interface->GetSpawn(state);
  8402. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8403. if (!player) {
  8404. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8405. return 0;
  8406. }
  8407. if (!player->IsPlayer()) {
  8408. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8409. return 0;
  8410. }
  8411. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8412. return 1;
  8413. }
  8414. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8415. if (!lua_interface)
  8416. return 0;
  8417. Spawn* player = lua_interface->GetSpawn(state);
  8418. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8419. if (!player) {
  8420. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8421. return 0;
  8422. }
  8423. if (!player->IsPlayer()) {
  8424. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8425. return 0;
  8426. }
  8427. Language* language = master_languages_list.GetLanguage(language_id);
  8428. if (language)
  8429. {
  8430. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8431. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8432. }
  8433. return 0;
  8434. }
  8435. int EQ2Emu_lua_IsNight(lua_State* state) {
  8436. if (!lua_interface)
  8437. return 0;
  8438. ZoneServer* zone = lua_interface->GetZone(state);
  8439. if (!zone) {
  8440. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8441. return 0;
  8442. }
  8443. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8444. return 1;
  8445. }
  8446. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8447. if (!lua_interface)
  8448. return 0;
  8449. Spawn* spawn = lua_interface->GetSpawn(state);
  8450. if (!spawn) {
  8451. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!spawn->IsWidget()) {
  8455. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. ((Widget*)spawn)->SetMultiFloorLift(true);
  8459. if (spawn->GetZone())
  8460. spawn->GetZone()->AddTransportSpawn(spawn);
  8461. return 0;
  8462. }
  8463. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8464. if (!lua_interface)
  8465. return 0;
  8466. Spawn* player = lua_interface->GetSpawn(state);
  8467. int32 path = lua_interface->GetInt32Value(state, 2);
  8468. if (!player) {
  8469. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8470. return 0;
  8471. }
  8472. if (!player->IsPlayer()) {
  8473. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8474. return 0;
  8475. }
  8476. if (path == 0) {
  8477. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. Client* client = player->GetZone()->GetClientBySpawn(player);
  8481. if (!client) {
  8482. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8483. return 0;
  8484. }
  8485. client->SendFlightAutoMount(path);
  8486. return 0;
  8487. }
  8488. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8489. if (!lua_interface)
  8490. return 0;
  8491. Spawn* player = lua_interface->GetSpawn(state);
  8492. if (!player) {
  8493. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8494. return 0;
  8495. }
  8496. if (!player->IsPlayer()) {
  8497. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8498. return 0;
  8499. }
  8500. Client* client = player->GetZone()->GetClientBySpawn(player);
  8501. if (!client) {
  8502. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8503. return 0;
  8504. }
  8505. client->EndAutoMount();
  8506. return 0;
  8507. }
  8508. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8509. if (!lua_interface)
  8510. return 0;
  8511. Spawn* player = lua_interface->GetSpawn(state);
  8512. if (!player) {
  8513. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8514. return 0;
  8515. }
  8516. if (!player->IsPlayer()) {
  8517. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8518. return 0;
  8519. }
  8520. Client* client = player->GetZone()->GetClientBySpawn(player);
  8521. if (!client) {
  8522. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8523. return 0;
  8524. }
  8525. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8526. return 1;
  8527. }
  8528. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8529. if (!lua_interface)
  8530. return 0;
  8531. Spawn* player = lua_interface->GetSpawn(state);
  8532. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8533. int32 value = lua_interface->GetInt32Value(state, 3);
  8534. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8535. if (!player) {
  8536. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. if (!player->IsPlayer()) {
  8540. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8541. return 0;
  8542. }
  8543. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8544. return 0;
  8545. }
  8546. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8547. if (!lua_interface)
  8548. return 0;
  8549. Spawn* player = lua_interface->GetSpawn(state);
  8550. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8551. if (!player) {
  8552. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8553. return 0;
  8554. }
  8555. if (!player->IsPlayer()) {
  8556. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8557. return 0;
  8558. }
  8559. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8560. if (!hd)
  8561. return 0;
  8562. lua_interface->SetInt32Value(state, hd->Value);
  8563. lua_interface->SetInt32Value(state, hd->Value2);
  8564. return 2;
  8565. }
  8566. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8567. if (!lua_interface)
  8568. return 0;
  8569. Spawn* spawn = lua_interface->GetSpawn(state);
  8570. int32 grid = lua_interface->GetInt32Value(state, 2);
  8571. if (!spawn) {
  8572. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8573. return 0;
  8574. }
  8575. if (grid == 0) {
  8576. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8577. return 0;
  8578. }
  8579. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8580. return 0;
  8581. }
  8582. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8583. if (!lua_interface)
  8584. return 0;
  8585. Spawn* spawn = lua_interface->GetSpawn(state);
  8586. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8587. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8588. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8589. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8590. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8591. if (!spawn) {
  8592. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8593. return 0;
  8594. }
  8595. //Add this quest to the list of required quests for this spawn
  8596. spawn->SetRequiredHistory(event_id, value1, value2);
  8597. //If private spawn value set
  8598. if (private_spawn) {
  8599. //Set the spawn to be private when not granted access via history
  8600. spawn->AddAllowAccessSpawn(spawn);
  8601. spawn->SetPrivateQuestSpawn(true);
  8602. }
  8603. //This value will override vis_flags in the vis packet
  8604. if (flag_override > 0)
  8605. spawn->SetQuestsRequiredOverride(flag_override);
  8606. return 0;
  8607. }
  8608. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8609. if (!lua_interface)
  8610. return 0;
  8611. Spawn* player = lua_interface->GetSpawn(state);
  8612. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8613. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8614. if (!player) {
  8615. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8616. return 0;
  8617. }
  8618. if (!player->IsPlayer()) {
  8619. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8620. return 0;
  8621. }
  8622. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8623. return 1;
  8624. }
  8625. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8626. if (!lua_interface)
  8627. return 0;
  8628. Spawn* player = lua_interface->GetSpawn(state);
  8629. int8 level = lua_interface->GetInt8Value(state, 2);
  8630. if (!player) {
  8631. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8632. return 0;
  8633. }
  8634. if (!player->IsPlayer()) {
  8635. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. if (level == 0) {
  8639. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8640. return 0;
  8641. }
  8642. Client* client = player->GetZone()->GetClientBySpawn(player);
  8643. if (!client) {
  8644. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8645. return 0;
  8646. }
  8647. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8648. return 0;
  8649. }
  8650. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8651. if (!lua_interface)
  8652. return 0;
  8653. Spawn* player = lua_interface->GetSpawn(state);
  8654. int32 amount = lua_interface->GetInt32Value(state, 2);
  8655. if (!player) {
  8656. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8657. return 0;
  8658. }
  8659. if (!player->IsPlayer()) {
  8660. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8661. return 0;
  8662. }
  8663. if (amount == 0) {
  8664. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8665. return 0;
  8666. }
  8667. ((Player*)player)->AddCoins(amount);
  8668. return 0;
  8669. }
  8670. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8671. if (!lua_interface)
  8672. return 0;
  8673. Spawn* player = lua_interface->GetSpawn(state);
  8674. int32 amount = lua_interface->GetInt32Value(state, 2);
  8675. if (!player) {
  8676. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8677. return 0;
  8678. }
  8679. if (!player->IsPlayer()) {
  8680. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8681. return 0;
  8682. }
  8683. if (amount == 0) {
  8684. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8685. return 0;
  8686. }
  8687. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8688. return 1;
  8689. }
  8690. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8691. if (!lua_interface)
  8692. return 0;
  8693. ZoneServer* zone = lua_interface->GetZone(state);
  8694. if (!zone) {
  8695. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8696. return 0;
  8697. }
  8698. vector<Entity*> players = zone->GetPlayers();
  8699. if (players.size() == 0)
  8700. return 0;
  8701. lua_createtable(state, players.size(), 0);
  8702. int newTable = lua_gettop(state);
  8703. for (int32 i = 0; i < players.size(); i++) {
  8704. lua_interface->SetSpawnValue(state, players.at(i));
  8705. lua_rawseti(state, newTable, i + 1);
  8706. }
  8707. return 1;
  8708. }
  8709. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8710. if (!lua_interface)
  8711. return 0;
  8712. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8713. if (!zone) {
  8714. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8715. return 0;
  8716. }
  8717. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8718. //Map of <placement_id, location_id>
  8719. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8720. map<int32, int32>::iterator itr;
  8721. vector<Spawn*> group;
  8722. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8723. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8724. if (!location) {
  8725. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8726. return 0;
  8727. }
  8728. Spawn* spawn = 0;
  8729. if (location->entities[0]) {
  8730. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8731. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8732. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8733. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8734. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8735. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8736. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8737. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8738. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8739. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8740. if(spawn && spawn->IsOmittedByDBFlag())
  8741. {
  8742. 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);
  8743. safe_delete(spawn);
  8744. continue;
  8745. }
  8746. if (spawn) {
  8747. const char* script = 0;
  8748. for (int x = 0; x < 3; x++) {
  8749. switch (x) {
  8750. case 0:
  8751. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8752. break;
  8753. case 1:
  8754. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8755. break;
  8756. case 2:
  8757. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8758. break;
  8759. }
  8760. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8761. spawn->SetSpawnScript(string(script));
  8762. break;
  8763. }
  8764. }
  8765. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8766. lua_interface->SetSpawnValue(state, spawn);
  8767. group.push_back(spawn);
  8768. }
  8769. else {
  8770. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8771. safe_delete(spawn);
  8772. }
  8773. }
  8774. }
  8775. if (!group.empty()) {
  8776. lua_createtable(state, group.size(), 0);
  8777. int newTable = lua_gettop(state);
  8778. for (int32 i = 0; i < group.size(); i++) {
  8779. lua_interface->SetSpawnValue(state, group[i]);
  8780. lua_rawseti(state, newTable, i + 1);
  8781. }
  8782. }
  8783. else
  8784. lua_pushnil(state);
  8785. return 1;
  8786. }
  8787. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8788. if (!lua_interface)
  8789. return 0;
  8790. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8791. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8792. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8793. if (!spawn) {
  8794. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. if (anim_id == 0) {
  8798. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. if (leeway == 0)
  8802. leeway = 5000;
  8803. spawn->SetSpawnAnim(anim_id);
  8804. spawn->SetSpawnAnimLeeway(leeway);
  8805. return 0;
  8806. }
  8807. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8808. if (!lua_interface)
  8809. return 0;
  8810. Spawn* player = lua_interface->GetSpawn(state);
  8811. if (!player) {
  8812. return 0;
  8813. }
  8814. Client* client = player->GetZone()->GetClientBySpawn(player);
  8815. if (!client) {
  8816. return 0;
  8817. }
  8818. lua_interface->SetInt32Value(state, client->GetVersion());
  8819. return 1;
  8820. }
  8821. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8822. if (!lua_interface)
  8823. return 0;
  8824. Item* item = lua_interface->GetItem(state);
  8825. if (!item) {
  8826. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8827. return 0;
  8828. }
  8829. lua_interface->SetInt32Value(state, item->details.item_id);
  8830. return 1;
  8831. }
  8832. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8833. if (!lua_interface)
  8834. return 0;
  8835. Spawn* spawn = lua_interface->GetSpawn(state);
  8836. if (!spawn) {
  8837. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8838. return 0;
  8839. }
  8840. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8841. return 1;
  8842. }
  8843. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8844. if (!lua_interface)
  8845. return 0;
  8846. Spawn* spawn = lua_interface->GetSpawn(state);
  8847. if (!spawn) {
  8848. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8849. return 0;
  8850. }
  8851. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8852. return 1;
  8853. }
  8854. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8855. if (!lua_interface)
  8856. return 0;
  8857. Spawn* spawn = lua_interface->GetSpawn(state);
  8858. if (!spawn) {
  8859. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8860. return 0;
  8861. }
  8862. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8863. return 1;
  8864. }
  8865. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8866. if (!lua_interface)
  8867. return 0;
  8868. Spawn* spawn = lua_interface->GetSpawn(state);
  8869. if (!spawn) {
  8870. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8871. return 0;
  8872. }
  8873. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8874. return 1;
  8875. }
  8876. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8877. if (!lua_interface)
  8878. return 0;
  8879. Spawn* spawn = lua_interface->GetSpawn(state);
  8880. float pct = lua_interface->GetFloatValue(state, 2);
  8881. if (!spawn) {
  8882. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8883. return 0;
  8884. }
  8885. if (pct == 0) {
  8886. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8887. return 0;
  8888. }
  8889. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8890. lua_interface->SetInt32Value(state, amount);
  8891. return 1;
  8892. }
  8893. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8894. if (!lua_interface)
  8895. return 0;
  8896. Spawn* spawn = lua_interface->GetSpawn(state);
  8897. float pct = lua_interface->GetFloatValue(state, 2);
  8898. if (!spawn) {
  8899. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8900. return 0;
  8901. }
  8902. if (pct == 0) {
  8903. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8904. return 0;
  8905. }
  8906. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8907. lua_interface->SetInt32Value(state, amount);
  8908. return 1;
  8909. }
  8910. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8911. if (!lua_interface)
  8912. return 0;
  8913. Spawn* spawn = lua_interface->GetSpawn(state);
  8914. if (!spawn) {
  8915. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8916. return 0;
  8917. }
  8918. if (!spawn->IsPlayer()) {
  8919. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8920. return 0;
  8921. }
  8922. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8923. return 1;
  8924. }
  8925. int EQ2Emu_lua_Evac(lua_State* state) {
  8926. if (!lua_interface)
  8927. return 0;
  8928. Spawn* target = lua_interface->GetSpawn(state);
  8929. if (target) {
  8930. float x = target->GetZone()->GetSafeX();
  8931. float y = target->GetZone()->GetSafeY();
  8932. float z = target->GetZone()->GetSafeZ();
  8933. float h = target->GetZone()->GetSafeHeading();
  8934. target->SetX(x);
  8935. target->SetY(y);
  8936. target->SetZ(z);
  8937. target->SetHeading(h);
  8938. target->SetSpawnOrigX(target->GetX());
  8939. target->SetSpawnOrigY(target->GetY());
  8940. target->SetSpawnOrigZ(target->GetZ());
  8941. target->SetSpawnOrigHeading(target->GetHeading());
  8942. if (target->IsPlayer()) {
  8943. Client* client = target->GetZone()->GetClientBySpawn(target);
  8944. if (client) {
  8945. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8946. if (packet)
  8947. {
  8948. packet->setDataByName("x", x);
  8949. packet->setDataByName("y", y);
  8950. packet->setDataByName("z", z);
  8951. client->QueuePacket(packet->serialize());
  8952. safe_delete(packet);
  8953. }
  8954. }
  8955. }
  8956. }
  8957. else {
  8958. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8959. ZoneServer* zone = spell->caster->GetZone();
  8960. float x = spell->caster->GetZone()->GetSafeX();
  8961. float y = spell->caster->GetZone()->GetSafeY();
  8962. float z = spell->caster->GetZone()->GetSafeZ();
  8963. float h = spell->caster->GetZone()->GetSafeHeading();
  8964. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8965. for (int32 i = 0; i < spell->targets.size(); i++) {
  8966. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8967. if (!target2)
  8968. continue;
  8969. target2->SetX(x);
  8970. target2->SetY(y);
  8971. target2->SetZ(z);
  8972. target2->SetHeading(h);
  8973. target2->SetSpawnOrigX(target2->GetX());
  8974. target2->SetSpawnOrigY(target2->GetY());
  8975. target2->SetSpawnOrigZ(target2->GetZ());
  8976. target2->SetSpawnOrigHeading(target2->GetHeading());
  8977. if (target2->IsPlayer()) {
  8978. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8979. if (client) {
  8980. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8981. if (packet)
  8982. {
  8983. client->SetReloadingZone(true);
  8984. packet->setDataByName("x", x);
  8985. packet->setDataByName("y", y);
  8986. packet->setDataByName("z", z);
  8987. client->QueuePacket(packet->serialize());
  8988. safe_delete(packet);
  8989. }
  8990. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8991. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8992. }
  8993. }
  8994. }
  8995. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8996. }
  8997. return 0;
  8998. }
  8999. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9000. if (!lua_interface)
  9001. return 0;
  9002. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9003. if (!luaspell) {
  9004. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9005. return 0;
  9006. }
  9007. int8 tier = luaspell->spell->GetSpellTier();
  9008. lua_interface->SetInt32Value(state, tier);
  9009. return 1;
  9010. }
  9011. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9012. if (!lua_interface)
  9013. return 0;
  9014. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9015. if (!luaspell) {
  9016. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9017. return 0;
  9018. }
  9019. int32 spell_id = luaspell->spell->GetSpellID();
  9020. lua_interface->SetInt32Value(state, spell_id);
  9021. return 1;
  9022. }
  9023. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9024. if (!lua_interface)
  9025. return 0;
  9026. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9027. if (!spawn) {
  9028. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9029. return 0;
  9030. }
  9031. if (!spawn->IsPlayer()) {
  9032. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9033. return 0;
  9034. }
  9035. ZoneServer* zone = spawn->GetZone();
  9036. if (!zone) {
  9037. return 0;
  9038. }
  9039. Client* client = zone->GetClientBySpawn(spawn);
  9040. if (!client) {
  9041. return 0;
  9042. }
  9043. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9044. return 0;
  9045. }
  9046. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9047. if (!lua_interface)
  9048. return 0;
  9049. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9050. if (!spawn) {
  9051. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. if (!spawn->IsPlayer()) {
  9055. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9056. return 0;
  9057. }
  9058. ZoneServer* zone = spawn->GetZone();
  9059. if (!zone) {
  9060. return 0;
  9061. }
  9062. Client* client = zone->GetClientBySpawn(spawn);
  9063. if (!client) {
  9064. return 0;
  9065. }
  9066. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9067. return 0;
  9068. }
  9069. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9070. if (!lua_interface)
  9071. return 0;
  9072. Spawn* caster = lua_interface->GetSpawn(state);
  9073. Spawn* target = lua_interface->GetSpawn(state, 2);
  9074. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9075. string spell_name = lua_interface->GetStringValue(state, 4);
  9076. if (!caster) {
  9077. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9078. return 0;
  9079. }
  9080. if (!caster->IsEntity()) {
  9081. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9082. return 0;
  9083. }
  9084. if (!target) {
  9085. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9086. return 0;
  9087. }
  9088. if (!target->IsEntity()) {
  9089. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9090. return 0;
  9091. }
  9092. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9093. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9094. return 0;
  9095. }
  9096. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9097. if (!lua_interface)
  9098. return 0;
  9099. Spawn* player = lua_interface->GetSpawn(state);
  9100. int32 amount = lua_interface->GetInt32Value(state, 2);
  9101. if (player && player->IsPlayer() && amount > 0) {
  9102. ((Player*)player)->AddXP(amount);
  9103. ((Player*)player)->SetCharSheetChanged(true);
  9104. Client* client = player->GetZone()->GetClientBySpawn(player);
  9105. if (client) {
  9106. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9107. }
  9108. }
  9109. return 0;
  9110. }
  9111. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9112. if (!lua_interface)
  9113. return 0;
  9114. Spawn* player = lua_interface->GetSpawn(state);
  9115. int8 type = lua_interface->GetInt8Value(state, 2);
  9116. string text = lua_interface->GetStringValue(state, 3);
  9117. Client* client = 0;
  9118. if (player && player->IsPlayer())
  9119. client = player->GetZone()->GetClientBySpawn(player);
  9120. if (!client || text.length() == 0) {
  9121. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9122. return 0;
  9123. }
  9124. client->SimpleMessage(type, text.c_str());
  9125. return 0;
  9126. }
  9127. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Spawn* player = lua_interface->GetSpawn(state);
  9131. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9132. Client* client = 0;
  9133. if (player && player->IsPlayer())
  9134. client = player->GetZone()->GetClientBySpawn(player);
  9135. if (!client || !spawn) {
  9136. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9137. return 0;
  9138. }
  9139. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9140. if (!items) {
  9141. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9142. return 0;
  9143. }
  9144. client->Loot(spawn->GetLootCoins(), items, spawn);
  9145. return 0;
  9146. }
  9147. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9148. if (!lua_interface)
  9149. return 0;
  9150. Spawn* spawnref = lua_interface->GetSpawn(state);
  9151. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9152. if (spawn_id > 0 && spawnref) {
  9153. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9154. if (spawns.size() == 0) {
  9155. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9156. return 0;
  9157. }
  9158. Spawn* spawn = 0;
  9159. int16 index = MakeRandomInt(0, spawns.size());
  9160. if (index >= spawns.size() || index < 0)
  9161. index = 0;
  9162. spawn = spawns[index];
  9163. lua_interface->SetSpawnValue(state, spawn);
  9164. return 1;
  9165. }
  9166. else {
  9167. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9168. }
  9169. return 0;
  9170. }
  9171. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9172. Spawn* player = lua_interface->GetSpawn(state);
  9173. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9174. string name = lua_interface->GetStringValue(state, 3);
  9175. float distance = lua_interface->GetFloatValue(state, 4);
  9176. string command = lua_interface->GetStringValue(state, 5);
  9177. string error_text = lua_interface->GetStringValue(state, 6);
  9178. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9179. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9180. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9181. if (distance == 0)
  9182. distance = 10.0f;
  9183. if (command.length() == 0)
  9184. command = name;
  9185. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9186. if (spawns.size() == 0) {
  9187. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9188. return 0;
  9189. }
  9190. Spawn* spawn = 0;
  9191. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9192. spawn = *itr;
  9193. if (spawn) {
  9194. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9195. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9196. }
  9197. }
  9198. }
  9199. return 0;
  9200. }
  9201. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9202. if (!lua_interface)
  9203. return 0;
  9204. Client* client = 0;
  9205. Spawn* player = lua_interface->GetSpawn(state);
  9206. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9207. if (player && player->IsPlayer() && player->GetZone())
  9208. client = player->GetZone()->GetClientBySpawn(player);
  9209. else{
  9210. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9211. return 0;
  9212. }
  9213. if (client) {
  9214. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9215. if (packet) {
  9216. packet->setDataByName("goal_num", goal_num);
  9217. client->QueuePacket(packet->serialize());
  9218. safe_delete(packet);
  9219. }
  9220. }
  9221. return 0;
  9222. }
  9223. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9224. if (!lua_interface)
  9225. return 0;
  9226. Client* client = 0;
  9227. Spawn* player = lua_interface->GetSpawn(state);
  9228. if (player && player->IsPlayer() && player->GetZone())
  9229. client = player->GetZone()->GetClientBySpawn(player);
  9230. else {
  9231. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9232. return 0;
  9233. }
  9234. if (client) {
  9235. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9236. }
  9237. return 0;
  9238. }
  9239. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9240. if (!lua_interface)
  9241. return 0;
  9242. Client* client = 0;
  9243. Spawn* player = lua_interface->GetSpawn(state);
  9244. float duration = lua_interface->GetFloatValue(state, 2);
  9245. string text = lua_interface->GetStringValue(state, 3);
  9246. string voice = lua_interface->GetStringValue(state, 4);
  9247. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9248. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9249. string signal = lua_interface->GetStringValue(state, 7);
  9250. string goal1 = lua_interface->GetStringValue(state, 8);
  9251. string task1 = lua_interface->GetStringValue(state, 9);
  9252. string goal2 = lua_interface->GetStringValue(state, 10);
  9253. string task2 = lua_interface->GetStringValue(state, 11);
  9254. string goal3 = lua_interface->GetStringValue(state, 12);
  9255. string task3 = lua_interface->GetStringValue(state, 13);
  9256. string goal4 = lua_interface->GetStringValue(state, 14);
  9257. string task4 = lua_interface->GetStringValue(state, 15);
  9258. if (!player) {
  9259. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9260. return 0;
  9261. }
  9262. if (!player->IsPlayer()) {
  9263. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9264. return 0;
  9265. }
  9266. else
  9267. client = ((Player*)player)->GetClient();
  9268. if (!client) {
  9269. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9270. return 0;
  9271. }
  9272. if (text.length() == 0) {
  9273. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9274. return 0;
  9275. }
  9276. if (duration >= 0 && duration < 2)
  9277. duration = 2;
  9278. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9279. if (packet) {
  9280. packet->setDataByName("open_seconds_max", duration);
  9281. packet->setDataByName("text", text.c_str());
  9282. packet->setDataByName("voice", voice.c_str());
  9283. int8 num_goals = 1;
  9284. if (task2.length() > 0)
  9285. num_goals++;
  9286. if (task3.length() > 0)
  9287. num_goals++;
  9288. if (task4.length() > 0)
  9289. num_goals++;
  9290. packet->setArrayLengthByName("num_goals", num_goals);
  9291. for (int8 i = 0; i < num_goals; i++) {
  9292. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9293. }
  9294. if (goal1.length() > 0)
  9295. packet->setArrayDataByName("goal_text", goal1.c_str());
  9296. if (goal2.length() > 0)
  9297. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9298. if (goal3.length() > 0)
  9299. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9300. if (goal4.length() > 0)
  9301. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9302. packet->setSubArrayDataByName("task_text", task1.c_str());
  9303. if (task2.length() > 0)
  9304. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9305. if (task3.length() > 0)
  9306. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9307. if (task4.length() > 0)
  9308. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9309. packet->setDataByName("complete_sound", "click");
  9310. packet->setDataByName("signal", signal.c_str());
  9311. packet->setDataByName("voice_key1", voice_key1);
  9312. packet->setDataByName("voice_key2", voice_key2);
  9313. client->QueuePacket(packet->serialize());
  9314. safe_delete(packet);
  9315. }
  9316. return 0;
  9317. }
  9318. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9319. if (!lua_interface)
  9320. return 0;
  9321. Client* client = 0;
  9322. Spawn* player = lua_interface->GetSpawn(state);
  9323. string window = lua_interface->GetStringValue(state, 2);
  9324. int8 show = lua_interface->GetInt8Value(state, 3);
  9325. if (!player) {
  9326. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9327. return 0;
  9328. }
  9329. if (!player->IsPlayer()) {
  9330. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9331. return 0;
  9332. }
  9333. else
  9334. client = ((Player*)player)->GetClient();
  9335. if (!client) {
  9336. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9337. return 0;
  9338. }
  9339. if (window.length() == 0) {
  9340. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9341. return 0;
  9342. }
  9343. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9344. if (packet) {
  9345. packet->setDataByName("window", window.c_str());
  9346. packet->setDataByName("show", show);
  9347. client->QueuePacket(packet->serialize());
  9348. safe_delete(packet);
  9349. }
  9350. return 0;
  9351. }
  9352. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9353. //See GameEvents.txt for options that can be used for this function
  9354. if (!lua_interface)
  9355. return 0;
  9356. Client* client = 0;
  9357. Spawn* player = lua_interface->GetSpawn(state);
  9358. string event_name = lua_interface->GetStringValue(state, 2);
  9359. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9360. if (!player || !player->IsPlayer()) {
  9361. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9362. return 0;
  9363. }
  9364. if (player->GetZone())
  9365. client = player->GetZone()->GetClientBySpawn(player);
  9366. if (!client) {
  9367. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9368. return 0;
  9369. }
  9370. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9371. if (packet) {
  9372. packet->setDataByName("event_name", event_name.c_str());
  9373. packet->setDataByName("enabled", enabled);
  9374. client->QueuePacket(packet->serialize());
  9375. safe_delete(packet);
  9376. }
  9377. return 0;
  9378. }
  9379. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9380. if (!lua_interface)
  9381. return 0;
  9382. Spawn* player = lua_interface->GetSpawn(state);
  9383. if (player && player->IsPlayer()) {
  9384. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9385. return 1;
  9386. }
  9387. return 0;
  9388. }
  9389. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9390. if (!lua_interface)
  9391. return 0;
  9392. Spawn* player = lua_interface->GetSpawn(state);
  9393. int8 step = lua_interface->GetInt8Value(state, 2);
  9394. if (player && player->IsPlayer() && step > 0) {
  9395. ((Player*)player)->SetTutorialStep(step);
  9396. }
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Client* client = 0;
  9403. Spawn* player = lua_interface->GetSpawn(state);
  9404. string window = lua_interface->GetStringValue(state, 2);
  9405. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9406. if (!player) {
  9407. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9408. return 0;
  9409. }
  9410. if (!player->IsPlayer()) {
  9411. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9412. return 0;
  9413. }
  9414. else
  9415. client = ((Player*)player)->GetClient();
  9416. if (!client) {
  9417. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9418. return 0;
  9419. }
  9420. if (window.length() == 0) {
  9421. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9422. return 0;
  9423. }
  9424. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9425. if (packet) {
  9426. packet->setDataByName("window", window.c_str());
  9427. packet->setDataByName("flash_seconds", flash_seconds);
  9428. client->QueuePacket(packet->serialize());
  9429. safe_delete(packet);
  9430. }
  9431. return 0;
  9432. }
  9433. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9434. if (!lua_interface)
  9435. return 0;
  9436. Spawn* spawn = lua_interface->GetSpawn(state);
  9437. Spawn* target = lua_interface->GetSpawn(state, 2);
  9438. if (spawn && target)
  9439. return spawn->CheckLoS(target);
  9440. return 0;
  9441. }
  9442. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9443. if (!lua_interface)
  9444. return 0;
  9445. Spawn* spawn = lua_interface->GetSpawn(state);
  9446. float x = lua_interface->GetFloatValue(state, 2);
  9447. float y = lua_interface->GetFloatValue(state, 3);
  9448. float z = lua_interface->GetFloatValue(state, 4);
  9449. if (spawn)
  9450. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9451. return 0;
  9452. }
  9453. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9454. if (!lua_interface)
  9455. return 0;
  9456. ZoneServer* zone = lua_interface->GetZone(state);
  9457. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9458. if (zone)
  9459. zone->SetExpansionFlag(xpackFlag);
  9460. return 0;
  9461. }
  9462. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9463. if (!lua_interface)
  9464. return 0;
  9465. ZoneServer* zone = lua_interface->GetZone(state);
  9466. if (zone) {
  9467. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9468. return 1;
  9469. }
  9470. return 0;
  9471. }
  9472. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9473. if (!lua_interface)
  9474. return 0;
  9475. ZoneServer* zone = lua_interface->GetZone(state);
  9476. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9477. if (zone)
  9478. zone->SetHolidayFlag(holidayFlag);
  9479. return 0;
  9480. }
  9481. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9482. if (!lua_interface)
  9483. return 0;
  9484. ZoneServer* zone = lua_interface->GetZone(state);
  9485. if (zone) {
  9486. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9487. return 1;
  9488. }
  9489. return 0;
  9490. }
  9491. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9492. if (!lua_interface)
  9493. return 0;
  9494. Spawn* spawn = lua_interface->GetSpawn(state);
  9495. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9496. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9497. float distance = lua_interface->GetFloatValue(state, 4);
  9498. string in_range_function = lua_interface->GetStringValue(state, 5);
  9499. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9500. if (spawn && distance > 0 && in_range_function.length() > 0)
  9501. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9502. return 0;
  9503. }
  9504. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9505. if (!lua_interface)
  9506. return 0;
  9507. Spawn* spawn = lua_interface->GetSpawn(state);
  9508. Spawn* target = lua_interface->GetSpawn(state, 2);
  9509. if (spawn && target)
  9510. {
  9511. if (spawn->IsPlayer() && target->IsEntity())
  9512. {
  9513. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9514. return 1;
  9515. }
  9516. else if (spawn->IsEntity() && target->IsEntity())
  9517. {
  9518. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9519. return 1;
  9520. }
  9521. }
  9522. return 0;
  9523. }
  9524. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9525. if (!lua_interface)
  9526. return 0;
  9527. Spawn* spawn = lua_interface->GetSpawn(state);
  9528. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9529. if (spawn && spawn->IsEntity())
  9530. {
  9531. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9532. if (spawn->IsPlayer())
  9533. {
  9534. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9535. if (client)
  9536. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9537. }
  9538. }
  9539. return 0;
  9540. }
  9541. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9542. if (!lua_interface)
  9543. return 0;
  9544. Spawn* spawn = lua_interface->GetSpawn(state);
  9545. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9546. if (spawn && spawn->IsEntity())
  9547. {
  9548. ((Entity*)spawn)->SetSeeHideSpell(val);
  9549. if (spawn->IsPlayer())
  9550. {
  9551. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9552. if (client)
  9553. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9554. }
  9555. }
  9556. return 0;
  9557. }
  9558. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9559. {
  9560. if (!lua_interface)
  9561. return 0;
  9562. Spawn* player = lua_interface->GetSpawn(state);
  9563. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9564. string command = lua_interface->GetStringValue(state, 3);
  9565. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9566. lua_interface->ResetFunctionStack(state);
  9567. if (spawn && player && player->IsPlayer())
  9568. {
  9569. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9570. bool res = false;
  9571. if (cmd)
  9572. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9573. lua_interface->SetBooleanValue(state, res);
  9574. return 1;
  9575. }
  9576. return 0;
  9577. }
  9578. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9579. {
  9580. if (!lua_interface)
  9581. return 0;
  9582. Spawn* spawn = lua_interface->GetSpawn(state);
  9583. int32 charID = lua_interface->GetInt32Value(state, 2);
  9584. string command = lua_interface->GetStringValue(state, 3);
  9585. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9586. lua_interface->ResetFunctionStack(state);
  9587. if (spawn && charID)
  9588. {
  9589. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9590. bool res = false;
  9591. if (cmd)
  9592. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9593. lua_interface->SetBooleanValue(state, res);
  9594. return 1;
  9595. }
  9596. return 0;
  9597. }
  9598. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9599. {
  9600. if (!lua_interface)
  9601. return 0;
  9602. Spawn* spawn = lua_interface->GetSpawn(state);
  9603. string command = lua_interface->GetStringValue(state, 2);
  9604. lua_interface->ResetFunctionStack(state);
  9605. if (spawn && command.length() > 0)
  9606. spawn->RemovePrimaryEntityCommand(command.c_str());
  9607. return 0;
  9608. }
  9609. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9610. if (!lua_interface)
  9611. return 0;
  9612. Spawn* spawn = lua_interface->GetSpawn(state);
  9613. float distance = lua_interface->GetFloatValue(state, 2);
  9614. string command = lua_interface->GetStringValue(state, 3);
  9615. Spawn* player = lua_interface->GetSpawn(state, 4);
  9616. lua_interface->ResetFunctionStack(state);
  9617. if (spawn) {
  9618. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9619. }
  9620. return 0;
  9621. }
  9622. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9623. if (!lua_interface)
  9624. return 0;
  9625. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9626. Spawn* spawn = lua_interface->GetSpawn(state);
  9627. Spawn* player = lua_interface->GetSpawn(state, 2);
  9628. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9629. lua_interface->ResetFunctionStack(state);
  9630. if (spawn && player && transport_id && player->IsPlayer()) {
  9631. Client* client = 0;
  9632. if (player && player->IsPlayer())
  9633. client = player->GetZone()->GetClientBySpawn(player);
  9634. if (!client)
  9635. return 0;
  9636. vector<TransportDestination*> destinations;
  9637. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9638. if (destinations.size())
  9639. {
  9640. client->SetTemporaryTransportID(transport_id);
  9641. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9642. }
  9643. else
  9644. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9645. }
  9646. return 0;
  9647. }
  9648. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9649. if (!lua_interface)
  9650. return 0;
  9651. Spawn* player = lua_interface->GetSpawn(state);
  9652. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9653. lua_interface->ResetFunctionStack(state);
  9654. if (player && player->IsPlayer()) {
  9655. Client* client = 0;
  9656. if (player && player->IsPlayer())
  9657. client = player->GetZone()->GetClientBySpawn(player);
  9658. if (!client)
  9659. return 0;
  9660. client->SetTemporaryTransportID(transport_id);
  9661. }
  9662. return 0;
  9663. }
  9664. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9665. if (!lua_interface)
  9666. return 0;
  9667. Spawn* player = lua_interface->GetSpawn(state);
  9668. lua_interface->ResetFunctionStack(state);
  9669. if (player && player->IsPlayer()) {
  9670. Client* client = 0;
  9671. if (player && player->IsPlayer())
  9672. client = player->GetZone()->GetClientBySpawn(player);
  9673. if (!client)
  9674. return 0;
  9675. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9676. return 1;
  9677. }
  9678. return 0;
  9679. }
  9680. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9681. if (!lua_interface)
  9682. return 0;
  9683. Spawn* spawn = lua_interface->GetSpawn(state);
  9684. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9685. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9686. if (!spawn) {
  9687. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9688. return 0;
  9689. }
  9690. if (!spawn->IsEntity()) {
  9691. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9692. return 0;
  9693. }
  9694. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9695. {
  9696. 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);
  9697. return 0;
  9698. }
  9699. lua_interface->ResetFunctionStack(state);
  9700. if (spell && spell->targets.size() > 0) {
  9701. ZoneServer* zone = spell->caster->GetZone();
  9702. for (int8 i = 0; i < spell->targets.size(); i++) {
  9703. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9704. if (target && target->IsEntity()) {
  9705. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9706. if (target->IsPlayer())
  9707. ((Player*)target)->SetCharSheetChanged(true);
  9708. }
  9709. }
  9710. }
  9711. else {
  9712. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9713. if (spawn->IsPlayer())
  9714. ((Player*)spawn)->SetCharSheetChanged(true);
  9715. }
  9716. return 0;
  9717. }
  9718. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9719. if (!lua_interface)
  9720. return 0;
  9721. Spawn* spawn = lua_interface->GetSpawn(state);
  9722. lua_interface->ResetFunctionStack(state);
  9723. if (!spawn) {
  9724. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9725. return 0;
  9726. }
  9727. if (!spawn->IsEntity()) {
  9728. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9729. return 0;
  9730. }
  9731. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9732. return 1;
  9733. }
  9734. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9735. if (!lua_interface)
  9736. return 0;
  9737. int32 spell_id = lua_interface->GetInt32Value(state);
  9738. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9739. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9740. if (spell_id > 0) {
  9741. if (spell_tier == 0)
  9742. spell_tier = 1;
  9743. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9744. LuaSpell* lua_spell = 0;
  9745. if(custom_lua_script.size() > 0)
  9746. {
  9747. // attempt to load the custom script since it isn't already loaded
  9748. // we will re-obtain the lua_spell further below
  9749. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9750. {
  9751. 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());
  9752. lua_interface->LoadLuaSpell(custom_lua_script);
  9753. }
  9754. }
  9755. else
  9756. custom_lua_script = spell->GetSpellData()->lua_script;
  9757. if (!lua_spell && lua_interface)
  9758. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9759. if (!lua_spell)
  9760. {
  9761. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9762. return 0;
  9763. }
  9764. lua_spell->spell = new Spell(spell);
  9765. lua_interface->AddCustomSpell(lua_spell);
  9766. lua_interface->SetSpellValue(state, lua_spell);
  9767. return 1;
  9768. }
  9769. return 0;
  9770. }
  9771. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9772. if (!lua_interface)
  9773. return 0;
  9774. LuaSpell* spell = lua_interface->GetSpell(state);
  9775. string field = lua_interface->GetStringValue(state, 2);
  9776. if (!spell) {
  9777. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9778. return 0;
  9779. }
  9780. if (!spell->spell || !spell->spell->GetSpellData()) {
  9781. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9782. return 0;
  9783. }
  9784. boost::to_lower(field);
  9785. return spell->spell->GetSpellData(state, field);
  9786. }
  9787. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9788. if (!lua_interface)
  9789. return 0;
  9790. LuaSpell* spell = lua_interface->GetSpell(state);
  9791. string field = lua_interface->GetStringValue(state, 2);
  9792. int8 fieldArg = 3; // field value after the initial set
  9793. if (!spell) {
  9794. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9795. return 0;
  9796. }
  9797. if (!spell->spell || !spell->spell->GetSpellData()) {
  9798. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9799. return 0;
  9800. }
  9801. boost::to_lower(field);
  9802. bool valSet = false;
  9803. spell->spell->SetSpellData(state, field, fieldArg);
  9804. return valSet;
  9805. }
  9806. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9807. if (!lua_interface)
  9808. return 0;
  9809. LuaSpell* spell = lua_interface->GetSpell(state);
  9810. int8 idx = lua_interface->GetInt32Value(state, 2);
  9811. if (!spell) {
  9812. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9813. return 0;
  9814. }
  9815. if (!spell->spell || !spell->spell->GetSpellData()) {
  9816. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9817. return 0;
  9818. }
  9819. if (spell->spell->lua_data.size() <= idx)
  9820. {
  9821. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9822. return 0;
  9823. }
  9824. bool setVal = true;
  9825. LUAData* data = spell->spell->lua_data[idx];
  9826. switch (data->type)
  9827. {
  9828. case 0:
  9829. {
  9830. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9831. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9832. data->int_value = value;
  9833. data->int_value2 = value2;
  9834. break;
  9835. }
  9836. case 1:
  9837. {
  9838. float value = lua_interface->GetFloatValue(state, 3);
  9839. float value2 = lua_interface->GetFloatValue(state, 4);
  9840. data->float_value = value;
  9841. data->float_value2 = value2;
  9842. break;
  9843. }
  9844. case 2:
  9845. {
  9846. bool value = lua_interface->GetBooleanValue(state, 3);
  9847. data->bool_value = value;
  9848. break;
  9849. }
  9850. case 3:
  9851. {
  9852. string value = lua_interface->GetStringValue(state, 3);
  9853. string value2 = lua_interface->GetStringValue(state, 4);
  9854. data->string_value = value;
  9855. data->string_value2 = value2;
  9856. break;
  9857. }
  9858. default:
  9859. setVal = false;
  9860. }
  9861. return setVal;
  9862. }
  9863. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9864. if (!lua_interface)
  9865. return 0;
  9866. LuaSpell* spell = lua_interface->GetSpell(state);
  9867. int8 idx = lua_interface->GetInt32Value(state, 2);
  9868. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9869. if (!spell) {
  9870. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9871. return 0;
  9872. }
  9873. if (!spell->spell || !spell->spell->GetSpellData()) {
  9874. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9875. return 0;
  9876. }
  9877. if (spell->spell->lua_data.size() <= idx)
  9878. {
  9879. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9880. return 0;
  9881. }
  9882. bool setVal = true;
  9883. LUAData* data = spell->spell->lua_data[idx];
  9884. switch (data->type)
  9885. {
  9886. case 0:
  9887. {
  9888. if(!secondfield)
  9889. lua_interface->SetSInt32Value(state, data->int_value);
  9890. else
  9891. lua_interface->SetSInt32Value(state, data->int_value2);
  9892. break;
  9893. }
  9894. case 1:
  9895. {
  9896. if (!secondfield)
  9897. lua_interface->SetFloatValue(state, data->float_value);
  9898. else
  9899. lua_interface->SetFloatValue(state, data->float_value2);
  9900. break;
  9901. }
  9902. case 2:
  9903. {
  9904. lua_interface->SetBooleanValue(state, data->bool_value);
  9905. break;
  9906. }
  9907. case 3:
  9908. {
  9909. if (!secondfield)
  9910. lua_interface->SetStringValue(state, data->string_value.c_str());
  9911. else
  9912. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9913. break;
  9914. }
  9915. default:
  9916. setVal = false;
  9917. }
  9918. return setVal;
  9919. }
  9920. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9921. if (!lua_interface)
  9922. return 0;
  9923. LuaSpell* spell = lua_interface->GetSpell(state);
  9924. int8 idx = lua_interface->GetInt32Value(state, 2);
  9925. string field = lua_interface->GetStringValue(state, 3);
  9926. boost::to_lower(field);
  9927. if (!spell) {
  9928. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9929. return 0;
  9930. }
  9931. if (!spell->spell || !spell->spell->GetSpellData()) {
  9932. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9933. return 0;
  9934. }
  9935. if (spell->spell->effects.size() <= idx)
  9936. {
  9937. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9938. return 0;
  9939. }
  9940. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9941. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9942. if (field == "description")
  9943. effect->description = string(lua_interface->GetStringValue(state, 4));
  9944. else if (field == "bullet")
  9945. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9946. else if (field == "percentage")
  9947. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9948. else // no match
  9949. return 0;
  9950. return 1;
  9951. }
  9952. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9953. if (!lua_interface)
  9954. return 0;
  9955. LuaSpell* spell = lua_interface->GetSpell(state);
  9956. int8 idx = lua_interface->GetInt32Value(state, 2);
  9957. string field = lua_interface->GetStringValue(state, 3);
  9958. boost::to_lower(field);
  9959. if (!spell) {
  9960. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9961. return 0;
  9962. }
  9963. if (!spell->spell || !spell->spell->GetSpellData()) {
  9964. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9965. return 0;
  9966. }
  9967. if (spell->spell->effects.size() <= idx)
  9968. {
  9969. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9970. return 0;
  9971. }
  9972. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9973. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9974. if (field == "description")
  9975. lua_interface->SetStringValue(state, effect->description.c_str());
  9976. else if (field == "bullet")
  9977. lua_interface->SetInt32Value(state, effect->subbullet);
  9978. else if (field == "percentage")
  9979. lua_interface->SetInt32Value(state, effect->percentage);
  9980. else // no match
  9981. return 0;
  9982. return 1;
  9983. }
  9984. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9985. if (!lua_interface)
  9986. return 0;
  9987. LuaSpell* spell = lua_interface->GetSpell(state);
  9988. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9989. Spawn* target = lua_interface->GetSpawn(state, 3);
  9990. if (!target) {
  9991. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9992. return 0;
  9993. }
  9994. if (!target->IsEntity()) {
  9995. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9996. return 0;
  9997. }
  9998. if (!spell) {
  9999. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10000. return 0;
  10001. }
  10002. if (caster && !caster->IsEntity()) {
  10003. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10004. return 0;
  10005. }
  10006. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10007. return 0;
  10008. }
  10009. int EQ2Emu_lua_InWater(lua_State* state) {
  10010. if (!lua_interface)
  10011. return 0;
  10012. Spawn* spawn = lua_interface->GetSpawn(state);
  10013. lua_interface->ResetFunctionStack(state);
  10014. if (spawn) {
  10015. lua_interface->SetBooleanValue(state, spawn->InWater());
  10016. return 1;
  10017. }
  10018. return 0;
  10019. }
  10020. int EQ2Emu_lua_InLava(lua_State* state) {
  10021. if (!lua_interface)
  10022. return 0;
  10023. Spawn* spawn = lua_interface->GetSpawn(state);
  10024. lua_interface->ResetFunctionStack(state);
  10025. if (spawn) {
  10026. lua_interface->SetBooleanValue(state, spawn->InLava());
  10027. return 1;
  10028. }
  10029. return 0;
  10030. }
  10031. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10032. if (!lua_interface)
  10033. return 0;
  10034. Spawn* attacker = lua_interface->GetSpawn(state);
  10035. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10036. int8 type = lua_interface->GetInt8Value(state, 3);
  10037. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10038. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10039. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10040. string spell_name = lua_interface->GetStringValue(state, 7);
  10041. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10042. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10043. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10044. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10045. lua_interface->ResetFunctionStack(state);
  10046. if (!attacker) {
  10047. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10048. return 0;
  10049. }
  10050. if (!attacker->IsEntity()) {
  10051. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10052. return 0;
  10053. }
  10054. if (!victim) {
  10055. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10056. return 0;
  10057. }
  10058. if (!victim->IsEntity()) {
  10059. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10060. return 0;
  10061. }
  10062. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10063. return 0;
  10064. }
  10065. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10066. if (!lua_interface)
  10067. return 0;
  10068. Spawn* spawn = lua_interface->GetSpawn(state);
  10069. lua_interface->ResetFunctionStack(state);
  10070. if (spawn) {
  10071. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10072. return 1;
  10073. }
  10074. return 0;
  10075. }
  10076. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10077. if (!lua_interface)
  10078. return 0;
  10079. Spawn* spawn = lua_interface->GetSpawn(state);
  10080. bool invul = lua_interface->GetBooleanValue(state, 2);
  10081. lua_interface->ResetFunctionStack(state);
  10082. if (spawn) {
  10083. spawn->SetInvulnerable(invul);
  10084. }
  10085. return 0;
  10086. }
  10087. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10088. if (!lua_interface)
  10089. return 0;
  10090. string category = lua_interface->GetStringValue(state);
  10091. string name = lua_interface->GetStringValue(state, 2);
  10092. lua_interface->ResetFunctionStack(state);
  10093. Rule *ret = 0;
  10094. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10095. lua_interface->SetBooleanValue(state, ret->GetBool());
  10096. return 1;
  10097. }
  10098. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10099. return 0;
  10100. }
  10101. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10102. if (!lua_interface)
  10103. return 0;
  10104. string category = lua_interface->GetStringValue(state);
  10105. string name = lua_interface->GetStringValue(state, 2);
  10106. lua_interface->ResetFunctionStack(state);
  10107. Rule *ret = 0;
  10108. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10109. lua_interface->SetInt32Value(state, ret->GetInt32());
  10110. return 1;
  10111. }
  10112. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10113. return 0;
  10114. }
  10115. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10116. if (!lua_interface)
  10117. return 0;
  10118. string category = lua_interface->GetStringValue(state);
  10119. string name = lua_interface->GetStringValue(state, 2);
  10120. lua_interface->ResetFunctionStack(state);
  10121. Rule *ret = 0;
  10122. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10123. lua_interface->SetFloatValue(state, ret->GetFloat());
  10124. return 1;
  10125. }
  10126. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10127. return 0;
  10128. }
  10129. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10130. if (!lua_interface)
  10131. return 0;
  10132. Spawn* spawn = lua_interface->GetSpawn(state);
  10133. string type = lua_interface->GetStringValue(state, 2);
  10134. lua_interface->ResetFunctionStack(state);
  10135. if (spawn) {
  10136. int res = 1;
  10137. boost::to_lower(type);
  10138. if(type == "assigned_aa")
  10139. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10140. else if ( type == "unassigned_aa")
  10141. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10142. else if ( type == "assigned_tradeskill_aa")
  10143. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10144. else if ( type == "unassigned_tradeskill_aa")
  10145. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10146. else if ( type == "assigned_prestige_aa")
  10147. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10148. else if ( type == "unassigned_prestige_aa")
  10149. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10150. else if ( type == "assigned_tradeskill_prestige_aa")
  10151. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10152. else if ( type == "unassigned_tradeskill_prestige_aa")
  10153. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10154. else
  10155. res = 0;
  10156. return res;
  10157. }
  10158. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10159. return 0;
  10160. }
  10161. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10162. if (!lua_interface)
  10163. return 0;
  10164. Spawn* spawn = lua_interface->GetSpawn(state);
  10165. string type = lua_interface->GetStringValue(state, 2);
  10166. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10167. lua_interface->ResetFunctionStack(state);
  10168. if (spawn) {
  10169. boost::to_lower(type);
  10170. if(type == "assigned_aa")
  10171. spawn->SetAssignedAA((sint16)value);
  10172. else if ( type == "unassigned_aa")
  10173. spawn->SetUnassignedAA((sint16)value);
  10174. else if ( type == "assigned_tradeskill_aa")
  10175. spawn->SetTradeskillAA((sint16)value);
  10176. else if ( type == "unassigned_tradeskill_aa")
  10177. spawn->SetUnassignedTradeskillAA((sint16)value);
  10178. else if ( type == "assigned_prestige_aa")
  10179. spawn->SetPrestigeAA((sint16)value);
  10180. else if ( type == "unassigned_prestige_aa")
  10181. spawn->SetUnassignedPrestigeAA((sint16)value);
  10182. else if ( type == "assigned_tradeskill_prestige_aa")
  10183. spawn->SetTradeskillPrestigeAA((sint16)value);
  10184. else if ( type == "unassigned_tradeskill_prestige_aa")
  10185. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10186. if(spawn->IsPlayer())
  10187. ((Player*)spawn)->SetCharSheetChanged(true);
  10188. }
  10189. return 0;
  10190. }
  10191. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10192. if (!lua_interface)
  10193. return 0;
  10194. string titleName = lua_interface->GetStringValue(state);
  10195. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10196. lua_interface->ResetFunctionStack(state);
  10197. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10198. lua_interface->SetSInt32Value(state, index);
  10199. return 1;
  10200. }
  10201. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10202. if (!lua_interface)
  10203. return 0;
  10204. Spawn* spawn = lua_interface->GetSpawn(state);
  10205. string titleName = lua_interface->GetStringValue(state, 2);
  10206. lua_interface->ResetFunctionStack(state);
  10207. if(!spawn->IsPlayer())
  10208. {
  10209. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10210. lua_interface->SetSInt32Value(state, -1);
  10211. return 1;
  10212. }
  10213. Player* player = (Player*)spawn;
  10214. // check if player already has the title, don't need to add twice
  10215. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10216. if ( playerHasTitle)
  10217. {
  10218. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10219. return 1;
  10220. }
  10221. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10222. if(!title)
  10223. {
  10224. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10225. lua_interface->SetSInt32Value(state, -1);
  10226. return 1;
  10227. }
  10228. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10229. if(returnIdx < 0)
  10230. {
  10231. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10232. }
  10233. lua_interface->SetSInt32Value(state, returnIdx);
  10234. player->GetClient()->SendTitleUpdate();
  10235. return 1;
  10236. }
  10237. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10238. if (!lua_interface)
  10239. return 0;
  10240. Spawn* spawn = lua_interface->GetSpawn(state);
  10241. string titleName = lua_interface->GetStringValue(state, 2);
  10242. lua_interface->ResetFunctionStack(state);
  10243. if(!spawn->IsPlayer())
  10244. {
  10245. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10246. return 0;
  10247. }
  10248. Player* player = (Player*)spawn;
  10249. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10250. if(!title)
  10251. {
  10252. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10253. return 0;
  10254. }
  10255. if(title->GetPrefix())
  10256. {
  10257. 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());
  10258. return 0;
  10259. }
  10260. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10261. player->GetClient()->SendTitleUpdate();
  10262. return 1;
  10263. }
  10264. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10265. if (!lua_interface)
  10266. return 0;
  10267. Spawn* spawn = lua_interface->GetSpawn(state);
  10268. string titleName = lua_interface->GetStringValue(state, 2);
  10269. lua_interface->ResetFunctionStack(state);
  10270. if(!spawn->IsPlayer())
  10271. {
  10272. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10273. return 0;
  10274. }
  10275. Player* player = (Player*)spawn;
  10276. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10277. if(!title)
  10278. {
  10279. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10280. return 0;
  10281. }
  10282. if(!title->GetPrefix())
  10283. {
  10284. 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());
  10285. return 0;
  10286. }
  10287. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10288. player->GetClient()->SendTitleUpdate();
  10289. return 1;
  10290. }
  10291. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10292. if (!lua_interface)
  10293. return 0;
  10294. Spawn* spawn = lua_interface->GetSpawn(state);
  10295. lua_interface->ResetFunctionStack(state);
  10296. if(!spawn->IsPlayer())
  10297. {
  10298. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10299. return 0;
  10300. }
  10301. Player* player = (Player*)spawn;
  10302. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10303. player->GetClient()->SendTitleUpdate();
  10304. return 1;
  10305. }
  10306. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10307. if (!lua_interface)
  10308. return 0;
  10309. Spawn* spawn = lua_interface->GetSpawn(state);
  10310. lua_interface->ResetFunctionStack(state);
  10311. if(!spawn->IsPlayer())
  10312. {
  10313. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10314. return 0;
  10315. }
  10316. Player* player = (Player*)spawn;
  10317. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10318. player->GetClient()->SendTitleUpdate();
  10319. return 1;
  10320. }
  10321. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10322. if (!lua_interface)
  10323. return 0;
  10324. Spawn* spawn = lua_interface->GetSpawn(state);
  10325. string field = lua_interface->GetStringValue(state, 2);
  10326. lua_interface->ResetFunctionStack(state);
  10327. if(!spawn || !spawn->IsEntity())
  10328. {
  10329. 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));
  10330. return 0;
  10331. }
  10332. Entity* ent = (Entity*)spawn;
  10333. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10334. return 1;
  10335. }
  10336. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10337. if (!lua_interface)
  10338. return 0;
  10339. Spawn* spawn = lua_interface->GetSpawn(state);
  10340. string field = lua_interface->GetStringValue(state, 2);
  10341. lua_interface->ResetFunctionStack(state);
  10342. if(!spawn || !spawn->IsEntity())
  10343. {
  10344. 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));
  10345. return 0;
  10346. }
  10347. Entity* ent = (Entity*)spawn;
  10348. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10349. return 1;
  10350. }
  10351. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10352. if (!lua_interface)
  10353. return 0;
  10354. Spawn* spawn = lua_interface->GetSpawn(state);
  10355. string field = lua_interface->GetStringValue(state, 2);
  10356. lua_interface->ResetFunctionStack(state);
  10357. if(!spawn || !spawn->IsEntity())
  10358. {
  10359. 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));
  10360. return 0;
  10361. }
  10362. Entity* ent = (Entity*)spawn;
  10363. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10364. return 1;
  10365. }
  10366. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10367. if (!lua_interface)
  10368. return 0;
  10369. Spawn* spawn = lua_interface->GetSpawn(state);
  10370. string field = lua_interface->GetStringValue(state, 2);
  10371. lua_interface->ResetFunctionStack(state);
  10372. if(!spawn || !spawn->IsEntity())
  10373. {
  10374. 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));
  10375. return 0;
  10376. }
  10377. Entity* ent = (Entity*)spawn;
  10378. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10379. return 1;
  10380. }
  10381. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10382. if (!lua_interface)
  10383. return 0;
  10384. Spawn* spawn = lua_interface->GetSpawn(state);
  10385. string field = lua_interface->GetStringValue(state, 2);
  10386. string value = lua_interface->GetStringValue(state, 3);
  10387. lua_interface->ResetFunctionStack(state);
  10388. if(!spawn || !spawn->IsEntity())
  10389. {
  10390. 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));
  10391. return 0;
  10392. }
  10393. Entity* ent = (Entity*)spawn;
  10394. bool set_ = ent->SetInfoStructString(field, value);
  10395. lua_interface->SetBooleanValue(state, set_);
  10396. return 1;
  10397. }
  10398. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10399. if (!lua_interface)
  10400. return 0;
  10401. Spawn* spawn = lua_interface->GetSpawn(state);
  10402. string field = lua_interface->GetStringValue(state, 2);
  10403. int64 value = lua_interface->GetInt64Value(state, 3);
  10404. lua_interface->ResetFunctionStack(state);
  10405. if(!spawn || !spawn->IsEntity())
  10406. {
  10407. 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));
  10408. return 0;
  10409. }
  10410. Entity* ent = (Entity*)spawn;
  10411. bool set_ = ent->SetInfoStructUInt(field, value);
  10412. lua_interface->SetBooleanValue(state, set_);
  10413. return 1;
  10414. }
  10415. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10416. if (!lua_interface)
  10417. return 0;
  10418. Spawn* spawn = lua_interface->GetSpawn(state);
  10419. string field = lua_interface->GetStringValue(state, 2);
  10420. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10421. lua_interface->ResetFunctionStack(state);
  10422. if(!spawn || !spawn->IsEntity())
  10423. {
  10424. 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));
  10425. return 0;
  10426. }
  10427. Entity* ent = (Entity*)spawn;
  10428. bool set_ = ent->SetInfoStructSInt(field, value);
  10429. lua_interface->SetBooleanValue(state, set_);
  10430. return 1;
  10431. }
  10432. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10433. if (!lua_interface)
  10434. return 0;
  10435. Spawn* spawn = lua_interface->GetSpawn(state);
  10436. string field = lua_interface->GetStringValue(state, 2);
  10437. float value = lua_interface->GetFloatValue(state, 3);
  10438. lua_interface->ResetFunctionStack(state);
  10439. if(!spawn || !spawn->IsEntity())
  10440. {
  10441. 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));
  10442. return 0;
  10443. }
  10444. Entity* ent = (Entity*)spawn;
  10445. bool set_ = ent->SetInfoStructFloat(field, value);
  10446. lua_interface->SetBooleanValue(state, set_);
  10447. return 1;
  10448. }
  10449. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10450. if (!lua_interface)
  10451. return 0;
  10452. Spawn* spawn = lua_interface->GetSpawn(state);
  10453. bool value = lua_interface->GetBooleanValue(state, 2);
  10454. lua_interface->ResetFunctionStack(state);
  10455. if(!spawn || !spawn->IsPlayer())
  10456. {
  10457. 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));
  10458. return 0;
  10459. }
  10460. ((Player*)spawn)->SetCharSheetChanged(value);
  10461. return 0;
  10462. }
  10463. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10464. if (!lua_interface)
  10465. return 0;
  10466. Spawn* spawn = lua_interface->GetSpawn(state);
  10467. std::string fromName = lua_interface->GetStringValue(state, 2);
  10468. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10469. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10470. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10471. int32 copper = lua_interface->GetInt32Value(state, 6);
  10472. int32 silver = lua_interface->GetInt32Value(state, 7);
  10473. int32 gold = lua_interface->GetInt32Value(state, 8);
  10474. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10475. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10476. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10477. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10478. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10479. lua_interface->ResetFunctionStack(state);
  10480. if(!spawn || !spawn->IsPlayer())
  10481. {
  10482. 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));
  10483. lua_interface->SetBooleanValue(state, false);
  10484. return 1;
  10485. }
  10486. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10487. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10488. lua_interface->SetBooleanValue(state, true);
  10489. return 1;
  10490. }
  10491. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10492. if (!lua_interface)
  10493. return 0;
  10494. int32 char_id = lua_interface->GetInt32Value(state);
  10495. std::string fromName = lua_interface->GetStringValue(state, 2);
  10496. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10497. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10498. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10499. int32 copper = lua_interface->GetInt32Value(state, 6);
  10500. int32 silver = lua_interface->GetInt32Value(state, 7);
  10501. int32 gold = lua_interface->GetInt32Value(state, 8);
  10502. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10503. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10504. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10505. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10506. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10507. lua_interface->ResetFunctionStack(state);
  10508. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10509. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10510. lua_interface->SetBooleanValue(state, true);
  10511. return 1;
  10512. }
  10513. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10514. Spawn* widget;
  10515. if (lua_interface) {
  10516. widget = lua_interface->GetSpawn(state);
  10517. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10518. lua_interface->ResetFunctionStack(state);
  10519. if (widget && widget->IsWidget())
  10520. {
  10521. ((Widget*)widget)->OpenDoor();
  10522. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10523. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10524. }
  10525. else
  10526. 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));
  10527. }
  10528. return 0;
  10529. }
  10530. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10531. Spawn* widget;
  10532. if (lua_interface) {
  10533. widget = lua_interface->GetSpawn(state);
  10534. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10535. lua_interface->ResetFunctionStack(state);
  10536. if (widget && widget->IsWidget())
  10537. {
  10538. ((Widget*)widget)->CloseDoor();
  10539. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10540. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10541. }
  10542. else
  10543. 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));
  10544. }
  10545. return 0;
  10546. }
  10547. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10548. if (!lua_interface)
  10549. return 0;
  10550. Spawn* widget = lua_interface->GetSpawn(state);
  10551. lua_interface->ResetFunctionStack(state);
  10552. if (widget && widget->IsWidget())
  10553. {
  10554. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10555. return 1;
  10556. }
  10557. return 0;
  10558. }
  10559. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10560. if (!lua_interface)
  10561. return 0;
  10562. sint32 min = lua_interface->GetSInt32Value(state);
  10563. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10564. lua_interface->ResetFunctionStack(state);
  10565. sint32 result = MakeRandomInt(min, max);
  10566. lua_interface->SetSInt32Value(state, result);
  10567. return 1;
  10568. }
  10569. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10570. if (!lua_interface)
  10571. return 0;
  10572. float min = lua_interface->GetFloatValue(state);
  10573. float max = lua_interface->GetFloatValue(state, 2);
  10574. lua_interface->ResetFunctionStack(state);
  10575. float result = MakeRandomFloat(min, max);
  10576. lua_interface->SetFloatValue(state, result);
  10577. return 1;
  10578. }
  10579. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10580. if (!lua_interface)
  10581. return 0;
  10582. Spawn* spawn = lua_interface->GetSpawn(state);
  10583. int32 value = lua_interface->GetInt32Value(state, 2);
  10584. lua_interface->ResetFunctionStack(state);
  10585. if(!spawn)
  10586. {
  10587. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10588. lua_interface->SetBooleanValue(state, false);
  10589. return 1;
  10590. }
  10591. spawn->AddIconValue(value);
  10592. lua_interface->SetBooleanValue(state, true);
  10593. return 1;
  10594. }
  10595. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10596. if (!lua_interface)
  10597. return 0;
  10598. Spawn* spawn = lua_interface->GetSpawn(state);
  10599. int32 value = lua_interface->GetInt32Value(state, 2);
  10600. lua_interface->ResetFunctionStack(state);
  10601. if(!spawn)
  10602. {
  10603. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10604. lua_interface->SetBooleanValue(state, false);
  10605. return 1;
  10606. }
  10607. spawn->RemoveIconValue(value);
  10608. lua_interface->SetBooleanValue(state, true);
  10609. return 1;
  10610. }
  10611. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10612. Spawn* npc = lua_interface->GetSpawn(state);
  10613. lua_interface->ResetFunctionStack(state);
  10614. if (npc && npc->IsNPC()) {
  10615. NPC* shard = (NPC*)npc;
  10616. int32 shardid = shard->GetShardID();
  10617. lua_interface->SetInt32Value(state, shardid);
  10618. return 1;
  10619. }
  10620. lua_interface->SetInt32Value(state, 0);
  10621. return 1;
  10622. }
  10623. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10624. Spawn* npc = lua_interface->GetSpawn(state);
  10625. lua_interface->ResetFunctionStack(state);
  10626. if (npc && npc->IsNPC()) {
  10627. NPC* shard = (NPC*)npc;
  10628. int32 charid = shard->GetShardCharID();
  10629. lua_interface->SetInt32Value(state, charid);
  10630. return 1;
  10631. }
  10632. lua_interface->SetInt32Value(state, 0);
  10633. return 1;
  10634. }
  10635. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10636. Spawn* npc = lua_interface->GetSpawn(state);
  10637. lua_interface->ResetFunctionStack(state);
  10638. if (npc && npc->IsNPC()) {
  10639. NPC* shard = (NPC*)npc;
  10640. int64 timestamp = shard->GetShardCreatedTimestamp();
  10641. lua_interface->SetSInt64Value(state, timestamp);
  10642. return 1;
  10643. }
  10644. lua_interface->SetSInt64Value(state, 0);
  10645. return 1;
  10646. }
  10647. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10648. if (!lua_interface)
  10649. return 0;
  10650. int32 shardid = lua_interface->GetInt32Value(state);
  10651. lua_interface->ResetFunctionStack(state);
  10652. if(shardid < 1)
  10653. lua_interface->SetBooleanValue(state, false);
  10654. else
  10655. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10656. return 1;
  10657. }
  10658. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10659. if (!lua_interface)
  10660. return 0;
  10661. Spawn* spawn = lua_interface->GetSpawn(state);
  10662. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10663. if (spawn) {
  10664. spawn->PauseMovement(delay_in_ms);
  10665. }
  10666. lua_interface->ResetFunctionStack(state);
  10667. return 0;
  10668. }
  10669. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10670. if (!lua_interface)
  10671. return 0;
  10672. Spawn* spawn = lua_interface->GetSpawn(state);
  10673. if (spawn) {
  10674. spawn->StopMovement();
  10675. }
  10676. lua_interface->ResetFunctionStack(state);
  10677. return 0;
  10678. }
  10679. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10680. Player* player = (Player*)lua_interface->GetSpawn(state);
  10681. int8 level = lua_interface->GetInt8Value(state, 2);
  10682. lua_interface->ResetFunctionStack(state);
  10683. if (player && player->IsPlayer() && level > 0) {
  10684. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10685. return 1;
  10686. }
  10687. return 0;
  10688. }
  10689. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10690. Player* player = (Player*)lua_interface->GetSpawn(state);
  10691. int8 level = lua_interface->GetInt8Value(state, 2);
  10692. lua_interface->ResetFunctionStack(state);
  10693. if (player && player->IsPlayer() && level > 0) {
  10694. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10695. return 1;
  10696. }
  10697. return 0;
  10698. }
  10699. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10700. ZoneServer* zone = lua_interface->GetZone(state);
  10701. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10702. lua_interface->ResetFunctionStack(state);
  10703. if (zone) {
  10704. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10705. if (spawn) {
  10706. lua_interface->SetSpawnValue(state, spawn);
  10707. return 1;
  10708. }
  10709. }
  10710. return 0;
  10711. }
  10712. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10713. if (!lua_interface)
  10714. return 0;
  10715. Spawn* spawn = lua_interface->GetSpawn(state);
  10716. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10717. lua_interface->ResetFunctionStack(state);
  10718. bool res = false;
  10719. if(spawn && spawn->IsTransportSpawn())
  10720. {
  10721. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10722. spawn->SetRailID(rail_id);
  10723. res = true;
  10724. }
  10725. else if (!spawn) {
  10726. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10727. }
  10728. else if(!spawn->IsTransportSpawn()) {
  10729. 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());
  10730. }
  10731. lua_interface->SetBooleanValue(state, res);
  10732. return 1;
  10733. }
  10734. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10735. if (!lua_interface)
  10736. return 0;
  10737. ZoneServer* zone = lua_interface->GetZone(state);
  10738. lua_interface->ResetFunctionStack(state);
  10739. if (zone) {
  10740. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10741. return 1;
  10742. }
  10743. return 0;
  10744. }
  10745. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10746. if (!lua_interface)
  10747. return 0;
  10748. Spawn* spawn = lua_interface->GetSpawn(state);
  10749. lua_interface->ResetFunctionStack(state);
  10750. if (spawn) {
  10751. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10752. return 1;
  10753. }
  10754. return 0;
  10755. }
  10756. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10757. if (!lua_interface)
  10758. return 0;
  10759. Spawn* player = lua_interface->GetSpawn(state);
  10760. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10761. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10762. lua_interface->ResetFunctionStack(state);
  10763. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10764. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10765. }
  10766. else if(!zoneID) {
  10767. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10768. }
  10769. else
  10770. {
  10771. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10772. return 1;
  10773. }
  10774. return 0;
  10775. }
  10776. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10777. if (!lua_interface)
  10778. return 0;
  10779. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10780. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10781. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10782. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10783. lua_interface->ResetFunctionStack(state);
  10784. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10785. world.GetWorldTimeStruct()->year = newYear;
  10786. world.GetWorldTimeStruct()->month = newMonth;
  10787. world.GetWorldTimeStruct()->hour = newHour;
  10788. world.GetWorldTimeStruct()->minute = newMinute;
  10789. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10790. return 0;
  10791. }
  10792. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10793. if (!lua_interface)
  10794. return 0;
  10795. lua_interface->ResetFunctionStack(state);
  10796. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10797. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10798. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10799. return 1;
  10800. }
  10801. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  10802. if (!lua_interface)
  10803. return 0;
  10804. lua_interface->ResetFunctionStack(state);
  10805. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10806. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  10807. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10808. return 1;
  10809. }
  10810. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  10811. if (!lua_interface)
  10812. return 0;
  10813. lua_interface->ResetFunctionStack(state);
  10814. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10815. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  10816. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10817. return 1;
  10818. }
  10819. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  10820. if (!lua_interface)
  10821. return 0;
  10822. lua_interface->ResetFunctionStack(state);
  10823. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10824. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  10825. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10826. return 1;
  10827. }
  10828. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  10829. if (!lua_interface)
  10830. return 0;
  10831. lua_interface->ResetFunctionStack(state);
  10832. world.SendTimeUpdate();
  10833. return 0;
  10834. }