LuaFunctions.cpp 380 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452
  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->SetInt32Value(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. ZoneServer* zone = lua_interface->GetZone(state);
  1502. Spawn* player = lua_interface->GetSpawn(state, 2);
  1503. Client* client = 0;
  1504. if (player && player->IsPlayer())
  1505. client = player->GetZone()->GetClientBySpawn(player);
  1506. float x = lua_interface->GetFloatValue(state, 3);
  1507. float y = lua_interface->GetFloatValue(state, 4);
  1508. float z = lua_interface->GetFloatValue(state, 5);
  1509. float heading = lua_interface->GetFloatValue(state, 6);
  1510. if (zone && client) {
  1511. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1512. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1513. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1514. {
  1515. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1516. return 0;
  1517. }
  1518. if (x != 0 || y != 0 || z != 0) {
  1519. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1520. player->SetX(x);
  1521. player->SetY(y);
  1522. player->SetZ(z);
  1523. player->SetHeading(heading);
  1524. client->Zone(zone->GetZoneName(), false);
  1525. }
  1526. else
  1527. client->Zone(zone->GetZoneName());
  1528. }
  1529. else
  1530. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1531. return 0;
  1532. }
  1533. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1534. if (!lua_interface)
  1535. return 0;
  1536. Spawn* spawn = lua_interface->GetSpawn(state);
  1537. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1538. if (spawn && spawn2)
  1539. spawn->AddAllowAccessSpawn(spawn2);
  1540. return 0;
  1541. }
  1542. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1543. if (!lua_interface)
  1544. return 0;
  1545. Spawn* target = lua_interface->GetSpawn(state);
  1546. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1547. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1548. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1549. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1550. if (!target) {
  1551. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1552. return 0;
  1553. }
  1554. if (!target->IsEntity()) {
  1555. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1556. return 0;
  1557. }
  1558. if (spell_id <= 0) {
  1559. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1560. return 0;
  1561. }
  1562. if (caster && !caster->IsEntity()) {
  1563. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1564. return 0;
  1565. }
  1566. if (spell_tier == 0)
  1567. spell_tier = 1;
  1568. if (!caster)
  1569. caster = target;
  1570. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1571. return 0;
  1572. }
  1573. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1574. if (!lua_interface)
  1575. return 0;
  1576. Spawn* target = lua_interface->GetSpawn(state);
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if (!luaspell)
  1579. return 0;
  1580. Spawn* caster = luaspell->caster;
  1581. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1582. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1583. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1584. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1585. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1586. //lua_interface->ResetFunctionStack(state);
  1587. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1588. vector<int16> faction_req;
  1589. vector<int16> race_req;
  1590. int32 class_req = 0;
  1591. int32 i = 0;
  1592. int8 f = 0;
  1593. int8 r = 0;
  1594. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1595. if (class_id < 100) {
  1596. class_req += pow(2.0, double(class_id - 1));
  1597. }
  1598. else if (class_id > 100 && class_id < 1000) {
  1599. race_req.push_back(class_id);
  1600. r++;
  1601. }
  1602. else {
  1603. faction_req.push_back(class_id);
  1604. f++;
  1605. }
  1606. i++;
  1607. }
  1608. if (caster && caster->IsEntity()) {
  1609. bool race_match = false;
  1610. bool success = false;
  1611. luaspell->resisted = false;
  1612. if (luaspell->targets.size() > 0) {
  1613. ZoneServer* zone = luaspell->caster->GetZone();
  1614. Spawn* target = 0;
  1615. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1616. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1617. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1618. if (race_req.size() > 0) {
  1619. for (int8 i = 0; i < race_req.size(); i++) {
  1620. if (target->GetLuaRaceId() == race_req[i]) {
  1621. race_match = true;
  1622. }
  1623. }
  1624. }
  1625. else
  1626. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1627. if (race_match == true) {
  1628. float distance = caster->GetDistance(target, true);
  1629. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1630. }
  1631. }
  1632. }
  1633. success = true;
  1634. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1635. }
  1636. else if (target) {
  1637. //check class and race/faction here
  1638. if (race_req.size() > 0) {
  1639. for (int8 i = 0; i < race_req.size(); i++) {
  1640. if (target->GetLuaRaceId() == race_req[i]) {
  1641. race_match = true;
  1642. }
  1643. }
  1644. }
  1645. else
  1646. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1647. if (race_match == true) {
  1648. float distance = caster->GetDistance(target, true);
  1649. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1650. success = true;
  1651. }
  1652. }
  1653. if (success) {
  1654. Spell* spell = luaspell->spell;
  1655. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1656. ((Player*)caster)->InCombat(true);
  1657. if (caster->GetZone())
  1658. caster->GetZone()->TriggerCharSheetTimer();
  1659. }
  1660. }
  1661. }
  1662. return 0;
  1663. }
  1664. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1665. if (!lua_interface)
  1666. return 0;
  1667. Spawn* spawn = lua_interface->GetSpawn(state);
  1668. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1669. lua_interface->ResetFunctionStack(state);
  1670. if (spawn && value != 0) {
  1671. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1672. spawn->SetPower(spawn->GetTotalPower());
  1673. else
  1674. spawn->SetPower(spawn->GetPower() + value);
  1675. }
  1676. return 0;
  1677. }
  1678. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1679. if (!lua_interface)
  1680. return 0;
  1681. Spawn* spawn = lua_interface->GetSpawn(state);
  1682. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1683. lua_interface->ResetFunctionStack(state);
  1684. if (spawn && value != 0) {
  1685. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1686. spawn->SetHP(spawn->GetTotalHP());
  1687. else
  1688. spawn->SetHP(spawn->GetHP() + value);
  1689. }
  1690. return 0;
  1691. }
  1692. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1693. if (!lua_interface)
  1694. return 0;
  1695. Spawn* spawn = lua_interface->GetSpawn(state);
  1696. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1697. lua_interface->ResetFunctionStack(state);
  1698. if (spawn && value != 0) {
  1699. spawn->SetPower(spawn->GetPower() + value);
  1700. if (value > spawn->GetTotalHPBase())
  1701. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1702. }
  1703. return 0;
  1704. }
  1705. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1706. if (!lua_interface)
  1707. return 0;
  1708. Spawn* spawn = lua_interface->GetSpawn(state);
  1709. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1710. lua_interface->ResetFunctionStack(state);
  1711. if (spawn && value != 0) {
  1712. spawn->SetHP(spawn->GetHP() + value);
  1713. if (value > spawn->GetTotalHPBase())
  1714. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1715. }
  1716. return 0;
  1717. }
  1718. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1719. if (!lua_interface)
  1720. return 0;
  1721. Spawn* spawn = lua_interface->GetSpawn(state);
  1722. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1723. lua_interface->ResetFunctionStack(state);
  1724. if (spawn) {
  1725. spawn->SetHP(value);
  1726. if (value > spawn->GetTotalHPBase())
  1727. spawn->SetTotalHP(value);
  1728. }
  1729. return 0;
  1730. }
  1731. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1732. if (!lua_interface)
  1733. return 0;
  1734. Spawn* spawn = lua_interface->GetSpawn(state);
  1735. float value = lua_interface->GetFloatValue(state, 2);
  1736. lua_interface->ResetFunctionStack(state);
  1737. if (spawn && spawn->IsEntity() && value > 0)
  1738. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1739. if (spawn->IsPlayer())
  1740. ((Player*)spawn)->SetCharSheetChanged(true);
  1741. return 0;
  1742. }
  1743. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1744. if (!lua_interface)
  1745. return 0;
  1746. Spawn* spawn = lua_interface->GetSpawn(state);
  1747. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1748. lua_interface->ResetFunctionStack(state);
  1749. if (spawn && spawn->IsEntity() && value > 0)
  1750. ((Entity*)spawn)->SetTotalHPBase(value);
  1751. return 0;
  1752. }
  1753. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1754. if (!lua_interface)
  1755. return 0;
  1756. Spawn* spawn = lua_interface->GetSpawn(state);
  1757. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1758. lua_interface->ResetFunctionStack(state);
  1759. if (spawn && value > 0) {
  1760. spawn->SetPower(value);
  1761. if (value > spawn->GetTotalPowerBase())
  1762. spawn->SetTotalPower(value);
  1763. }
  1764. return 0;
  1765. }
  1766. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1767. if (!lua_interface)
  1768. return 0;
  1769. Spawn* spawn = lua_interface->GetSpawn(state);
  1770. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1771. lua_interface->ResetFunctionStack(state);
  1772. if (spawn && spawn->IsEntity() && value > 0)
  1773. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1774. return 0;
  1775. }
  1776. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1777. if (!lua_interface)
  1778. return 0;
  1779. Spawn* spawn = lua_interface->GetSpawn(state);
  1780. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1781. lua_interface->ResetFunctionStack(state);
  1782. if (spawn && spawn->IsEntity() && value > 0)
  1783. ((Entity*)spawn)->SetTotalPowerBase(value);
  1784. return 0;
  1785. }
  1786. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1787. if (!lua_interface)
  1788. return 0;
  1789. Spawn* spawn = lua_interface->GetSpawn(state);
  1790. float x = lua_interface->GetFloatValue(state, 2);
  1791. float y = lua_interface->GetFloatValue(state, 3);
  1792. float z = lua_interface->GetFloatValue(state, 4);
  1793. float heading = lua_interface->GetFloatValue(state, 5);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn) {
  1796. spawn->SetX(x);
  1797. spawn->SetY(y);
  1798. spawn->SetZ(z);
  1799. if (heading != 0)
  1800. spawn->SetHeading(heading);
  1801. spawn->SetSpawnOrigX(spawn->GetX());
  1802. spawn->SetSpawnOrigY(spawn->GetY());
  1803. spawn->SetSpawnOrigZ(spawn->GetZ());
  1804. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1805. if (spawn->IsPlayer()) {
  1806. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1807. if (client) {
  1808. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1809. client->QueuePacket(packet);
  1810. }
  1811. }
  1812. }
  1813. return 0;
  1814. }
  1815. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1816. if (!lua_interface)
  1817. return 0;
  1818. Spawn* spawn = lua_interface->GetSpawn(state);
  1819. float value = lua_interface->GetFloatValue(state, 2);
  1820. lua_interface->ResetFunctionStack(state);
  1821. if (spawn) {
  1822. spawn->SetHeading(value);
  1823. if (spawn->IsPlayer()) {
  1824. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1825. if (client) {
  1826. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1827. client->QueuePacket(packet);
  1828. }
  1829. }
  1830. }
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. int16 value = lua_interface->GetInt16Value(state, 2);
  1838. lua_interface->ResetFunctionStack(state);
  1839. if (spawn)
  1840. spawn->SetModelType(value);
  1841. return 0;
  1842. }
  1843. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1844. if (!lua_interface)
  1845. return 0;
  1846. Spawn* spawn = lua_interface->GetSpawn(state);
  1847. int8 value = lua_interface->GetInt8Value(state, 2);
  1848. lua_interface->ResetFunctionStack(state);
  1849. if (spawn) {
  1850. if (spawn->IsPlayer())
  1851. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1852. else
  1853. spawn->SetAdventureClass(value);
  1854. }
  1855. return 0;
  1856. }
  1857. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1858. if (!lua_interface)
  1859. return 0;
  1860. Spawn* spawn = lua_interface->GetSpawn(state);
  1861. int8 value = lua_interface->GetInt8Value(state, 2);
  1862. lua_interface->ResetFunctionStack(state);
  1863. if (spawn) {
  1864. spawn->SetTradeskillClass(value);
  1865. if (spawn->IsEntity()) {
  1866. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1867. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1868. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1869. }
  1870. if (spawn->IsPlayer())
  1871. ((Player*)spawn)->SetCharSheetChanged(true);
  1872. }
  1873. return 0;
  1874. }
  1875. int EQ2Emu_lua_SetMount(lua_State* state) {
  1876. if (!lua_interface)
  1877. return 0;
  1878. Spawn* spawn = lua_interface->GetSpawn(state);
  1879. int16 value = lua_interface->GetInt16Value(state, 2);
  1880. if (spawn && spawn->IsEntity()) {
  1881. ((Entity*)spawn)->SetMount(value);
  1882. EQ2_Color color;
  1883. color.red = 255;
  1884. color.green = 255;
  1885. color.blue = 255;
  1886. ((Entity*)spawn)->SetMountColor(&color);
  1887. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1888. }
  1889. return 0;
  1890. }
  1891. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1892. if (!lua_interface)
  1893. return 0;
  1894. Spawn* spawn = lua_interface->GetSpawn(state);
  1895. EQ2_Color mount_color;
  1896. EQ2_Color saddle_color;
  1897. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1898. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1899. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1900. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1901. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1902. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1903. if (spawn && spawn->IsEntity()) {
  1904. ((Entity*)spawn)->SetMountColor(&mount_color);
  1905. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1906. }
  1907. return 0;
  1908. }
  1909. int EQ2Emu_lua_GetMount(lua_State* state) {
  1910. if (!lua_interface)
  1911. return 0;
  1912. Spawn* spawn = lua_interface->GetSpawn(state);
  1913. if (spawn && spawn->IsEntity()) {
  1914. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1915. return 1;
  1916. }
  1917. return 0;
  1918. }
  1919. int EQ2Emu_lua_GetRace(lua_State* state) {
  1920. if (!lua_interface)
  1921. return 0;
  1922. Spawn* spawn = lua_interface->GetSpawn(state);
  1923. if (spawn)
  1924. {
  1925. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1926. lua_interface->SetInt32Value(state, spawn->GetRace());
  1927. return 1;
  1928. }
  1929. return 0;
  1930. }
  1931. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1932. if (!lua_interface)
  1933. return 0;
  1934. Spawn* spawn = lua_interface->GetSpawn(state);
  1935. if (spawn) {
  1936. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1937. return 1;
  1938. }
  1939. return 0;
  1940. }
  1941. int EQ2Emu_lua_GetClass(lua_State* state) {
  1942. Spawn* spawn = lua_interface->GetSpawn(state);
  1943. if (spawn) {
  1944. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1945. return 1;
  1946. }
  1947. return 0;
  1948. }
  1949. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. if (spawn) {
  1952. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1953. return 1;
  1954. }
  1955. return 0;
  1956. }
  1957. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1958. if (!lua_interface)
  1959. return 0;
  1960. Spawn* spawn = lua_interface->GetSpawn(state);
  1961. float value = lua_interface->GetFloatValue(state, 2);
  1962. lua_interface->ResetFunctionStack(state);
  1963. if (spawn) {
  1964. spawn->SetSpeed(value);
  1965. ((Entity*)spawn)->SetSpeed(value);
  1966. if (spawn->IsPlayer()) {
  1967. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1968. if (client) {
  1969. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1970. if (packet) {
  1971. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1972. packet->setDataByName("speed", value);
  1973. packet->setDataByName("size", 0.51);
  1974. EQ2Packet* app = packet->serialize();
  1975. client->QueuePacket(app);
  1976. safe_delete(packet);
  1977. }
  1978. }
  1979. }
  1980. }
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. const int16 type = lua_interface->GetInt16Value(state, 2);
  1988. const float value = lua_interface->GetFloatValue(state, 3);
  1989. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1990. int64 class_req = 0;
  1991. int32 class_id = 0;
  1992. vector<int16> faction_req;
  1993. vector<int16> race_req;
  1994. int32 i = 0;
  1995. int8 f = 0;
  1996. int8 r = 0;
  1997. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1998. if (class_id < 100) {
  1999. class_req += pow(2.0, double(class_id - 1));
  2000. }
  2001. else if (class_id > 100 && class_id < 1000) {
  2002. race_req.push_back(class_id);
  2003. r++;
  2004. }
  2005. else {
  2006. faction_req.push_back(class_id);
  2007. f++;
  2008. }
  2009. i++;
  2010. }
  2011. if (value != 0 && type >= 0) {
  2012. if (luaspell && luaspell->spell && luaspell->caster) {
  2013. ZoneServer* zone = luaspell->caster->GetZone();
  2014. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2015. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2016. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2017. if (target) {
  2018. if (target->IsPlayer()) {
  2019. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2020. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2021. if (((Player*)target)->GetGroupMemberInfo())
  2022. ((Player*)target)->UpdateGroupMemberInfo();
  2023. ((Player*)target)->SetCharSheetChanged(true);
  2024. }
  2025. else if (target->IsNPC())
  2026. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2027. else
  2028. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2029. }
  2030. }
  2031. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2032. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2033. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2034. }
  2035. else if (spawn && spawn->IsEntity()) {
  2036. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2037. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2038. if (spawn->IsPlayer())
  2039. ((Player*)spawn)->SetCharSheetChanged(true);
  2040. }
  2041. else
  2042. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2043. }
  2044. else
  2045. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2046. return 0;
  2047. }
  2048. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2049. if (!lua_interface)
  2050. return 0;
  2051. Spawn* spawn = lua_interface->GetSpawn(state);
  2052. int16 type = lua_interface->GetInt16Value(state, 2);
  2053. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2054. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2055. if (!spawn) {
  2056. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2057. return 0;
  2058. }
  2059. if (!spawn->IsEntity()) {
  2060. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2061. return 0;
  2062. }
  2063. if (value == 0) {
  2064. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2065. return 0;
  2066. }
  2067. if (!luaspell || !luaspell->spell) {
  2068. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2069. return 0;
  2070. }
  2071. int32 class_req = 0;
  2072. vector<int16> faction_req;
  2073. vector<int16> race_req;
  2074. int32 class_id = 0;
  2075. int32 i = 0;
  2076. int8 f = 0;
  2077. int8 r = 0;
  2078. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2079. if (class_id < 100) {
  2080. class_req += pow(2.0, double(class_id - 1));
  2081. }
  2082. else if (class_id > 100 && class_id < 1000) {
  2083. race_req.push_back(class_id);
  2084. r++;
  2085. }
  2086. else {
  2087. faction_req.push_back(class_id);
  2088. f++;
  2089. }
  2090. i++;
  2091. }
  2092. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2093. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2094. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2095. if (spawn->IsPlayer())
  2096. ((Player*)spawn)->SetCharSheetChanged(true);
  2097. return 0;
  2098. }
  2099. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2100. if (!lua_interface)
  2101. return 0;
  2102. Spawn* spawn = lua_interface->GetSpawn(state);
  2103. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2104. if (!spawn) {
  2105. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2106. return 0;
  2107. }
  2108. if (!spawn->IsEntity()) {
  2109. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2110. return 0;
  2111. }
  2112. if (!luaspell || !luaspell->spell) {
  2113. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2114. return 0;
  2115. }
  2116. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2117. if (spawn->IsPlayer())
  2118. ((Player*)spawn)->SetCharSheetChanged(true);
  2119. return 0;
  2120. }
  2121. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2122. if (!lua_interface)
  2123. return 0;
  2124. Spawn* spawn = lua_interface->GetSpawn(state);
  2125. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2126. if (luaspell && luaspell->spell) {
  2127. ZoneServer* zone = luaspell->caster->GetZone();
  2128. Spawn* target = 0;
  2129. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2130. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2131. target = zone->GetSpawnByID(luaspell->targets[i]);
  2132. if (target && target->IsEntity()) {
  2133. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2134. if (target->IsPlayer())
  2135. ((Player*)target)->SetCharSheetChanged(true);
  2136. }
  2137. }
  2138. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2139. }
  2140. else if (spawn && spawn->IsEntity()) {
  2141. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2142. if (spawn->IsPlayer())
  2143. ((Player*)spawn)->SetCharSheetChanged(true);
  2144. }
  2145. return 0;
  2146. }
  2147. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2148. if (!lua_interface)
  2149. return 0;
  2150. Spawn* spawn = lua_interface->GetSpawn(state);
  2151. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2152. float value = lua_interface->GetFloatValue(state, 3);
  2153. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2154. if (value != 0) {
  2155. int32 spell_id = 0;
  2156. if (luaspell && luaspell->spell && luaspell->caster) {
  2157. spell_id = luaspell->spell->GetSpellID();
  2158. ZoneServer* zone = luaspell->caster->GetZone();
  2159. Spawn* target = 0;
  2160. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2161. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2162. target = zone->GetSpawnByID(luaspell->targets[i]);
  2163. if (target && target->Alive()) {
  2164. if (target->IsPlayer()) {
  2165. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2166. Client* client = target->GetZone()->GetClientBySpawn(target);
  2167. if (client) {
  2168. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2169. if (packet)
  2170. client->QueuePacket(packet);
  2171. }
  2172. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2173. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2174. }
  2175. else if (target->IsNPC()) {
  2176. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2177. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2178. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2179. }
  2180. else
  2181. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2182. }
  2183. }
  2184. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2185. }
  2186. else if (spawn) {
  2187. if (spawn->IsPlayer()) {
  2188. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2189. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2190. if (client) {
  2191. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2192. if (packet)
  2193. client->QueuePacket(packet);
  2194. }
  2195. }
  2196. else if (spawn->IsNPC())
  2197. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2198. else
  2199. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2200. }
  2201. }
  2202. else
  2203. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2204. return 0;
  2205. }
  2206. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2207. if (!lua_interface)
  2208. return 0;
  2209. Spawn* spawn = lua_interface->GetSpawn(state);
  2210. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2211. if (spawn && spawn->IsPlayer()) {
  2212. int32 spell_id = 0;
  2213. if (luaspell && luaspell->spell) {
  2214. spell_id = luaspell->spell->GetSpellID();
  2215. ZoneServer* zone = luaspell->caster->GetZone();
  2216. Spawn* target = 0;
  2217. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2218. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2219. target = zone->GetSpawnByID(luaspell->targets[i]);
  2220. if (target) {
  2221. if (target->IsPlayer()) {
  2222. ((Player*)target)->RemoveSkillBonus(spell_id);
  2223. Client* client = target->GetZone()->GetClientBySpawn(target);
  2224. if (client) {
  2225. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2226. if (packet)
  2227. client->QueuePacket(packet);
  2228. }
  2229. }
  2230. else if (target->IsNPC())
  2231. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2232. else
  2233. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2234. }
  2235. }
  2236. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2237. }
  2238. else if (spawn) {
  2239. if (spawn->IsPlayer()) {
  2240. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2241. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2242. if (client) {
  2243. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2244. if (packet)
  2245. client->QueuePacket(packet);
  2246. }
  2247. }
  2248. else if (spawn->IsNPC())
  2249. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2250. else
  2251. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2252. }
  2253. }
  2254. return 0;
  2255. }
  2256. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2257. if (!lua_interface)
  2258. return 0;
  2259. Spawn* spawn = lua_interface->GetSpawn(state);
  2260. int8 type = lua_interface->GetInt32Value(state, 2);
  2261. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2262. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2263. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2264. ZoneServer* zone = luaspell->caster->GetZone();
  2265. Spawn* target = 0;
  2266. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2267. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2268. target = zone->GetSpawnByID(luaspell->targets[i]);
  2269. if (target && target->IsEntity()) {
  2270. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2271. ((Entity*)target)->AddMezSpell(luaspell);
  2272. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2273. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2274. if (target->IsNPC())
  2275. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2276. }
  2277. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2278. ((Entity*)target)->AddStifleSpell(luaspell);
  2279. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2280. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2281. if (target->IsNPC())
  2282. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2283. }
  2284. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2285. ((Entity*)target)->AddDazeSpell(luaspell);
  2286. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2287. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2288. if (target->IsNPC())
  2289. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2290. }
  2291. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2292. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2293. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2294. ((Entity*)target)->AddStunSpell(luaspell);
  2295. if (target->IsNPC())
  2296. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2297. }
  2298. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2299. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2300. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2301. ((Entity*)target)->AddRootSpell(luaspell);
  2302. if (target->IsNPC())
  2303. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2304. }
  2305. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2306. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2307. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2308. ((Entity*)target)->AddFearSpell(luaspell);
  2309. if (target->IsNPC())
  2310. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2311. }
  2312. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2313. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2314. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2315. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2316. }
  2317. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2318. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2319. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2320. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2321. }
  2322. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2323. ((Entity*)target)->AddSnareSpell(luaspell);
  2324. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2325. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2326. if (target->IsNPC())
  2327. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2328. }
  2329. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2330. ((Entity*)target)->AddFlightSpell(luaspell);
  2331. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2332. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2333. }
  2334. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2335. ((Entity*)target)->AddGlideSpell(luaspell);
  2336. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2337. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2338. }
  2339. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2340. ((Entity*)target)->AddSafefallSpell(luaspell);
  2341. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2342. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2343. }
  2344. else
  2345. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2346. }
  2347. else
  2348. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2349. }
  2350. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2351. }
  2352. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2353. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2354. ((Entity*)spawn)->AddMezSpell(luaspell);
  2355. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2356. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2357. }
  2358. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2359. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2360. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2361. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2362. }
  2363. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2364. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2365. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2366. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2367. }
  2368. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2369. ((Entity*)spawn)->AddStunSpell(luaspell);
  2370. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2371. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2372. }
  2373. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2374. ((Entity*)spawn)->AddRootSpell(luaspell);
  2375. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2376. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2377. }
  2378. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2379. ((Entity*)spawn)->AddFearSpell(luaspell);
  2380. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2381. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2384. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2385. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2386. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2387. }
  2388. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2389. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2390. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2391. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2392. }
  2393. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2394. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2395. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2396. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2397. }
  2398. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2399. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2400. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2401. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2402. }
  2403. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2404. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2405. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2406. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2407. }
  2408. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2409. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2410. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2411. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2412. }
  2413. else
  2414. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2415. }
  2416. else
  2417. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2418. return 0;
  2419. }
  2420. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2421. if (!lua_interface)
  2422. return 0;
  2423. Spawn* spawn = lua_interface->GetSpawn(state);
  2424. int8 type = lua_interface->GetInt8Value(state, 2);
  2425. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2426. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2427. if (spawn && spawn->IsEntity()) {
  2428. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2429. ZoneServer* zone = luaspell->caster->GetZone();
  2430. Spawn* target = 0;
  2431. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2432. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2433. target = zone->GetSpawnByID(luaspell->targets[i]);
  2434. if (target) {
  2435. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2436. ((Entity*)target)->RemoveMezSpell(luaspell);
  2437. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2438. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2440. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2442. ((Entity*)target)->RemoveStunSpell(luaspell);
  2443. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2444. ((Entity*)target)->RemoveRootSpell(luaspell);
  2445. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2446. ((Entity*)target)->RemoveFearSpell(luaspell);
  2447. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2448. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2449. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2450. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2451. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2452. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2453. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2454. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2455. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2456. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2457. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2458. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2459. else
  2460. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2461. }
  2462. }
  2463. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2464. }
  2465. else if (only_remove_spawn) {
  2466. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2467. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2468. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2469. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2470. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2471. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2472. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2473. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2474. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2475. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2476. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2477. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2478. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2479. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2480. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2481. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2482. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2483. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2484. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2485. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2486. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2487. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2488. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2489. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2490. else
  2491. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2492. }
  2493. }
  2494. return 0;
  2495. }
  2496. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2497. if (!lua_interface)
  2498. return 0;
  2499. Spawn* spawn = lua_interface->GetSpawn(state);
  2500. int8 type = lua_interface->GetInt8Value(state, 2);
  2501. bool hasEffect = false;
  2502. if (!spawn)
  2503. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2504. else if (!spawn->IsEntity())
  2505. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2506. else if (type < CONTROL_MAX_EFFECTS)
  2507. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2508. else
  2509. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2510. lua_interface->SetBooleanValue(state, hasEffect);
  2511. return 1;
  2512. }
  2513. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2514. if (!lua_interface)
  2515. return 0;
  2516. Spawn* spawn = lua_interface->GetSpawn(state);
  2517. float distance = 0.0f;
  2518. if (!spawn)
  2519. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2520. else if (!spawn->IsNPC())
  2521. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2522. else
  2523. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2524. lua_interface->SetFloatValue(state, distance);
  2525. return 1;
  2526. }
  2527. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2528. if (!lua_interface)
  2529. return 0;
  2530. Spawn* spawn = lua_interface->GetSpawn(state);
  2531. float distance = 0.0f;
  2532. if (!spawn)
  2533. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2534. else if (!spawn->IsNPC())
  2535. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2536. else
  2537. distance = ((NPC*)spawn)->GetAggroRadius();
  2538. lua_interface->SetFloatValue(state, distance);
  2539. return 1;
  2540. }
  2541. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2542. if (!lua_interface)
  2543. return 0;
  2544. Spawn* spawn = lua_interface->GetSpawn(state);
  2545. float distance = lua_interface->GetFloatValue(state, 2);
  2546. bool override = lua_interface->GetBooleanValue(state, 3);
  2547. bool result = false;
  2548. lua_interface->ResetFunctionStack(state);
  2549. if (!spawn)
  2550. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2551. else if (!spawn->IsNPC())
  2552. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2553. else
  2554. {
  2555. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2556. result = true;
  2557. }
  2558. lua_interface->SetBooleanValue(state, result);
  2559. return 1;
  2560. }
  2561. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2562. if (!lua_interface)
  2563. return 0;
  2564. Spawn* spawn = lua_interface->GetSpawn(state);
  2565. int16 value = lua_interface->GetInt16Value(state, 2);
  2566. if (spawn && spawn->IsEntity()) {
  2567. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2568. if (spawn->IsPlayer())
  2569. ((Player*)spawn)->SetCharSheetChanged(true);
  2570. }
  2571. return 0;
  2572. }
  2573. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2574. if (!lua_interface)
  2575. return 0;
  2576. Spawn* spawn = lua_interface->GetSpawn(state);
  2577. int16 value = lua_interface->GetInt16Value(state, 2);
  2578. if (spawn && spawn->IsEntity()) {
  2579. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2580. if (spawn->IsPlayer())
  2581. ((Player*)spawn)->SetCharSheetChanged(true);
  2582. }
  2583. return 0;
  2584. }
  2585. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2586. if (!lua_interface)
  2587. return 0;
  2588. Spawn* spawn = lua_interface->GetSpawn(state);
  2589. int16 value = lua_interface->GetInt16Value(state, 2);
  2590. if (spawn && spawn->IsEntity()) {
  2591. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2592. if (spawn->IsPlayer())
  2593. ((Player*)spawn)->SetCharSheetChanged(true);
  2594. }
  2595. return 0;
  2596. }
  2597. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2598. if (!lua_interface)
  2599. return 0;
  2600. Spawn* spawn = lua_interface->GetSpawn(state);
  2601. int16 value = lua_interface->GetInt16Value(state, 2);
  2602. if (spawn && spawn->IsEntity()) {
  2603. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2604. if (spawn->IsPlayer())
  2605. ((Player*)spawn)->SetCharSheetChanged(true);
  2606. }
  2607. return 0;
  2608. }
  2609. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2610. if (!lua_interface)
  2611. return 0;
  2612. Spawn* spawn = lua_interface->GetSpawn(state);
  2613. int16 value = lua_interface->GetInt16Value(state, 2);
  2614. if (spawn && spawn->IsEntity()) {
  2615. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2616. if (spawn->IsPlayer())
  2617. ((Player*)spawn)->SetCharSheetChanged(true);
  2618. }
  2619. return 0;
  2620. }
  2621. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2622. if (!lua_interface)
  2623. return 0;
  2624. Spawn* spawn = lua_interface->GetSpawn(state);
  2625. int8 value = lua_interface->GetInt8Value(state, 2);
  2626. if (spawn && spawn->IsEntity()) {
  2627. ((Entity*)spawn)->SetDeity(value);
  2628. if (spawn->IsPlayer())
  2629. ((Player*)spawn)->SetCharSheetChanged(true);
  2630. }
  2631. lua_interface->ResetFunctionStack(state);
  2632. return 0;
  2633. }
  2634. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2635. if (!lua_interface)
  2636. return 0;
  2637. Spawn* spawn = lua_interface->GetSpawn(state);
  2638. if (spawn && spawn->IsEntity()) {
  2639. int8 deity = ((Entity*)spawn)->GetDeity();
  2640. lua_interface->SetInt32Value(state, deity);
  2641. return 1;
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_SetInt(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2650. if (spawn && spawn->IsEntity()) {
  2651. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2652. if (spawn->IsPlayer())
  2653. ((Player*)spawn)->SetCharSheetChanged(true);
  2654. }
  2655. return 0;
  2656. }
  2657. int EQ2Emu_lua_SetWis(lua_State* state) {
  2658. if (!lua_interface)
  2659. return 0;
  2660. Spawn* spawn = lua_interface->GetSpawn(state);
  2661. float value = lua_interface->GetFloatValue(state, 2);
  2662. if (spawn && spawn->IsEntity()) {
  2663. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2664. if (spawn->IsPlayer())
  2665. ((Player*)spawn)->SetCharSheetChanged(true);
  2666. }
  2667. return 0;
  2668. }
  2669. int EQ2Emu_lua_SetSta(lua_State* state) {
  2670. if (!lua_interface)
  2671. return 0;
  2672. Spawn* spawn = lua_interface->GetSpawn(state);
  2673. float value = lua_interface->GetFloatValue(state, 2);
  2674. if (spawn && spawn->IsEntity()) {
  2675. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2676. if (spawn->IsPlayer())
  2677. ((Player*)spawn)->SetCharSheetChanged(true);
  2678. }
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_SetStr(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* spawn = lua_interface->GetSpawn(state);
  2685. float value = lua_interface->GetFloatValue(state, 2);
  2686. if (spawn && spawn->IsEntity()) {
  2687. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2688. if (spawn->IsPlayer())
  2689. ((Player*)spawn)->SetCharSheetChanged(true);
  2690. }
  2691. return 0;
  2692. }
  2693. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2694. if (!lua_interface)
  2695. return 0;
  2696. Spawn* spawn = lua_interface->GetSpawn(state);
  2697. float value = lua_interface->GetFloatValue(state, 2);
  2698. if (spawn && spawn->IsEntity()) {
  2699. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2700. if (spawn->IsPlayer())
  2701. ((Player*)spawn)->SetCharSheetChanged(true);
  2702. }
  2703. return 0;
  2704. }
  2705. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2706. if (!lua_interface)
  2707. return 0;
  2708. Spawn* spawn = lua_interface->GetSpawn(state);
  2709. if (spawn) {
  2710. lua_interface->SetInt32Value(state, spawn->GetHP());
  2711. return 1;
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Spawn* spawn = lua_interface->GetSpawn(state);
  2719. if (spawn) {
  2720. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2721. return 1;
  2722. }
  2723. return 0;
  2724. }
  2725. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2726. if (!lua_interface)
  2727. return 0;
  2728. Spawn* spawn = lua_interface->GetSpawn(state);
  2729. if (spawn) {
  2730. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2731. return 1;
  2732. }
  2733. return 0;
  2734. }
  2735. int EQ2Emu_lua_GetName(lua_State* state) {
  2736. if (!lua_interface)
  2737. return 0;
  2738. Spawn* spawn = lua_interface->GetSpawn(state);
  2739. if (spawn) {
  2740. lua_interface->SetStringValue(state, spawn->GetName());
  2741. return 1;
  2742. }
  2743. return 0;
  2744. }
  2745. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2746. Spawn* spawn = lua_interface->GetSpawn(state);
  2747. if (spawn) {
  2748. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2749. return 1;
  2750. }
  2751. return 0;
  2752. }
  2753. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2754. if (!lua_interface)
  2755. return 0;
  2756. Spawn* spawn = lua_interface->GetSpawn(state);
  2757. if (spawn) {
  2758. lua_interface->SetInt32Value(state, spawn->GetPower());
  2759. return 1;
  2760. }
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. if (spawn) {
  2768. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2769. return 1;
  2770. }
  2771. return 0;
  2772. }
  2773. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2774. if (!lua_interface)
  2775. return 0;
  2776. Spawn* spawn = lua_interface->GetSpawn(state);
  2777. if (spawn) {
  2778. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2779. return 1;
  2780. }
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* spawn = lua_interface->GetSpawn(state);
  2787. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2788. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2789. if (spawn && spawn2) {
  2790. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2791. lua_interface->SetFloatValue(state, distance);
  2792. return 1;
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_GetX(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* spawn = lua_interface->GetSpawn(state);
  2800. if (spawn) {
  2801. lua_interface->SetFloatValue(state, spawn->GetX());
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_GetY(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* spawn = lua_interface->GetSpawn(state);
  2810. if (spawn) {
  2811. lua_interface->SetFloatValue(state, spawn->GetY());
  2812. return 1;
  2813. }
  2814. return 0;
  2815. }
  2816. int EQ2Emu_lua_GetZ(lua_State* state) {
  2817. if (!lua_interface)
  2818. return 0;
  2819. Spawn* spawn = lua_interface->GetSpawn(state);
  2820. if (spawn) {
  2821. lua_interface->SetFloatValue(state, spawn->GetZ());
  2822. return 1;
  2823. }
  2824. return 0;
  2825. }
  2826. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2827. if (!lua_interface)
  2828. return 0;
  2829. Spawn* spawn = lua_interface->GetSpawn(state);
  2830. if (spawn) {
  2831. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2832. return 1;
  2833. }
  2834. return 0;
  2835. }
  2836. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2837. if (!lua_interface)
  2838. return 0;
  2839. Spawn* spawn = lua_interface->GetSpawn(state);
  2840. if (spawn) {
  2841. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2842. return 1;
  2843. }
  2844. return 0;
  2845. }
  2846. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2847. if (!lua_interface)
  2848. return 0;
  2849. Spawn* spawn = lua_interface->GetSpawn(state);
  2850. if (spawn) {
  2851. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2852. return 1;
  2853. }
  2854. return 0;
  2855. }
  2856. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2857. if (!lua_interface)
  2858. return 0;
  2859. Spawn* spawn = lua_interface->GetSpawn(state);
  2860. if (spawn && spawn->IsEntity()) {
  2861. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2862. return 1;
  2863. }
  2864. return 0;
  2865. }
  2866. int EQ2Emu_lua_GetInt(lua_State* state) {
  2867. if (!lua_interface)
  2868. return 0;
  2869. Spawn* spawn = lua_interface->GetSpawn(state);
  2870. if (spawn && spawn->IsEntity()) {
  2871. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2872. return 1;
  2873. }
  2874. return 0;
  2875. }
  2876. int EQ2Emu_lua_GetWis(lua_State* state) {
  2877. if (!lua_interface)
  2878. return 0;
  2879. Spawn* spawn = lua_interface->GetSpawn(state);
  2880. if (spawn && spawn->IsEntity()) {
  2881. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2882. return 1;
  2883. }
  2884. return 0;
  2885. }
  2886. int EQ2Emu_lua_GetSta(lua_State* state) {
  2887. if (!lua_interface)
  2888. return 0;
  2889. Spawn* spawn = lua_interface->GetSpawn(state);
  2890. if (spawn && spawn->IsEntity()) {
  2891. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2892. return 1;
  2893. }
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetStr(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn && spawn->IsEntity()) {
  2901. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2902. return 1;
  2903. }
  2904. return 0;
  2905. }
  2906. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2907. if (!lua_interface)
  2908. return 0;
  2909. Spawn* spawn = lua_interface->GetSpawn(state);
  2910. if (spawn && spawn->IsEntity()) {
  2911. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2912. return 1;
  2913. }
  2914. return 0;
  2915. }
  2916. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2917. if (!lua_interface)
  2918. return 0;
  2919. Spawn* spawn = lua_interface->GetSpawn(state);
  2920. if (spawn && spawn->IsEntity()) {
  2921. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2922. return 1;
  2923. }
  2924. return 0;
  2925. }
  2926. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2927. if (!lua_interface)
  2928. return 0;
  2929. Spawn* spawn = lua_interface->GetSpawn(state);
  2930. if (spawn && spawn->IsEntity()) {
  2931. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2932. return 1;
  2933. }
  2934. return 0;
  2935. }
  2936. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2937. if (!lua_interface)
  2938. return 0;
  2939. Spawn* spawn = lua_interface->GetSpawn(state);
  2940. if (spawn && spawn->IsEntity()) {
  2941. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2942. return 1;
  2943. }
  2944. return 0;
  2945. }
  2946. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2947. if (!lua_interface)
  2948. return 0;
  2949. Spawn* spawn = lua_interface->GetSpawn(state);
  2950. if (spawn && spawn->IsEntity()) {
  2951. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2952. return 1;
  2953. }
  2954. return 0;
  2955. }
  2956. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2957. if (!lua_interface)
  2958. return 0;
  2959. Spawn* spawn = lua_interface->GetSpawn(state);
  2960. if (spawn && spawn->IsEntity()) {
  2961. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2962. return 1;
  2963. }
  2964. return 0;
  2965. }
  2966. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2967. if (!lua_interface)
  2968. return 0;
  2969. Spawn* player = lua_interface->GetSpawn(state);
  2970. if (!player || !player->IsPlayer()) {
  2971. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2972. return 0;
  2973. }
  2974. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2975. if (quest_id <= 0) {
  2976. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2977. return 0;
  2978. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2979. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2980. return 0;
  2981. }
  2982. int32 step = lua_interface->GetInt32Value(state, 3);
  2983. if (step > 0) {
  2984. Client* client = player->GetZone()->GetClientBySpawn(player);
  2985. if (client)
  2986. client->AddPendingQuestUpdate(quest_id, step);
  2987. } else {
  2988. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2993. Spawn* player = lua_interface->GetSpawn(state);
  2994. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2995. int32 step = lua_interface->GetInt32Value(state, 3);
  2996. int32 progress = lua_interface->GetInt32Value(state, 4);
  2997. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2998. Client* client = player->GetZone()->GetClientBySpawn(player);
  2999. if (client)
  3000. client->AddPendingQuestUpdate(quest_id, step, progress);
  3001. }
  3002. return 0;
  3003. }
  3004. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3005. if (!lua_interface)
  3006. return 0;
  3007. Spawn* player = lua_interface->GetSpawn(state);
  3008. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3009. if (player && player->IsPlayer() && quest_id > 0) {
  3010. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3011. return 1;
  3012. }
  3013. return 0;
  3014. }
  3015. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3016. if (!lua_interface)
  3017. return 0;
  3018. Spawn* player = lua_interface->GetSpawn(state);
  3019. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3020. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3021. if (player && player->IsPlayer() && quest_id > 0) {
  3022. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3023. return 1;
  3024. }
  3025. return 0;
  3026. }
  3027. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3028. if (!lua_interface)
  3029. return 0;
  3030. Spawn* player = lua_interface->GetSpawn(state);
  3031. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3032. if (player && player->IsPlayer() && quest_id > 0) {
  3033. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3034. return 1;
  3035. }
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Quest* quest = lua_interface->GetQuest(state);
  3042. string name = lua_interface->GetStringValue(state, 2);
  3043. string type = lua_interface->GetStringValue(state, 3);
  3044. string zone = lua_interface->GetStringValue(state, 4);
  3045. int16 level = lua_interface->GetInt16Value(state, 5);
  3046. string description = lua_interface->GetStringValue(state, 6);
  3047. bool load = true;
  3048. if (!quest) {
  3049. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3050. load = false;
  3051. }
  3052. if (load && name.length() == 0) {
  3053. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3054. load = false;
  3055. }
  3056. if (load && type.length() == 0) {
  3057. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3058. load = false;
  3059. }
  3060. if (load && zone.length() == 0) {
  3061. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3062. load = false;
  3063. }
  3064. if (load && description.length() == 0) {
  3065. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3066. load = false;
  3067. }
  3068. if (load && level == 0) {
  3069. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3070. load = false;
  3071. }
  3072. if (load)
  3073. quest->RegisterQuest(name, type, zone, level, description);
  3074. return 0;
  3075. }
  3076. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3077. if (!lua_interface)
  3078. return 0;
  3079. Quest* quest = lua_interface->GetQuest(state);
  3080. if (quest) {
  3081. int8 level = lua_interface->GetInt16Value(state, 2);
  3082. quest->SetPrereqLevel(level);
  3083. }
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3087. if (!lua_interface)
  3088. return 0;
  3089. Quest* quest = lua_interface->GetQuest(state);
  3090. if (quest) {
  3091. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3092. quest->AddPrereqQuest(quest_id);
  3093. }
  3094. return 0;
  3095. }
  3096. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3097. if (!lua_interface)
  3098. return 0;
  3099. Quest* quest = lua_interface->GetQuest(state);
  3100. if (quest) {
  3101. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3102. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3103. if (quantity == 0)
  3104. quantity = 1;
  3105. Item* master_item = master_item_list.GetItem(item_id);
  3106. if (master_item) {
  3107. Item* item = new Item(master_item);
  3108. item->details.count = quantity;
  3109. quest->AddPrereqItem(item);
  3110. }
  3111. }
  3112. return 0;
  3113. }
  3114. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3115. if (!lua_interface)
  3116. return 0;
  3117. Spawn* player = lua_interface->GetSpawn(state);
  3118. if(!player || !player->IsPlayer()) {
  3119. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3120. return 0;
  3121. }
  3122. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3123. if (quest_id > 0) {
  3124. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3125. return 1;
  3126. } else {
  3127. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Quest* quest = lua_interface->GetQuest(state);
  3135. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3136. if (quest && spawn_id > 0)
  3137. quest->SetQuestReturnNPC(spawn_id);
  3138. return 0;
  3139. }
  3140. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3141. if (!lua_interface)
  3142. return 0;
  3143. Spawn* spawn = lua_interface->GetSpawn(state);
  3144. if (!spawn) {
  3145. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3146. return 0;
  3147. }
  3148. int32 time = lua_interface->GetInt32Value(state, 2);
  3149. if (time <= 0) {
  3150. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3151. return 0;
  3152. }
  3153. string function = lua_interface->GetStringValue(state, 3);
  3154. if (function.length() == 0) {
  3155. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3156. return 0;
  3157. }
  3158. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3159. Spawn* player = lua_interface->GetSpawn(state, 5);
  3160. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3161. if ( time < 10)
  3162. time = 10;
  3163. timer->timer = Timer::GetCurrentTime2() + time;
  3164. timer->function = function;
  3165. timer->spawn = spawn->GetID();
  3166. timer->player = player ? player->GetID() : 0;
  3167. if (max_count == 0)
  3168. max_count = 1;
  3169. timer->max_count = max_count;
  3170. timer->current_count = 0;
  3171. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3172. return 0;
  3173. }
  3174. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3175. if (!lua_interface)
  3176. return 0;
  3177. Spawn* player = lua_interface->GetSpawn(state);
  3178. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3179. if (player && player->IsPlayer() && quest_id > 0) {
  3180. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3181. return 1;
  3182. }
  3183. return 0;
  3184. }
  3185. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3186. if (!lua_interface)
  3187. return 0;
  3188. Spawn* player = lua_interface->GetSpawn(state);
  3189. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3190. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3191. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3192. if (quest)
  3193. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3194. return 1;
  3195. }
  3196. return 0;
  3197. }
  3198. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3199. if (!lua_interface)
  3200. return 0;
  3201. Spawn* player = lua_interface->GetSpawn(state);
  3202. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3203. if (player && player->IsPlayer() && quest_id > 0) {
  3204. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3205. return 1;
  3206. }
  3207. return 0;
  3208. }
  3209. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3210. if (!lua_interface)
  3211. return 0;
  3212. Spawn* npc = lua_interface->GetSpawn(state);
  3213. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3214. if (npc && !npc->IsPlayer() && quest_id > 0)
  3215. npc->AddProvidedQuest(quest_id);
  3216. return 0;
  3217. }
  3218. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3219. if (!lua_interface)
  3220. return 0;
  3221. Spawn* npc = lua_interface->GetSpawn(state);
  3222. Spawn* player = lua_interface->GetSpawn(state, 2);
  3223. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3224. bool forced = lua_interface->GetBooleanValue(state, 4);
  3225. /* NPC is allowed to be null */
  3226. if (player && player->IsPlayer() && quest_id > 0) {
  3227. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3228. if (master_quest) {
  3229. Client* client = player->GetZone()->GetClientBySpawn(player);
  3230. if (!client) {
  3231. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3232. }
  3233. Quest* quest = new Quest(master_quest);
  3234. if (!quest) {
  3235. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3236. }
  3237. if (client && quest) {
  3238. if (npc)
  3239. quest->SetQuestGiver(npc->GetDatabaseID());
  3240. else
  3241. quest->SetQuestGiver(0);
  3242. client->AddPendingQuest(quest, forced);
  3243. }
  3244. }
  3245. else {
  3246. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3247. }
  3248. }
  3249. else {
  3250. 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);
  3251. }
  3252. return 0;
  3253. }
  3254. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3255. if (!lua_interface)
  3256. return 0;
  3257. Quest* quest = lua_interface->GetQuest(state);
  3258. if (quest) {
  3259. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3260. quest->AddPrereqClass(class_id);
  3261. }
  3262. return 0;
  3263. }
  3264. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3265. if (!lua_interface)
  3266. return 0;
  3267. Quest* quest = lua_interface->GetQuest(state);
  3268. if (quest) {
  3269. int8 race = lua_interface->GetInt8Value(state, 2);
  3270. quest->AddPrereqRace(race);
  3271. }
  3272. return 0;
  3273. }
  3274. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3275. if (!lua_interface)
  3276. return 0;
  3277. Quest* quest = lua_interface->GetQuest(state);
  3278. if (quest) {
  3279. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3280. quest->AddPrereqModelType(model_type);
  3281. }
  3282. return 0;
  3283. }
  3284. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3285. if (!lua_interface)
  3286. return 0;
  3287. Quest* quest = lua_interface->GetQuest(state);
  3288. if (!quest) {
  3289. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3290. return 0;
  3291. }
  3292. int8 level = lua_interface->GetInt8Value(state, 2);
  3293. quest->SetPrereqTSLevel(level);
  3294. return 0;
  3295. }
  3296. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3297. if (!lua_interface)
  3298. return 0;
  3299. Quest* quest = lua_interface->GetQuest(state);
  3300. if (!quest) {
  3301. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3302. return 0;
  3303. }
  3304. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3305. quest->AddPrereqTradeskillClass(class_id);
  3306. return 0;
  3307. }
  3308. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3309. if (!lua_interface)
  3310. return 0;
  3311. Quest* quest = lua_interface->GetQuest(state);
  3312. if (quest) {
  3313. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3314. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3315. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3316. quest->AddPrereqFaction(faction_id, min, max);
  3317. }
  3318. return 0;
  3319. }
  3320. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3321. if (!lua_interface)
  3322. return 0;
  3323. Quest* quest = lua_interface->GetQuest(state);
  3324. if (quest) {
  3325. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3326. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3327. if (quantity == 0)
  3328. quantity = 1;
  3329. Item* master_item = master_item_list.GetItem(item_id);
  3330. if (master_item) {
  3331. Item* item = new Item(master_item);
  3332. item->details.count = quantity;
  3333. quest->AddSelectableRewardItem(item);
  3334. }
  3335. }
  3336. return 0;
  3337. }
  3338. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3339. if (!lua_interface)
  3340. return 0;
  3341. Quest* quest = lua_interface->GetQuest(state);
  3342. if (quest) {
  3343. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3344. vector<Item*>* items = quest->GetRewardItems();
  3345. if (items) {
  3346. vector<Item*>::iterator itr;
  3347. for (itr = items->begin(); itr != items->end(); itr++) {
  3348. if (*itr && (*itr)->details.item_id == item_id) {
  3349. lua_interface->SetBooleanValue(state, true);
  3350. return 1;
  3351. }
  3352. }
  3353. }
  3354. }
  3355. lua_interface->SetBooleanValue(state, false);
  3356. return 1;
  3357. }
  3358. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3359. if (!lua_interface)
  3360. return 0;
  3361. Quest* quest = lua_interface->GetQuest(state);
  3362. if (quest) {
  3363. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3364. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3365. if (quantity == 0)
  3366. quantity = 1;
  3367. Item* master_item = master_item_list.GetItem(item_id);
  3368. if (master_item) {
  3369. Item* item = new Item(master_item);
  3370. item->details.count = quantity;
  3371. quest->AddRewardItem(item);
  3372. }
  3373. }
  3374. return 0;
  3375. }
  3376. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3377. if (!lua_interface)
  3378. return 0;
  3379. Quest* quest = lua_interface->GetQuest(state);
  3380. if (quest) {
  3381. int32 copper = lua_interface->GetInt32Value(state, 2);
  3382. int32 silver = lua_interface->GetInt32Value(state, 3);
  3383. int32 gold = lua_interface->GetInt32Value(state, 4);
  3384. int32 plat = lua_interface->GetInt32Value(state, 5);
  3385. quest->AddRewardCoins(copper, silver, gold, plat);
  3386. }
  3387. return 0;
  3388. }
  3389. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3390. if (!lua_interface)
  3391. return 0;
  3392. Quest* quest = lua_interface->GetQuest(state);
  3393. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3394. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3395. if (quest && faction_id > 0 && amount != 0)
  3396. quest->AddRewardFaction(faction_id, amount);
  3397. return 0;
  3398. }
  3399. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3400. if (!lua_interface)
  3401. return 0;
  3402. Quest* quest = lua_interface->GetQuest(state);
  3403. if (quest) {
  3404. int32 status = lua_interface->GetInt32Value(state, 2);
  3405. quest->SetRewardStatus(status);
  3406. }
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3410. if (!lua_interface)
  3411. return 0;
  3412. Quest* quest = lua_interface->GetQuest(state);
  3413. if (quest) {
  3414. int32 status = lua_interface->GetInt32Value(state, 2);
  3415. quest->SetStatusTmpReward(status);
  3416. }
  3417. return 0;
  3418. }
  3419. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3420. if (!lua_interface)
  3421. return 0;
  3422. Quest* quest = lua_interface->GetQuest(state);
  3423. if (quest) {
  3424. int64 coins = lua_interface->GetInt64Value(state, 2);
  3425. quest->SetCoinTmpReward(coins);
  3426. }
  3427. return 0;
  3428. }
  3429. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3430. if (!lua_interface)
  3431. return 0;
  3432. Quest* quest = lua_interface->GetQuest(state);
  3433. if (quest) {
  3434. string comment = lua_interface->GetStringValue(state, 2);
  3435. quest->SetRewardComment(comment);
  3436. }
  3437. return 0;
  3438. }
  3439. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3440. if (!lua_interface)
  3441. return 0;
  3442. Quest* quest = lua_interface->GetQuest(state);
  3443. if (quest) {
  3444. int32 exp = lua_interface->GetInt32Value(state, 2);
  3445. quest->SetRewardXP(exp);
  3446. }
  3447. return 0;
  3448. }
  3449. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3450. Quest* quest = lua_interface->GetQuest(state);
  3451. if (quest) {
  3452. int32 step = lua_interface->GetInt32Value(state, 2);
  3453. string description = lua_interface->GetStringValue(state, 3);
  3454. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3455. float percentage = lua_interface->GetFloatValue(state, 5);
  3456. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3457. int16 icon = lua_interface->GetInt16Value(state, 7);
  3458. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3459. const char* taskgroup = 0;
  3460. if (str_taskgroup.length() > 0)
  3461. taskgroup = str_taskgroup.c_str();
  3462. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3463. if (quest_step && icon && quantity > 0)
  3464. quest_step->SetIcon(icon);
  3465. }
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3469. {
  3470. if (!lua_interface)
  3471. return 0;
  3472. Quest* quest = lua_interface->GetQuest(state);
  3473. if (quest) {
  3474. int32 step = lua_interface->GetInt32Value(state, 2);
  3475. string description = lua_interface->GetStringValue(state, 3);
  3476. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3477. float percentage = lua_interface->GetFloatValue(state, 5);
  3478. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3479. int16 icon = lua_interface->GetInt16Value(state, 7);
  3480. const char* taskgroup = 0;
  3481. if (str_taskgroup.length() > 0)
  3482. taskgroup = str_taskgroup.c_str();
  3483. int32 id = 0;
  3484. vector<int32>* ids = 0;
  3485. int i = 0;
  3486. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3487. if (ids == 0)
  3488. ids = new vector<int32>;
  3489. ids->push_back(id);
  3490. i++;
  3491. }
  3492. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3493. if (quest_step && icon > 0 && quantity > 0)
  3494. quest_step->SetIcon(icon);
  3495. if (quest->GetPlayer()) {
  3496. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3497. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3498. }
  3499. safe_delete(ids);
  3500. }
  3501. return 0;
  3502. }
  3503. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3504. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3505. }
  3506. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3507. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3508. }
  3509. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3510. if (!lua_interface)
  3511. return 0;
  3512. Quest* quest = lua_interface->GetQuest(state);
  3513. if (quest) {
  3514. int32 step = lua_interface->GetInt32Value(state, 2);
  3515. string description = lua_interface->GetStringValue(state, 3);
  3516. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3517. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3518. int16 icon = lua_interface->GetInt16Value(state, 6);
  3519. const char* taskgroup = 0;
  3520. if (str_taskgroup.length() > 0)
  3521. taskgroup = str_taskgroup.c_str();
  3522. int32 npc_id = 0;
  3523. vector<int32>* ids = 0;
  3524. int i = 0;
  3525. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3526. if (ids == 0)
  3527. ids = new vector<int32>;
  3528. ids->push_back(npc_id);
  3529. i++;
  3530. }
  3531. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3532. if (quest_step && icon > 0)
  3533. quest_step->SetIcon(icon);
  3534. if (quest->GetPlayer()) {
  3535. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3536. if(client)
  3537. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3538. }
  3539. safe_delete(ids);
  3540. }
  3541. return 0;
  3542. }
  3543. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3544. if (!lua_interface)
  3545. return 0;
  3546. Quest* quest = lua_interface->GetQuest(state);
  3547. if (quest) {
  3548. int32 step = lua_interface->GetInt32Value(state, 2);
  3549. string description = lua_interface->GetStringValue(state, 3);
  3550. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3551. float percentage = lua_interface->GetFloatValue(state, 5);
  3552. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3553. int16 icon = lua_interface->GetInt16Value(state, 7);
  3554. const char* taskgroup = 0;
  3555. if (str_taskgroup.length() > 0)
  3556. taskgroup = str_taskgroup.c_str();
  3557. int32 item_id = 0;
  3558. vector<int32>* ids = 0;
  3559. int i = 0;
  3560. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3561. if (ids == 0)
  3562. ids = new vector<int32>;
  3563. ids->push_back(item_id);
  3564. i++;
  3565. }
  3566. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3567. if (quest_step && icon > 0 && quantity > 0)
  3568. quest_step->SetIcon(icon);
  3569. if (quest->GetPlayer()) {
  3570. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3571. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3572. }
  3573. safe_delete(ids);
  3574. }
  3575. return 0;
  3576. }
  3577. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3578. if (!lua_interface)
  3579. return 0;
  3580. Quest* quest = lua_interface->GetQuest(state);
  3581. if (quest) {
  3582. int32 step = lua_interface->GetInt32Value(state, 2);
  3583. string description = lua_interface->GetStringValue(state, 3);
  3584. float max_variation = lua_interface->GetFloatValue(state, 4);
  3585. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3586. int16 icon = lua_interface->GetInt16Value(state, 6);
  3587. const char* taskgroup = 0;
  3588. if (str_taskgroup.length() > 0)
  3589. taskgroup = str_taskgroup.c_str();
  3590. vector<Location>* locations = 0;
  3591. int8 i = 7;
  3592. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3593. while (true) {
  3594. Location loc;
  3595. loc.x = lua_interface->GetFloatValue(state, i);
  3596. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3597. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3598. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3599. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3600. break;
  3601. if (locations == 0)
  3602. locations = new vector<Location>;
  3603. locations->push_back(loc);
  3604. i += 4;
  3605. }
  3606. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3607. if (quest_step && icon > 0)
  3608. quest_step->SetIcon(icon);
  3609. if (quest->GetPlayer()) {
  3610. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3611. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3612. }
  3613. }
  3614. return 0;
  3615. }
  3616. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3617. if (!lua_interface)
  3618. return 0;
  3619. Quest* quest = lua_interface->GetQuest(state);
  3620. if (quest) {
  3621. int32 step = lua_interface->GetInt32Value(state, 2);
  3622. string description = lua_interface->GetStringValue(state, 3);
  3623. float max_variation = lua_interface->GetFloatValue(state, 4);
  3624. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3625. int16 icon = lua_interface->GetInt16Value(state, 6);
  3626. const char* taskgroup = 0;
  3627. if (str_taskgroup.length() > 0)
  3628. taskgroup = str_taskgroup.c_str();
  3629. vector<Location>* locations = 0;
  3630. int8 i = 7;
  3631. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3632. while (true) {
  3633. Location loc;
  3634. loc.x = lua_interface->GetFloatValue(state, i);
  3635. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3636. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3637. loc.zone_id = 0;
  3638. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3639. break;
  3640. if (locations == 0)
  3641. locations = new vector<Location>;
  3642. locations->push_back(loc);
  3643. i += 3;
  3644. }
  3645. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3646. if (quest_step && icon > 0)
  3647. quest_step->SetIcon(icon);
  3648. if (quest->GetPlayer()) {
  3649. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3650. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3651. }
  3652. }
  3653. return 0;
  3654. }
  3655. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3656. if (!lua_interface)
  3657. return 0;
  3658. Quest* quest = lua_interface->GetQuest(state);
  3659. if (quest) {
  3660. int32 step = lua_interface->GetInt32Value(state, 2);
  3661. string description = lua_interface->GetStringValue(state, 3);
  3662. float max_variation = lua_interface->GetFloatValue(state, 4);
  3663. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3664. int16 icon = lua_interface->GetInt16Value(state, 6);
  3665. const char* taskgroup = 0;
  3666. if (str_taskgroup.length() > 0)
  3667. taskgroup = str_taskgroup.c_str();
  3668. vector<Location>* locations = 0;
  3669. int i = 7;
  3670. while (true) {
  3671. Location loc;
  3672. loc.x = lua_interface->GetFloatValue(state, i);
  3673. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3674. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3675. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3676. break;
  3677. if (locations == 0)
  3678. locations = new vector<Location>;
  3679. locations->push_back(loc);
  3680. i += 3;
  3681. }
  3682. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3683. if (quest_step && icon > 0)
  3684. quest_step->SetIcon(icon);
  3685. if (quest->GetPlayer()) {
  3686. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3687. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3688. }
  3689. }
  3690. return 0;
  3691. }
  3692. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3693. Quest* quest = lua_interface->GetQuest(state);
  3694. if (quest) {
  3695. int32 step = lua_interface->GetInt32Value(state, 2);
  3696. string description = lua_interface->GetStringValue(state, 3);
  3697. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3698. float percentage = lua_interface->GetFloatValue(state, 5);
  3699. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3700. int16 icon = lua_interface->GetInt16Value(state, 7);
  3701. const char* taskgroup = 0;
  3702. if (str_taskgroup.length() > 0)
  3703. taskgroup = str_taskgroup.c_str();
  3704. int32 spell_id = 0;
  3705. vector<int32>* ids = 0;
  3706. int i = 0;
  3707. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3708. if (ids == 0)
  3709. ids = new vector<int32>;
  3710. ids->push_back(spell_id);
  3711. i++;
  3712. }
  3713. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3714. if (quest_step && icon > 0 && quantity > 0)
  3715. quest_step->SetIcon(icon);
  3716. if (quest->GetPlayer()) {
  3717. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3718. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3719. }
  3720. safe_delete(ids);
  3721. }
  3722. return 0;
  3723. }
  3724. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3725. if (!lua_interface)
  3726. return 0;
  3727. Quest* quest = lua_interface->GetQuest(state);
  3728. if (quest) {
  3729. int32 step = lua_interface->GetInt32Value(state, 2);
  3730. string description = lua_interface->GetStringValue(state, 3);
  3731. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3732. float percentage = lua_interface->GetFloatValue(state, 5);
  3733. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3734. int16 icon = lua_interface->GetInt16Value(state, 7);
  3735. const char* taskgroup = 0;
  3736. if (str_taskgroup.length() > 0)
  3737. taskgroup = str_taskgroup.c_str();
  3738. int32 item_id = 0;
  3739. vector<int32>* ids = 0;
  3740. int i = 0;
  3741. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3742. if (ids == 0)
  3743. ids = new vector<int32>;
  3744. ids->push_back(item_id);
  3745. i++;
  3746. }
  3747. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3748. if (quest_step && icon > 0 && quantity > 0)
  3749. quest_step->SetIcon(icon);
  3750. if (quest->GetPlayer()) {
  3751. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3752. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3753. }
  3754. safe_delete(ids);
  3755. }
  3756. return 0;
  3757. }
  3758. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3759. if (!lua_interface)
  3760. return 0;
  3761. Quest* quest = lua_interface->GetQuest(state);
  3762. if (quest) {
  3763. int32 step = lua_interface->GetInt32Value(state, 2);
  3764. string description = lua_interface->GetStringValue(state, 3);
  3765. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3766. float percentage = lua_interface->GetFloatValue(state, 5);
  3767. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3768. int16 icon = lua_interface->GetInt16Value(state, 7);
  3769. const char* taskgroup = 0;
  3770. if (str_taskgroup.length() > 0)
  3771. taskgroup = str_taskgroup.c_str();
  3772. int32 item_id = 0;
  3773. vector<int32>* ids = 0;
  3774. int i = 0;
  3775. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3776. if (ids == 0)
  3777. ids = new vector<int32>;
  3778. ids->push_back(item_id);
  3779. i++;
  3780. }
  3781. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3782. if (quest_step && icon > 0 && quantity > 0)
  3783. quest_step->SetIcon(icon);
  3784. if (quest->GetPlayer()) {
  3785. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3786. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3787. }
  3788. safe_delete(ids);
  3789. }
  3790. return 0;
  3791. }
  3792. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3793. if (!lua_interface)
  3794. return 0;
  3795. Quest* quest = lua_interface->GetQuest(state);
  3796. if (quest) {
  3797. string action = lua_interface->GetStringValue(state, 2);
  3798. if (action.length() > 0)
  3799. quest->SetCompleteAction(action);
  3800. }
  3801. return 0;
  3802. }
  3803. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3804. if (!lua_interface)
  3805. return 0;
  3806. Quest* quest = lua_interface->GetQuest(state);
  3807. if (quest) {
  3808. int32 step = lua_interface->GetInt32Value(state, 2);
  3809. string action = lua_interface->GetStringValue(state, 3);
  3810. if (step > 0 && action.length() > 0)
  3811. quest->AddCompleteAction(step, action);
  3812. }
  3813. return 0;
  3814. }
  3815. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3816. if (!lua_interface)
  3817. return 0;
  3818. Quest* quest = lua_interface->GetQuest(state);
  3819. if (quest) {
  3820. int32 step = lua_interface->GetInt32Value(state, 2);
  3821. string action = lua_interface->GetStringValue(state, 3);
  3822. if (step > 0 && action.length() > 0)
  3823. quest->AddProgressAction(step, action);
  3824. }
  3825. return 0;
  3826. }
  3827. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3828. if (!lua_interface)
  3829. return 0;
  3830. Quest* quest = lua_interface->GetQuest(state);
  3831. string description = lua_interface->GetStringValue(state, 2);
  3832. if (quest && description.length() > 0)
  3833. quest->SetDescription(description);
  3834. return 0;
  3835. }
  3836. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3837. if (!lua_interface)
  3838. return 0;
  3839. Quest* quest = lua_interface->GetQuest(state);
  3840. string description = lua_interface->GetStringValue(state, 2);
  3841. if (quest && description.length() > 0)
  3842. quest->SetCompletedDescription(description);
  3843. return 0;
  3844. }
  3845. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3846. if (!lua_interface)
  3847. return 0;
  3848. Quest* quest = lua_interface->GetQuest(state);
  3849. int32 step = lua_interface->GetInt32Value(state, 2);
  3850. string description = lua_interface->GetStringValue(state, 3);
  3851. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3852. if (quest && step > 0 && description.length() > 0) {
  3853. quest->SetTaskGroupDescription(step, description, display_bullets);
  3854. /* if (quest->GetPlayer()) {
  3855. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3856. if (client)
  3857. client->SendQuestUpdateStep(quest, step, false);
  3858. }*/
  3859. }
  3860. return 0;
  3861. }
  3862. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3863. if (!lua_interface)
  3864. return 0;
  3865. Quest* quest = lua_interface->GetQuest(state);
  3866. int32 step = lua_interface->GetInt32Value(state, 2);
  3867. string description = lua_interface->GetStringValue(state, 3);
  3868. if (quest && step > 0 && description.length() > 0) {
  3869. quest->SetStepDescription(step, description);
  3870. /*if (quest->GetPlayer()) {
  3871. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3872. if (client)
  3873. client->SendQuestUpdateStepImmediately(quest, step);
  3874. }*/
  3875. }
  3876. return 0;
  3877. }
  3878. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3879. Quest* quest = lua_interface->GetQuest(state);
  3880. string zone = lua_interface->GetStringValue(state, 2);
  3881. if (quest && zone.length() > 0)
  3882. quest->SetZone(zone);
  3883. return 0;
  3884. }
  3885. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3886. if (!lua_interface)
  3887. return 0;
  3888. Quest* quest = lua_interface->GetQuest(state);
  3889. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3890. lua_interface->ResetFunctionStack(state);
  3891. if (quest && spawn) {
  3892. if (spawn->IsPlayer()) {
  3893. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3894. if (client)
  3895. {
  3896. client->AddPendingQuestAcceptReward(quest);
  3897. client->AddPendingQuestReward(quest);
  3898. }
  3899. }
  3900. }
  3901. return 0;
  3902. }
  3903. int EQ2Emu_lua_Harvest(lua_State* state) {
  3904. if (!lua_interface)
  3905. return 0;
  3906. Spawn* player = lua_interface->GetSpawn(state);
  3907. Spawn* node = lua_interface->GetSpawn(state, 2);
  3908. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3909. Client* client = player->GetZone()->GetClientBySpawn(player);
  3910. if (client) {
  3911. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3912. ((GroundSpawn*)node)->ProcessHarvest(client);
  3913. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3914. player->GetZone()->RemoveSpawn(node, true);
  3915. }
  3916. }
  3917. else if (player && player->IsPlayer()) {
  3918. Client* client = player->GetZone()->GetClientBySpawn(player);
  3919. if (client)
  3920. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3921. }
  3922. return 0;
  3923. }
  3924. int EQ2Emu_lua_Bind(lua_State* state) {
  3925. if (!lua_interface)
  3926. return 0;
  3927. Spawn* spawn = lua_interface->GetSpawn(state);
  3928. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3929. float x = lua_interface->GetFloatValue(state, 3);
  3930. float y = lua_interface->GetFloatValue(state, 4);
  3931. float z = lua_interface->GetFloatValue(state, 5);
  3932. float h = lua_interface->GetFloatValue(state, 6);
  3933. if (!spawn) {
  3934. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3935. return 0;
  3936. }
  3937. if (!spawn->IsPlayer()) {
  3938. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3939. return 0;
  3940. }
  3941. if (zone_id == 0) {
  3942. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3943. if (!client) {
  3944. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3945. return 0;
  3946. }
  3947. if (!client->Bind())
  3948. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3949. }
  3950. else {
  3951. Player* player = (Player*)spawn;
  3952. player->GetPlayerInfo()->SetBindZone(zone_id);
  3953. player->GetPlayerInfo()->SetBindX(x);
  3954. player->GetPlayerInfo()->SetBindY(y);
  3955. player->GetPlayerInfo()->SetBindZ(z);
  3956. player->GetPlayerInfo()->SetBindHeading(h);
  3957. }
  3958. return 0;
  3959. }
  3960. int EQ2Emu_lua_Gate(lua_State* state) {
  3961. if (!lua_interface)
  3962. return 0;
  3963. Spawn* spawn = lua_interface->GetSpawn(state);
  3964. if (spawn) {
  3965. if (spawn->IsPlayer()) {
  3966. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3967. if (client) {
  3968. if (!client->Gate())
  3969. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3970. }
  3971. }
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3976. if (!lua_interface)
  3977. return 0;
  3978. bool ret = false;
  3979. Spawn* spawn = lua_interface->GetSpawn(state);
  3980. if (spawn) {
  3981. if (spawn->IsPlayer()) {
  3982. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3983. if (client)
  3984. ret = client->BindAllowed();
  3985. }
  3986. }
  3987. lua_interface->SetBooleanValue(state, ret);
  3988. return 1;
  3989. }
  3990. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3991. if (!lua_interface)
  3992. return 0;
  3993. bool ret = false;
  3994. Spawn* spawn = lua_interface->GetSpawn(state);
  3995. if (spawn) {
  3996. if (spawn->IsPlayer()) {
  3997. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3998. if (client)
  3999. ret = client->GateAllowed();
  4000. }
  4001. }
  4002. lua_interface->SetBooleanValue(state, ret);
  4003. return 1;
  4004. }
  4005. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4006. Spawn* spawn = lua_interface->GetSpawn(state);
  4007. if (spawn) {
  4008. lua_interface->SetBooleanValue(state, spawn->Alive());
  4009. return 1;
  4010. }
  4011. return 0;
  4012. }
  4013. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4014. if (!lua_interface)
  4015. return 0;
  4016. Spawn* spawn = lua_interface->GetSpawn(state);
  4017. if (spawn && spawn->IsEntity()) {
  4018. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4019. return 1;
  4020. }
  4021. return 0;
  4022. }
  4023. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4024. Spawn* spawn = lua_interface->GetSpawn(state);
  4025. string message = lua_interface->GetStringValue(state, 2);
  4026. string color_str = lua_interface->GetStringValue(state, 3);
  4027. int8 color = CHANNEL_NARRATIVE;
  4028. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4029. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4030. if (client) {
  4031. if (color_str.length() > 0) {
  4032. // leave for backwards compat, but all future should just use the number
  4033. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4034. color = CHANNEL_COLOR_RED;
  4035. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4036. color = CHANNEL_COLOR_YELLOW;
  4037. else
  4038. {
  4039. // use a number to specify the channel as per Commands/Commands.h defines
  4040. color = (int8)atoul(color_str.c_str());
  4041. }
  4042. }
  4043. client->SimpleMessage(color, message.c_str());
  4044. }
  4045. }
  4046. return 0;
  4047. }
  4048. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4049. Spawn* spawn = lua_interface->GetSpawn(state);
  4050. string message = lua_interface->GetStringValue(state, 2);
  4051. int8 red = lua_interface->GetInt8Value(state, 3);
  4052. int8 green = lua_interface->GetInt8Value(state, 4);
  4053. int8 blue = lua_interface->GetInt8Value(state, 5);
  4054. if (!spawn) {
  4055. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4056. return 0;
  4057. }
  4058. int32 words = ::CountWordsInString(message.c_str());
  4059. if (words < 5)
  4060. words = 5;
  4061. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4062. if (client)
  4063. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4064. return 0;
  4065. }
  4066. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4067. Spawn* spawn = lua_interface->GetSpawn(state);
  4068. int8 param = lua_interface->GetInt8Value(state, 2);
  4069. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4070. int8 value = lua_interface->GetInt8Value(state, 4);
  4071. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4072. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4073. if (client) {
  4074. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4075. switch (param) {
  4076. case 1: {
  4077. packet->setDataByName("parameter1", param_value);
  4078. break;
  4079. }
  4080. case 2: {
  4081. packet->setDataByName("parameter2", param_value);
  4082. break;
  4083. }
  4084. case 3: {
  4085. packet->setDataByName("parameter3", param_value);
  4086. break;
  4087. }
  4088. case 4: {
  4089. packet->setDataByName("parameter4", param_value);
  4090. break;
  4091. }
  4092. case 5: {
  4093. packet->setDataByName("parameter5", param_value);
  4094. break;
  4095. }
  4096. }
  4097. packet->setDataByName("value", value);
  4098. client->QueuePacket(packet->serialize());
  4099. safe_delete(packet);
  4100. }
  4101. }
  4102. return 0;
  4103. }
  4104. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4105. Spawn* spawn = lua_interface->GetSpawn(state);
  4106. if (spawn && spawn->IsPlayer()) {
  4107. if (((Player*)spawn)->GetIsTracking())
  4108. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4109. else
  4110. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4111. }
  4112. return 0;
  4113. }
  4114. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4115. Spawn* player = lua_interface->GetSpawn(state);
  4116. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4117. string name = lua_interface->GetStringValue(state, 3);
  4118. float distance = lua_interface->GetFloatValue(state, 4);
  4119. string command = lua_interface->GetStringValue(state, 5);
  4120. string error_text = lua_interface->GetStringValue(state, 6);
  4121. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4122. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4123. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4124. if (spawn) {
  4125. if (distance == 0)
  4126. distance = 10.0f;
  4127. if (command.length() == 0)
  4128. command = name;
  4129. if (command.length() < 1 && name.length() < 1)
  4130. {
  4131. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4132. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4133. spawn->RemovePrimaryCommands();
  4134. }
  4135. else
  4136. {
  4137. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4138. }
  4139. }
  4140. return 0;
  4141. }
  4142. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4143. if (!lua_interface)
  4144. return 0;
  4145. Spawn* player = lua_interface->GetSpawn(state);
  4146. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4147. int16 tier = lua_interface->GetInt16Value(state, 3);
  4148. if (player && player->IsPlayer()) {
  4149. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4150. return 1;
  4151. }
  4152. return 0;
  4153. }
  4154. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4155. if (!lua_interface)
  4156. return 0;
  4157. Spawn* player = lua_interface->GetSpawn(state);
  4158. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4159. int16 tier = lua_interface->GetInt16Value(state, 3);
  4160. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4161. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4162. bool add_to_hotbar = true;
  4163. if (num_args > 4) {
  4164. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4165. }
  4166. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4167. if (player && spell && player->IsPlayer()) {
  4168. Client* client = player->GetClient();
  4169. if (client) {
  4170. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4171. {
  4172. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4173. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4174. client->GetPlayer()->UnlockSpell(spell);
  4175. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4176. }
  4177. else
  4178. {
  4179. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4180. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4181. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4182. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4183. client->GetPlayer()->UnlockSpell(spell);
  4184. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4185. }
  4186. //if (client ) {
  4187. // ((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);
  4188. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4189. if (outapp)
  4190. client->QueuePacket(outapp);
  4191. }
  4192. }
  4193. return 0;
  4194. }
  4195. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4196. if (!lua_interface)
  4197. return 0;
  4198. Spawn* player = lua_interface->GetSpawn(state);
  4199. if (player && player->IsPlayer()) {
  4200. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4201. return 1;
  4202. }
  4203. return 0;
  4204. }
  4205. int EQ2Emu_lua_Attack(lua_State* state) {
  4206. if (lua_interface) {
  4207. Spawn* npc = lua_interface->GetSpawn(state);
  4208. Spawn* player = lua_interface->GetSpawn(state, 2);
  4209. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4210. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4211. }
  4212. return 0;
  4213. }
  4214. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4215. if (lua_interface) {
  4216. Spawn* target = lua_interface->GetSpawn(state);
  4217. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4218. if (target && target->GetZone())
  4219. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4220. }
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4224. Spawn* player;
  4225. if (lua_interface) {
  4226. player = lua_interface->GetSpawn(state);
  4227. if (player && player->IsPlayer()) {
  4228. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4229. return 1;
  4230. }
  4231. }
  4232. return 0;
  4233. }
  4234. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4235. Spawn* player;
  4236. Client* client;
  4237. if (lua_interface) {
  4238. player = lua_interface->GetSpawn(state);
  4239. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4240. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4241. client->HandInCollections();
  4242. }
  4243. return 0;
  4244. }
  4245. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4246. Spawn* widget;
  4247. if (lua_interface) {
  4248. widget = lua_interface->GetSpawn(state);
  4249. if (widget && widget->IsWidget())
  4250. ((Widget*)widget)->HandleUse(nullptr, "");
  4251. }
  4252. return 0;
  4253. }
  4254. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4255. Spawn* spawn = 0;
  4256. int32 primary_list = 0;
  4257. int32 secondary_list = 0;
  4258. if (lua_interface) {
  4259. spawn = lua_interface->GetSpawn(state);
  4260. primary_list = lua_interface->GetInt32Value(state, 2);
  4261. secondary_list = lua_interface->GetInt32Value(state, 3);
  4262. if (!spawn->IsNPC()) {
  4263. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4264. return 0;
  4265. }
  4266. NPC* npc = (NPC*)spawn;
  4267. npc->SetPrimarySpellList(primary_list);
  4268. npc->SetSecondarySpellList(secondary_list);
  4269. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4270. }
  4271. return 0;
  4272. }
  4273. int EQ2Emu_lua_GetPet(lua_State* state) {
  4274. if (!lua_interface)
  4275. return 0;
  4276. Spawn* spawn = lua_interface->GetSpawn(state);
  4277. if (spawn) {
  4278. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4279. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4280. return 1;
  4281. }
  4282. }
  4283. return 0;
  4284. }
  4285. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4286. if (!lua_interface)
  4287. return 0;
  4288. Spawn* spawn = lua_interface->GetSpawn(state);
  4289. if (spawn) {
  4290. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4291. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4292. return 1;
  4293. }
  4294. }
  4295. return 0;
  4296. }
  4297. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4298. if (!lua_interface)
  4299. return 0;
  4300. Spawn* spawn = lua_interface->GetSpawn(state);
  4301. if (spawn) {
  4302. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4303. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4304. return 1;
  4305. }
  4306. }
  4307. return 0;
  4308. }
  4309. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4310. if (!lua_interface)
  4311. return 0;
  4312. Spawn* spawn = lua_interface->GetSpawn(state);
  4313. if (spawn) {
  4314. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4315. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4316. return 1;
  4317. }
  4318. }
  4319. return 0;
  4320. }
  4321. int EQ2Emu_lua_Charm(lua_State* state) {
  4322. if (!lua_interface)
  4323. return 0;
  4324. Spawn* owner = lua_interface->GetSpawn(state);
  4325. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4326. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4327. if (!luaspell) {
  4328. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4329. return 0;
  4330. }
  4331. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4332. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4333. pet->SetPet(true);
  4334. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4335. ((NPC*)pet)->SetOwner((Entity*)owner);
  4336. // If owner is player and player does not have a summoned pet set the players charsheet
  4337. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4338. Player* player = (Player*)owner;
  4339. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4340. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4341. player->GetInfoStruct()->set_pet_movement(2);
  4342. player->GetInfoStruct()->set_pet_behavior(3);
  4343. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4344. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4345. // Make sure the values get sent to the client
  4346. player->SetCharSheetChanged(true);
  4347. }
  4348. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4349. pet->SetSpawnScript("");
  4350. // Set faction to the same as the owner
  4351. pet->SetFactionID(owner->GetFactionID());
  4352. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4353. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4354. // Clear hate list
  4355. ((NPC*)pet)->Brain()->ClearHate();
  4356. // Set the brain to a pet brain
  4357. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4358. }
  4359. return 0;
  4360. }
  4361. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4362. if (!lua_interface)
  4363. return 0;
  4364. Spawn* spawn = lua_interface->GetSpawn(state);
  4365. if (!spawn) {
  4366. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4367. return 0;
  4368. }
  4369. vector<Spawn*> groupMembers;
  4370. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4371. groupMembers = *spawn->GetSpawnGroup();
  4372. }
  4373. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4374. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4375. deque<GroupMemberInfo*>::iterator itr;
  4376. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4377. if (group)
  4378. {
  4379. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4380. deque<GroupMemberInfo*>* members = group->GetMembers();
  4381. GroupMemberInfo* info = 0;
  4382. for (itr = members->begin(); itr != members->end(); itr++) {
  4383. info = *itr;
  4384. if (info->client)
  4385. groupMembers.push_back(info->client->GetPlayer());
  4386. }
  4387. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4388. }
  4389. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4390. }
  4391. else
  4392. return 0;
  4393. lua_createtable(state, groupMembers.size(), 0);
  4394. int newTable = lua_gettop(state);
  4395. for (int32 i = 0; i < groupMembers.size(); i++) {
  4396. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4397. lua_rawseti(state, newTable, i + 1);
  4398. }
  4399. return 1;
  4400. }
  4401. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4402. if (!lua_interface)
  4403. return 0;
  4404. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4405. lua_interface->SetOptionWindowValue(state, option_window);
  4406. return 1;
  4407. }
  4408. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4409. if (!lua_interface)
  4410. return 0;
  4411. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4412. if (option_window) {
  4413. OptionWindowOption option_window_option;
  4414. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4415. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4416. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4417. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4418. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4419. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4420. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4421. option_window->push_back(option_window_option);
  4422. }
  4423. return 0;
  4424. }
  4425. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4426. if (!lua_interface)
  4427. return 0;
  4428. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4429. Spawn* player = lua_interface->GetSpawn(state, 2);
  4430. string window_title = lua_interface->GetStringValue(state, 3);
  4431. string cancel_command = lua_interface->GetStringValue(state, 4);
  4432. Client* client = player->GetZone()->GetClientBySpawn(player);
  4433. if (option_window && window_title.length() > 0 && client) {
  4434. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4435. if (!packet)
  4436. return 0;
  4437. packet->setDataByName("title_text", window_title.c_str());
  4438. if (cancel_command.length() > 0)
  4439. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4440. packet->setArrayLengthByName("num_selections", option_window->size());
  4441. vector<OptionWindowOption>::iterator itr;
  4442. int8 i = 0;
  4443. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4444. OptionWindowOption opt = *itr;
  4445. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4446. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4447. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4448. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4449. if (opt.optionCommand.length() > 0)
  4450. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4451. if (opt.optionConfirmTitle.length() > 0)
  4452. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4453. i++;
  4454. }
  4455. client->QueuePacket(packet->serialize());
  4456. safe_delete(option_window);
  4457. safe_delete(packet);
  4458. }
  4459. return 0;
  4460. }
  4461. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4462. if (!lua_interface)
  4463. return 0;
  4464. Spawn* spawn = lua_interface->GetSpawn(state);
  4465. if (spawn) {
  4466. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4467. return 1;
  4468. }
  4469. else
  4470. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4471. return 0;
  4472. }
  4473. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4474. if (!lua_interface)
  4475. return 0;
  4476. Spawn* spawn = lua_interface->GetSpawn(state);
  4477. if (spawn) {
  4478. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4479. return 1;
  4480. }
  4481. else
  4482. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4483. return 0;
  4484. }
  4485. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4486. if (!lua_interface)
  4487. return 0;
  4488. Spawn* spawn = lua_interface->GetSpawn(state);
  4489. if (spawn) {
  4490. int8 class_id = spawn->GetTradeskillClass();
  4491. // Need to add 42 for the offset in the array
  4492. class_id += 44;
  4493. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4494. return 1;
  4495. }
  4496. else
  4497. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4498. return 0;
  4499. }
  4500. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4501. if (!lua_interface)
  4502. return 0;
  4503. Spawn* spawn = lua_interface->GetSpawn(state);
  4504. int16 level = lua_interface->GetInt8Value(state, 2);
  4505. if (spawn) {
  4506. if (spawn->IsPlayer())
  4507. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4508. else
  4509. spawn->SetTSLevel(level);
  4510. }
  4511. else
  4512. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4513. return 0;
  4514. }
  4515. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4516. if (!lua_interface)
  4517. return 0;
  4518. Spawn* spawn = lua_interface->GetSpawn(state);
  4519. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4520. if (spawn) {
  4521. spawn->SetAttackable(attackable);
  4522. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4527. // Check to see if we have a valid lua_interface
  4528. if (!lua_interface)
  4529. return 0;
  4530. // Get the spawn that is getting the pet
  4531. Spawn* spawn = lua_interface->GetSpawn(state);
  4532. // Get the DB ID of the pet
  4533. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4534. // The max level the pet can gain
  4535. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4536. // Get the spell that this command was called from
  4537. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4538. // Check to make sure the spawn pointer is valid
  4539. if (!spawn) {
  4540. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4541. return 0;
  4542. }
  4543. // Check to make sure the spawn is an entity
  4544. if (!spawn->IsEntity()) {
  4545. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4546. return 0;
  4547. }
  4548. // Check to make sure the spawn doesn't already have a pet of this type
  4549. if (((Entity*)spawn)->GetPet()) {
  4550. if (spawn->IsPlayer()) {
  4551. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4552. if (client)
  4553. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4554. }
  4555. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4556. return 0;
  4557. }
  4558. // Check to see if the DB ID for the pet is set
  4559. if (pet_id == 0) {
  4560. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4561. return 0;
  4562. }
  4563. // Check to see if the pointer to the spell is valid
  4564. if (!luaspell) {
  4565. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4566. return 0;
  4567. }
  4568. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4569. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4570. if (!pet) {
  4571. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4572. return 0;
  4573. }
  4574. // Check to make sure the pet is an npc
  4575. if (!pet->IsNPC()) {
  4576. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4577. return 0;
  4578. }
  4579. // Spawn the pet at the same location as the owner
  4580. pet->SetX(spawn->GetX());
  4581. pet->SetY(spawn->GetY());
  4582. pet->SetZ(spawn->GetZ());
  4583. pet->SetLocation(spawn->GetLocation());
  4584. pet->SetHeading(spawn->GetHeading());
  4585. spawn->GetZone()->AddSpawn(pet);
  4586. /*
  4587. const char* spawn_script = world.GetSpawnScript(pet_id);
  4588. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4589. spawn->SetSpawnScript(string(spawn_script));
  4590. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4591. }*/
  4592. // Get a random pet name
  4593. string random_pet_name;
  4594. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4595. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4596. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4597. // If player set various values for the char sheet (pet window)
  4598. if (spawn->IsPlayer()) {
  4599. Player* player = (Player*)spawn;
  4600. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4601. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4602. player->GetInfoStruct()->set_pet_movement(2);
  4603. player->GetInfoStruct()->set_pet_behavior(3);
  4604. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4605. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4606. // Make sure the values get sent to the client
  4607. player->SetCharSheetChanged(true);
  4608. }
  4609. // Set the pets name
  4610. pet->SetName(random_pet_name.c_str());
  4611. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4612. if (max_level > 0)
  4613. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4614. else
  4615. pet->SetLevel(spawn->GetLevel());
  4616. // Set the max level this pet can reach
  4617. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4618. // Set the faction of the pet to the same faction as the owner
  4619. pet->SetFactionID(spawn->GetFactionID());
  4620. // Set the spawn as a pet
  4621. pet->SetPet(true);
  4622. // Give a pointer of the owner to the pet
  4623. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4624. // Give a pointer of the pet to the owner
  4625. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4626. // Set the pet type
  4627. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4628. // Set the spell id used to create this pet
  4629. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4630. // Set the spell tier used to create this pet
  4631. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4632. // Set the pets spawn type to 6
  4633. pet->SetSpawnType(6);
  4634. // Set the pets brain
  4635. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4636. // Check to see if the pet has a subtitle
  4637. if (strlen(pet->GetSubTitle()) > 0) {
  4638. // Add the players name to the front of the sub title
  4639. string pet_subtitle;
  4640. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4641. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4642. // Set the pets subtitle to the new one
  4643. pet->SetSubTitle(pet_subtitle.c_str());
  4644. }
  4645. // Add the "Pet Options" entity command to the pet
  4646. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4647. // Set the pet as the return value for this function
  4648. lua_interface->SetSpawnValue(state, pet);
  4649. return 1;
  4650. }
  4651. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4652. if (!lua_interface)
  4653. return 0;
  4654. Spawn* spawn = lua_interface->GetSpawn(state);
  4655. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4656. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4657. if (!spawn) {
  4658. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4659. return 0;
  4660. }
  4661. if (!spawn->IsEntity()) {
  4662. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4663. return 0;
  4664. }
  4665. if (((Entity*)spawn)->GetDeityPet()) {
  4666. if (spawn->IsPlayer()) {
  4667. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4668. if (client)
  4669. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4670. }
  4671. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4672. return 0;
  4673. }
  4674. if (pet_id == 0) {
  4675. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4676. return 0;
  4677. }
  4678. if (!luaspell) {
  4679. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4680. return 0;
  4681. }
  4682. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4683. if (!pet) {
  4684. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4685. return 0;
  4686. }
  4687. if (!pet->IsNPC()) {
  4688. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4689. return 0;
  4690. }
  4691. pet->SetX(spawn->GetX());
  4692. pet->SetY(spawn->GetY());
  4693. pet->SetZ(spawn->GetZ());
  4694. pet->SetLocation(spawn->GetLocation());
  4695. pet->SetHeading(spawn->GetHeading());
  4696. spawn->GetZone()->AddSpawn(pet);
  4697. string random_pet_name;
  4698. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4699. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4700. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4701. pet->SetName(random_pet_name.c_str());
  4702. pet->SetLevel(spawn->GetLevel());
  4703. pet->SetFactionID(spawn->GetFactionID());
  4704. pet->SetPet(true);
  4705. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4706. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4707. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4708. pet->SetSpawnType(6);
  4709. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4710. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4711. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4712. if (strlen(pet->GetSubTitle()) > 0) {
  4713. string pet_subtitle;
  4714. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4715. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4716. pet->SetSubTitle(pet_subtitle.c_str());
  4717. }
  4718. // deity and cosmetic pets are not attackable
  4719. pet->SetAttackable(false);
  4720. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4721. lua_interface->SetSpawnValue(state, pet);
  4722. return 1;
  4723. }
  4724. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4725. if (!lua_interface)
  4726. return 0;
  4727. Spawn* spawn = lua_interface->GetSpawn(state);
  4728. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4729. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4730. if (!spawn) {
  4731. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. if (!spawn->IsEntity()) {
  4735. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4736. return 0;
  4737. }
  4738. if (((Entity*)spawn)->GetCosmeticPet()) {
  4739. if (spawn->IsPlayer()) {
  4740. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4741. if (client)
  4742. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4743. }
  4744. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4745. return 0;
  4746. }
  4747. if (pet_id == 0) {
  4748. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4749. return 0;
  4750. }
  4751. if (!luaspell) {
  4752. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4756. if (!pet) {
  4757. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4758. return 0;
  4759. }
  4760. if (!pet->IsNPC()) {
  4761. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4762. return 0;
  4763. }
  4764. pet->SetX(spawn->GetX());
  4765. pet->SetY(spawn->GetY());
  4766. pet->SetZ(spawn->GetZ());
  4767. pet->SetLocation(spawn->GetLocation());
  4768. pet->SetHeading(spawn->GetHeading());
  4769. spawn->GetZone()->AddSpawn(pet);
  4770. string random_pet_name;
  4771. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4772. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4773. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4774. pet->SetName(random_pet_name.c_str());
  4775. pet->SetLevel(spawn->GetLevel());
  4776. pet->SetFactionID(spawn->GetFactionID());
  4777. pet->SetPet(true);
  4778. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4779. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4780. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4781. pet->SetSpawnType(6);
  4782. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4783. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4784. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4785. if (strlen(pet->GetSubTitle()) > 0) {
  4786. string pet_subtitle;
  4787. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4788. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4789. pet->SetSubTitle(pet_subtitle.c_str());
  4790. }
  4791. pet->SetAttackable(false);
  4792. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4793. lua_interface->SetSpawnValue(state, pet);
  4794. return 1;
  4795. }
  4796. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4797. if (!lua_interface)
  4798. return 0;
  4799. Spawn* spawn = lua_interface->GetSpawn(state);
  4800. if (!spawn) {
  4801. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4802. return 0;
  4803. }
  4804. if (!spawn->IsPet()) {
  4805. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4806. return 0;
  4807. }
  4808. if (!((NPC*)spawn)->IsDismissing())
  4809. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4810. return 0;
  4811. }
  4812. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4813. if (!lua_interface)
  4814. return 0;
  4815. Quest* quest = lua_interface->GetQuest(state);
  4816. if (!quest) {
  4817. 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));
  4818. return 0;
  4819. }
  4820. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4821. if (feather_color > 0)
  4822. quest->SetFeatherColor(feather_color);
  4823. return 0;
  4824. }
  4825. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4826. if (!lua_interface)
  4827. return 0;
  4828. Spawn* spawn = lua_interface->GetSpawn(state);
  4829. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4830. if (!spawn) {
  4831. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4832. return 0;
  4833. }
  4834. if (!spawn2) {
  4835. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4836. return 0;
  4837. }
  4838. spawn->RemoveSpawnAccess(spawn2);
  4839. return 0;
  4840. }
  4841. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4842. if (!lua_interface)
  4843. return 0;
  4844. ZoneServer* zone = lua_interface->GetZone(state);
  4845. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4846. if (!zone) {
  4847. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (location_id == 0) {
  4851. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4852. return 0;
  4853. }
  4854. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4855. if (!location) {
  4856. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4857. return 0;
  4858. }
  4859. Spawn* spawn = 0;
  4860. if (location->entities[0]) {
  4861. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4862. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4863. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4864. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4865. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4866. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4867. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4868. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4869. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4870. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4871. if(spawn && spawn->IsOmittedByDBFlag())
  4872. {
  4873. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  4874. safe_delete(spawn);
  4875. spawn = 0;
  4876. return 0;
  4877. }
  4878. if (spawn) {
  4879. const char* script = 0;
  4880. for (int x = 0; x < 3; x++) {
  4881. switch (x) {
  4882. case 0:
  4883. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4884. break;
  4885. case 1:
  4886. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4887. break;
  4888. case 2:
  4889. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4890. break;
  4891. }
  4892. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4893. spawn->SetSpawnScript(string(script));
  4894. break;
  4895. }
  4896. }
  4897. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4898. lua_interface->SetSpawnValue(state, spawn);
  4899. return 1;
  4900. }
  4901. else {
  4902. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  4903. safe_delete(spawn);
  4904. }
  4905. }
  4906. return 0;
  4907. }
  4908. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4909. if (!lua_interface)
  4910. return 0;
  4911. Spawn* caster = lua_interface->GetSpawn(state);
  4912. Spawn* target = lua_interface->GetSpawn(state, 2);
  4913. int32 id = lua_interface->GetInt32Value(state, 3);
  4914. string command = lua_interface->GetStringValue(state, 4);
  4915. if (!caster) {
  4916. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4917. return 0;
  4918. }
  4919. if (!target) {
  4920. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4921. return 0;
  4922. }
  4923. if (!caster->IsPlayer()) {
  4924. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4928. if (!entity_command) {
  4929. 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());
  4930. return 0;
  4931. }
  4932. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4933. if (!client) {
  4934. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4935. return 0;
  4936. }
  4937. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4938. return 0;
  4939. }
  4940. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4941. if (!lua_interface)
  4942. return 0;
  4943. Spawn* spawn = lua_interface->GetSpawn(state);
  4944. if (!spawn) {
  4945. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4946. return 0;
  4947. }
  4948. if (!spawn->IsNPC()) {
  4949. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4950. return 0;
  4951. }
  4952. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4953. return 0;
  4954. }
  4955. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4956. if (!lua_interface)
  4957. return 0;
  4958. Spawn* spawn = lua_interface->GetSpawn(state);
  4959. int16 tick = lua_interface->GetInt16Value(state, 2);
  4960. if (!spawn) {
  4961. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4962. return 0;
  4963. }
  4964. if (!spawn->IsNPC()) {
  4965. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4966. return 0;
  4967. }
  4968. if (tick < 20) {
  4969. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. ((NPC*)spawn)->Brain()->SetTick(tick);
  4973. return 0;
  4974. }
  4975. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4976. if (!lua_interface)
  4977. return 0;
  4978. Spawn* spawn = lua_interface->GetSpawn(state);
  4979. Spawn* target = lua_interface->GetSpawn(state, 2);
  4980. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4981. if (!spawn) {
  4982. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4983. return 0;
  4984. }
  4985. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4986. spawn->SetFollowTarget(target, follow_distance);
  4987. return 0;
  4988. }
  4989. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4990. if (!lua_interface)
  4991. return 0;
  4992. Spawn* spawn = lua_interface->GetSpawn(state);
  4993. if (!spawn) {
  4994. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4995. return 0;
  4996. }
  4997. Spawn* target = spawn->GetFollowTarget();
  4998. if (target) {
  4999. lua_interface->SetSpawnValue(state, target);
  5000. return 1;
  5001. }
  5002. return 0;
  5003. }
  5004. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5005. if (!lua_interface)
  5006. return 0;
  5007. Spawn* spawn = lua_interface->GetSpawn(state);
  5008. if (!spawn) {
  5009. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. if (spawn->following)
  5013. spawn->following = false;
  5014. else
  5015. spawn->following = true;
  5016. return 0;
  5017. }
  5018. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5019. if (!lua_interface)
  5020. return 0;
  5021. Spawn* spawn = lua_interface->GetSpawn(state);
  5022. if (!spawn) {
  5023. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5024. return 0;
  5025. }
  5026. lua_interface->SetBooleanValue(state, spawn->following);
  5027. return 1;
  5028. }
  5029. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5030. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5031. // I will attempt to explain how this function works for future refrence
  5032. // Fist lets make sure lua_interface is valid, if not return out
  5033. if (!lua_interface)
  5034. return 0;
  5035. // Next we grab the first 2 params same as we usually would
  5036. Spawn* spawn = lua_interface->GetSpawn(state);
  5037. string var = lua_interface->GetStringValue(state, 2);
  5038. // 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
  5039. // 1 = Spawn
  5040. // 2 = Zone
  5041. // 3 = Item
  5042. // 4 = Quest
  5043. // 5 = String
  5044. // 6 = nil (null)
  5045. int8 dataType = 0;
  5046. // Define pointers for each potential type
  5047. Spawn* spawnVal = 0;
  5048. ZoneServer* zone = 0;
  5049. Item* item = 0;
  5050. Quest* quest = 0;
  5051. string val;
  5052. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5053. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5054. // options window are also light user data be we do not handle those.
  5055. // We check with lua_islightuserdata(lua_State*, index)
  5056. if (lua_islightuserdata(state, 3)) {
  5057. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5058. // and convert it to LUAUserData*
  5059. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5060. // Check to make sure the data we got is valid, if not give an error
  5061. if (!data || !data->IsCorrectlyInitialized()) {
  5062. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5063. }
  5064. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5065. else if (data->IsSpawn()) {
  5066. spawnVal = data->spawn;
  5067. dataType = 1;
  5068. }
  5069. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5070. else if (data->IsZone()) {
  5071. zone = data->zone;
  5072. dataType = 2;
  5073. }
  5074. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5075. else if (data->IsItem()) {
  5076. item = data->item;
  5077. dataType = 3;
  5078. }
  5079. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5080. else if (data->IsQuest()) {
  5081. quest = data->quest;
  5082. dataType = 4;
  5083. }
  5084. }
  5085. // Wasn't light user data, check if it is nil(null)
  5086. else if (lua_isnil(state, 3)) {
  5087. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5088. dataType = 6;
  5089. }
  5090. // Wasn't light user data or nil (null), must be a string
  5091. else {
  5092. // Set the string and dataType variable
  5093. val = lua_interface->GetStringValue(state, 3);
  5094. dataType = 5;
  5095. }
  5096. // We now have all the params, lets check to make sure they are valid
  5097. if (!spawn) {
  5098. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5099. return 0;
  5100. }
  5101. if (var.length() == 0) {
  5102. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5103. return 0;
  5104. }
  5105. if (dataType == 0) {
  5106. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5107. return 0;
  5108. }
  5109. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5110. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5111. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5112. switch (dataType) {
  5113. case 1:
  5114. // 1 = Spawn
  5115. spawn->AddTempVariable(var, spawnVal);
  5116. break;
  5117. case 2:
  5118. // 2 = Zone
  5119. spawn->AddTempVariable(var, zone);
  5120. break;
  5121. case 3:
  5122. // 3 = Item
  5123. spawn->AddTempVariable(var, item);
  5124. break;
  5125. case 4:
  5126. // 4 = Quest
  5127. spawn->AddTempVariable(var, quest);
  5128. break;
  5129. case 5:
  5130. // 5 = String
  5131. spawn->AddTempVariable(var, val);
  5132. break;
  5133. case 6:
  5134. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5135. spawn->DeleteTempVariable(var);
  5136. break;
  5137. }
  5138. // And we are done so return out
  5139. return 0;
  5140. }
  5141. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5142. if (!lua_interface)
  5143. return 0;
  5144. Spawn* spawn = lua_interface->GetSpawn(state);
  5145. string var = lua_interface->GetStringValue(state, 2);
  5146. if (!spawn) {
  5147. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5148. return 0;
  5149. }
  5150. if (var.length() == 0) {
  5151. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5152. return 0;
  5153. }
  5154. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5155. int8 type = spawn->GetTempVariableType(var);
  5156. Spawn* spawn2 = 0;
  5157. ZoneServer* zone = 0;
  5158. Item* item = 0;
  5159. Quest* quest = 0;
  5160. // Set the lua function return value based on the type of data the variable contains
  5161. switch (type) {
  5162. case 1:
  5163. spawn2 = spawn->GetTempVariableSpawn(var);
  5164. if (!spawn2)
  5165. return 0;
  5166. lua_interface->SetSpawnValue(state, spawn2);
  5167. break;
  5168. case 2:
  5169. zone = spawn->GetTempVariableZone(var);
  5170. if (!zone)
  5171. return 0;
  5172. lua_interface->SetZoneValue(state, zone);
  5173. break;
  5174. case 3:
  5175. item = spawn->GetTempVariableItem(var);
  5176. if (!item)
  5177. return 0;
  5178. lua_interface->SetItemValue(state, item);
  5179. break;
  5180. case 4:
  5181. quest = spawn->GetTempVariableQuest(var);
  5182. if (!quest)
  5183. return 0;
  5184. lua_interface->SetQuestValue(state, quest);
  5185. break;
  5186. case 5:
  5187. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5188. break;
  5189. default:
  5190. // Not a valid type then the variable was not set so return out
  5191. return 0;
  5192. }
  5193. // Return value was set so return out
  5194. return 1;
  5195. }
  5196. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5197. {
  5198. if (!lua_interface)
  5199. return 0;
  5200. Quest* quest = lua_interface->GetQuest(state);
  5201. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5202. string description = lua_interface->GetStringValue(state, 3);
  5203. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5204. if (!quest) {
  5205. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5206. lua_interface->SetBooleanValue(state, false);
  5207. return 1;
  5208. }
  5209. if (!spawn) {
  5210. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5211. lua_interface->SetBooleanValue(state, false);
  5212. return 1;
  5213. }
  5214. if (!spawn->IsPlayer()) {
  5215. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5216. lua_interface->SetBooleanValue(state, false);
  5217. return 1;
  5218. }
  5219. if (item_id == 0) {
  5220. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5221. lua_interface->SetBooleanValue(state, false);
  5222. return 1;
  5223. }
  5224. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5225. if (!client) {
  5226. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5227. lua_interface->SetBooleanValue(state, false);
  5228. return 1;
  5229. }
  5230. Item* item = master_item_list.GetItem(item_id);
  5231. if (!item) {
  5232. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5233. lua_interface->SetBooleanValue(state, false);
  5234. return 1;
  5235. }
  5236. Item* firstItem = new Item(item);
  5237. quest->AddTmpRewardItem(firstItem);
  5238. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5239. bool itemsAddedSuccessfully = true;
  5240. if(num_args > 4)
  5241. {
  5242. for(int8 n=5;n<num_args+1;n++)
  5243. {
  5244. int32 new_item = lua_interface->GetInt32Value(state, n);
  5245. Item* tmpItem = master_item_list.GetItem(new_item);
  5246. if(tmpItem)
  5247. {
  5248. Item* newTmpItem = new Item(tmpItem);
  5249. quest->AddTmpRewardItem(newTmpItem);
  5250. }
  5251. else
  5252. itemsAddedSuccessfully = false;
  5253. }
  5254. }
  5255. client->AddPendingQuestAcceptReward(quest);
  5256. client->DisplayQuestComplete(quest, true, description);
  5257. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5258. return 1;
  5259. }
  5260. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5261. if (!lua_interface)
  5262. return 0;
  5263. Quest* quest = lua_interface->GetQuest(state);
  5264. if (!quest) {
  5265. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5266. return 0;
  5267. }
  5268. quest->SetRepeatable(true);
  5269. return 0;
  5270. }
  5271. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5272. if (!lua_interface)
  5273. return 0;
  5274. Spawn* spawn = lua_interface->GetSpawn(state);
  5275. if (!spawn) {
  5276. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5277. return 0;
  5278. }
  5279. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5280. string ret = classes.GetClassNameCase(base_class);
  5281. if (ret.length() > 0) {
  5282. lua_interface->SetStringValue(state, ret.c_str());
  5283. return 1;
  5284. }
  5285. return 0;
  5286. }
  5287. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5288. if (!lua_interface)
  5289. return 0;
  5290. Spawn* player = lua_interface->GetSpawn(state);
  5291. if (player && player->IsPlayer()) {
  5292. Client* client = player->GetClient();
  5293. if (client)
  5294. client->SendWaypoints();
  5295. }
  5296. return 0;
  5297. }
  5298. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5299. if (!lua_interface)
  5300. return 0;
  5301. Spawn* player = lua_interface->GetSpawn(state);
  5302. string name = lua_interface->GetStringValue(state, 2);
  5303. int32 type = lua_interface->GetInt32Value(state, 3);
  5304. if (type == 0)
  5305. type = 2;
  5306. if (name.length() > 0) {
  5307. if (player && player->IsPlayer()) {
  5308. Client* client = player->GetClient();
  5309. if (client)
  5310. client->AddWaypoint(name, type);
  5311. }
  5312. }
  5313. return 0;
  5314. }
  5315. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5316. if (!lua_interface)
  5317. return 0;
  5318. Spawn* player = lua_interface->GetSpawn(state);
  5319. string name = lua_interface->GetStringValue(state, 2);
  5320. if (name.length() > 0) {
  5321. if (player && player->IsPlayer()) {
  5322. Client* client = player->GetClient();
  5323. if (client)
  5324. client->RemoveWaypoint(name);
  5325. }
  5326. }
  5327. return 0;
  5328. }
  5329. int EQ2Emu_lua_AddWard(lua_State* state) {
  5330. if (!lua_interface)
  5331. return 0;
  5332. int32 damage = lua_interface->GetInt32Value(state);
  5333. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5334. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5335. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5336. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5337. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5338. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5339. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5340. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5341. bool ward_was_added = false;
  5342. ZoneServer* zone = spell->caster->GetZone();
  5343. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5344. for (int32 i = 0; i < spell->targets.size(); i++) {
  5345. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5346. if (!target)
  5347. continue;
  5348. if (target->IsEntity()) {
  5349. // If the ward is already active remove it
  5350. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5351. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5352. // Create new ward info
  5353. WardInfo* ward = new WardInfo;
  5354. ward->Spell = spell;
  5355. ward->BaseDamage = damage;
  5356. ward->DamageLeft = damage;
  5357. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5358. ward->keepWard = keepWard;
  5359. ward->WardType = wardType;
  5360. if (damageAbsorptionPercent > 100)
  5361. damageAbsorptionPercent = 100;
  5362. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5363. if (damageAbsorptionMaxHealthPercent > 100)
  5364. damageAbsorptionMaxHealthPercent = 100;
  5365. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5366. ward->RedirectDamagePercent = redirectDamagePercent;
  5367. ward->LastRedirectDamage = 0;
  5368. ward->LastAbsorbedDamage = 0;
  5369. ward->HitCount = 0;
  5370. spell->num_triggers = maxHitCount;
  5371. spell->had_triggers = true;
  5372. spell->cancel_after_all_triggers = false;
  5373. ward->MaxHitCount = maxHitCount;
  5374. if (wardType == WARD_TYPE_MAGICAL)
  5375. ward->DamageType = damageTypes;
  5376. // Add the ward to the entity
  5377. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5378. ward_was_added = true;
  5379. }
  5380. }
  5381. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5382. if (ward_was_added && spell->caster->IsPlayer()) {
  5383. spell->had_dmg_remaining = true;
  5384. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5385. }
  5386. return 0;
  5387. }
  5388. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5389. if (!lua_interface)
  5390. return 0;
  5391. int32 amount = lua_interface->GetInt32Value(state);
  5392. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5393. WardInfo* ward = 0;
  5394. ZoneServer* zone = spell->caster->GetZone();
  5395. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5396. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5397. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5398. ward = target->GetWard(spell->spell->GetSpellID());
  5399. if (target && ward) {
  5400. ward->DamageLeft += amount;
  5401. if (ward->DamageLeft > ward->BaseDamage)
  5402. ward->DamageLeft = ward->BaseDamage;
  5403. for (int32 i = 0; i < spell->targets.size(); i++) {
  5404. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5405. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5406. }
  5407. }
  5408. }
  5409. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5410. if (ward && spell->caster->IsPlayer())
  5411. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5412. return 0;
  5413. }
  5414. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5415. if (!lua_interface)
  5416. return 0;
  5417. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5418. if (!spell) {
  5419. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5420. return 0;
  5421. }
  5422. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5423. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5424. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5425. if (ward) {
  5426. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5427. return 1;
  5428. }
  5429. }
  5430. return 0;
  5431. }
  5432. int EQ2Emu_lua_GetWardValue(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 GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5438. return 0;
  5439. }
  5440. string type = lua_interface->GetStringValue(state, 2);
  5441. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5442. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5443. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5444. if (ward) {
  5445. if (boost::iequals(type, "damageleft"))
  5446. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5447. else if (boost::iequals(type, "basedamage"))
  5448. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5449. else if (boost::iequals(type, "keepward"))
  5450. lua_interface->SetBooleanValue(state, ward->keepWard);
  5451. else if (boost::iequals(type, "wardtype"))
  5452. lua_interface->SetInt32Value(state, ward->WardType);
  5453. else if (boost::iequals(type, "dmgabsorptionpct"))
  5454. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5455. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5456. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5457. else if (boost::iequals(type, "redirectdamagepercent"))
  5458. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5459. else if (boost::iequals(type, "lastredirectdamage"))
  5460. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5461. else if (boost::iequals(type, "lastabsorbeddamage"))
  5462. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5463. else if (boost::iequals(type, "hitcount"))
  5464. lua_interface->SetInt32Value(state, ward->HitCount);
  5465. else if (boost::iequals(type, "maxhitcount"))
  5466. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5467. else
  5468. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5469. return 1;
  5470. }
  5471. }
  5472. return 0;
  5473. }
  5474. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5475. if (!lua_interface)
  5476. return 0;
  5477. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5478. ZoneServer* zone = spell->caster->GetZone();
  5479. Spawn* target = 0;
  5480. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5481. for (int32 i = 0; i < spell->targets.size(); i++) {
  5482. target = zone->GetSpawnByID(spell->targets.at(i));
  5483. if (target && target->IsEntity()) {
  5484. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5485. }
  5486. }
  5487. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5488. return 0;
  5489. }
  5490. int EQ2Emu_lua_Interrupt(lua_State* state)
  5491. {
  5492. if (!lua_interface)
  5493. return 0;
  5494. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5495. Spawn* target = lua_interface->GetSpawn(state, 2);
  5496. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5497. if (!caster)
  5498. {
  5499. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5500. return 0;
  5501. }
  5502. if (!target)
  5503. {
  5504. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5505. return 0;
  5506. }
  5507. if (!spell) {
  5508. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5509. return 0;
  5510. }
  5511. if (!target->IsEntity() && !spell)
  5512. {
  5513. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5514. return 0;
  5515. }
  5516. if (!target && spell) {
  5517. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5518. for (int8 i = 0; i < spell->targets.size(); i++) {
  5519. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5520. if (!target || !target->IsEntity())
  5521. continue;
  5522. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5523. }
  5524. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5525. }
  5526. else
  5527. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5528. return 0;
  5529. }
  5530. int EQ2Emu_lua_Stealth(lua_State* state) {
  5531. if (!lua_interface)
  5532. return 0;
  5533. int8 type = lua_interface->GetInt8Value(state);
  5534. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5535. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5536. if (!spell) {
  5537. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5538. return 0;
  5539. }
  5540. ZoneServer* zone = spell->caster->GetZone();
  5541. if (spawn) {
  5542. if (spawn->IsEntity()) {
  5543. if (type == 1) {
  5544. ((Entity*)spawn)->AddStealthSpell(spell);
  5545. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5546. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5547. }
  5548. else if (type == 2) {
  5549. ((Entity*)spawn)->AddInvisSpell(spell);
  5550. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5551. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5552. }
  5553. return 0;
  5554. }
  5555. else {
  5556. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5557. return 0;
  5558. }
  5559. }
  5560. else {
  5561. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5562. for (int32 i = 0; i < spell->targets.size(); i++) {
  5563. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5564. if (!spawn || !spawn->IsEntity())
  5565. continue;
  5566. if (type == 1) {
  5567. ((Entity*)spawn)->AddStealthSpell(spell);
  5568. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5569. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5570. }
  5571. else if (type == 2) {
  5572. ((Entity*)spawn)->AddInvisSpell(spell);
  5573. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5574. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5575. }
  5576. else {
  5577. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5578. break;
  5579. }
  5580. }
  5581. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5582. }
  5583. return 0;
  5584. }
  5585. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5586. if (!lua_interface)
  5587. return 0;
  5588. Spawn* spawn = lua_interface->GetSpawn(state);
  5589. if (!spawn) {
  5590. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. if (spawn->IsEntity()) {
  5594. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5595. return 1;
  5596. }
  5597. else
  5598. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5599. return 0;
  5600. }
  5601. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5602. if (!lua_interface)
  5603. return 0;
  5604. Spawn* spawn = lua_interface->GetSpawn(state);
  5605. if (!spawn) {
  5606. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5607. return 0;
  5608. }
  5609. if (spawn->IsEntity()) {
  5610. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5611. return 1;
  5612. }
  5613. else
  5614. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5615. return 0;
  5616. }
  5617. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5618. if (!lua_interface)
  5619. return 0;
  5620. Spawn* player = lua_interface->GetSpawn(state);
  5621. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5622. lua_interface->ResetFunctionStack(state);
  5623. if (!player->IsPlayer()) {
  5624. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5625. return 0;
  5626. }
  5627. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5628. return 1;
  5629. }
  5630. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5631. if (!lua_interface)
  5632. return 0;
  5633. Spawn* player = lua_interface->GetSpawn(state);
  5634. int8 slot = lua_interface->GetInt8Value(state, 2);
  5635. lua_interface->ResetFunctionStack(state);
  5636. if (!player) {
  5637. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5638. return 0;
  5639. }
  5640. if (!player->IsPlayer()) {
  5641. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5642. return 0;
  5643. }
  5644. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5645. if (!item) {
  5646. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5647. return 0;
  5648. }
  5649. lua_interface->SetItemValue(state, item);
  5650. return 1;
  5651. }
  5652. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5653. if (!lua_interface)
  5654. return 0;
  5655. Spawn* player = lua_interface->GetSpawn(state);
  5656. int32 id = lua_interface->GetInt32Value(state, 2);
  5657. lua_interface->ResetFunctionStack(state);
  5658. if (!player) {
  5659. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5660. return 0;
  5661. }
  5662. if (!player->IsPlayer()) {
  5663. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5664. return 0;
  5665. }
  5666. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5667. if (!item) {
  5668. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5669. return 0;
  5670. }
  5671. lua_interface->SetItemValue(state, item);
  5672. return 1;
  5673. }
  5674. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5675. if (!lua_interface)
  5676. return 0;
  5677. Spawn* spawn = lua_interface->GetSpawn(state);
  5678. int8 slot = lua_interface->GetInt8Value(state, 2);
  5679. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5680. lua_interface->ResetFunctionStack(state);
  5681. if (!spawn) {
  5682. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5683. return 0;
  5684. }
  5685. if (!spawn->IsEntity()) {
  5686. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5687. return 0;
  5688. }
  5689. Item* item = master_item_list.GetItem(item_id);
  5690. if (!item) {
  5691. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5692. return 0;
  5693. }
  5694. Item* copy = new Item(item);
  5695. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5696. if(result)
  5697. {
  5698. ((Entity*)spawn)->SetEquipment(copy, slot);
  5699. spawn->vis_changed = true;
  5700. if(spawn->IsPlayer())
  5701. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5702. }
  5703. else
  5704. {
  5705. safe_delete(copy);
  5706. }
  5707. lua_interface->SetBooleanValue(state, result);
  5708. return 1;
  5709. }
  5710. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5711. if (!lua_interface)
  5712. return 0;
  5713. Spawn* spawn = lua_interface->GetSpawn(state);
  5714. int8 slot = lua_interface->GetInt8Value(state, 2);
  5715. Item* item = lua_interface->GetItem(state, 3);
  5716. lua_interface->ResetFunctionStack(state);
  5717. if (!spawn) {
  5718. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5719. return 0;
  5720. }
  5721. if (!spawn->IsEntity()) {
  5722. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5723. return 0;
  5724. }
  5725. if (!item) {
  5726. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5727. return 0;
  5728. }
  5729. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5730. if(result)
  5731. {
  5732. ((Entity*)spawn)->SetEquipment(item, slot);
  5733. spawn->vis_changed = true;
  5734. if(spawn->IsPlayer())
  5735. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5736. }
  5737. lua_interface->SetBooleanValue(state, result);
  5738. return 1;
  5739. }
  5740. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5741. if (!lua_interface)
  5742. return 0;
  5743. Spawn* spawn = lua_interface->GetSpawn(state);
  5744. int8 slot = lua_interface->GetInt8Value(state, 2);
  5745. 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
  5746. lua_interface->ResetFunctionStack(state);
  5747. if (!spawn) {
  5748. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5749. return 0;
  5750. }
  5751. if (!spawn->IsEntity()) {
  5752. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5753. return 0;
  5754. }
  5755. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5756. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5757. spawn->vis_changed = true;
  5758. if(spawn->IsPlayer())
  5759. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5760. lua_interface->SetBooleanValue(state, true);
  5761. return 1;
  5762. }
  5763. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5764. if (!lua_interface)
  5765. return 0;
  5766. Spawn* spawn = lua_interface->GetSpawn(state);
  5767. int8 slot = lua_interface->GetInt8Value(state, 2);
  5768. int16 type = lua_interface->GetInt16Value(state, 3);
  5769. int8 r = lua_interface->GetInt8Value(state, 4);
  5770. int8 g = lua_interface->GetInt8Value(state, 5);
  5771. int8 b = lua_interface->GetInt8Value(state, 6);
  5772. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5773. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5774. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5775. lua_interface->ResetFunctionStack(state);
  5776. if (!spawn) {
  5777. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. if (!spawn->IsEntity()) {
  5781. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5782. return 0;
  5783. }
  5784. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5785. spawn->vis_changed = true;
  5786. lua_interface->SetBooleanValue(state, true);
  5787. return 1;
  5788. }
  5789. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5790. if (!lua_interface)
  5791. return 0;
  5792. Spawn* player = lua_interface->GetSpawn(state);
  5793. int32 id = lua_interface->GetInt32Value(state, 2);
  5794. int8 count = lua_interface->GetInt8Value(state, 3);
  5795. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5796. lua_interface->ResetFunctionStack(state);
  5797. if (!player) {
  5798. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5799. return 0;
  5800. }
  5801. if (!player->IsPlayer()) {
  5802. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5803. return 0;
  5804. }
  5805. if (!count)
  5806. count = 1;
  5807. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5808. if (!item) {
  5809. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5810. return 0;
  5811. }
  5812. lua_interface->SetItemValue(state, item);
  5813. return 1;
  5814. }
  5815. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5816. if (!lua_interface)
  5817. return 0;
  5818. Spawn* spawn = lua_interface->GetSpawn(state);
  5819. int32 anim = lua_interface->GetInt32Value(state, 2);
  5820. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5821. int8 type = lua_interface->GetInt8Value(state, 4);
  5822. if (!spawn) {
  5823. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5824. return 0;
  5825. }
  5826. if (spawn2) {
  5827. if (spawn2->IsPlayer()) {
  5828. if (type != 1 && type != 2)
  5829. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5830. else
  5831. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5832. return 0;
  5833. }
  5834. else {
  5835. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5836. return 0;
  5837. }
  5838. }
  5839. else
  5840. spawn->GetZone()->PlayAnimation(spawn, anim);
  5841. return 0;
  5842. }
  5843. int EQ2Emu_lua_IsPet(lua_State* state) {
  5844. if (!lua_interface)
  5845. return 0;
  5846. Spawn* spawn = lua_interface->GetSpawn(state);
  5847. if (!spawn) {
  5848. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5849. return 0;
  5850. }
  5851. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5852. return 1;
  5853. }
  5854. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5855. if (!lua_interface)
  5856. return 0;
  5857. Spawn* spawn = lua_interface->GetSpawn(state);
  5858. if (!spawn) {
  5859. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5860. return 0;
  5861. }
  5862. if (!spawn->IsNPC()) {
  5863. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5864. return 0;
  5865. }
  5866. if (((NPC*)spawn)->GetOwner()) {
  5867. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5868. return 1;
  5869. }
  5870. return 0;
  5871. }
  5872. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5873. if (!lua_interface)
  5874. return 0;
  5875. Spawn* spawn = lua_interface->GetSpawn(state);
  5876. Spawn* target = lua_interface->GetSpawn(state, 2);
  5877. if (!spawn) {
  5878. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5879. return 0;
  5880. }
  5881. if (!spawn) {
  5882. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5883. return 0;
  5884. }
  5885. spawn->SetTarget(target);
  5886. return 0;
  5887. }
  5888. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5889. if (!lua_interface)
  5890. return 0;
  5891. Spawn* spawn = lua_interface->GetSpawn(state);
  5892. bool val = lua_interface->GetBooleanValue(state, 2);
  5893. if (!spawn) {
  5894. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5895. return 0;
  5896. }
  5897. if (!spawn->IsEntity()) {
  5898. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5899. return 0;
  5900. }
  5901. ((Entity*)spawn)->InCombat(val);
  5902. if (val) {
  5903. spawn->ClearRunningLocations();
  5904. spawn->CalculateRunningLocation(true);
  5905. }
  5906. return 0;
  5907. }
  5908. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5909. if (!lua_interface)
  5910. return 0;
  5911. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5912. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5913. if (!spawn1) {
  5914. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5915. return 0;
  5916. }
  5917. if (!spawn2) {
  5918. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5919. return 0;
  5920. }
  5921. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5922. return 1;
  5923. }
  5924. int EQ2Emu_lua_Runback(lua_State* state) {
  5925. if (!lua_interface)
  5926. return 0;
  5927. Spawn* spawn = lua_interface->GetSpawn(state);
  5928. if (!spawn) {
  5929. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5930. return 0;
  5931. }
  5932. if (!spawn->IsNPC()) {
  5933. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. ((NPC*)spawn)->Runback();
  5937. return 0;
  5938. }
  5939. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. Spawn* spawn = lua_interface->GetSpawn(state);
  5943. if (!spawn) {
  5944. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. if (!spawn->IsNPC()) {
  5948. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5952. return 1;
  5953. }
  5954. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5955. if (!lua_interface)
  5956. return 0;
  5957. Spawn* spawn = lua_interface->GetSpawn(state);
  5958. if (!spawn) {
  5959. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5960. return 0;
  5961. }
  5962. if (!spawn->IsEntity()) {
  5963. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5964. return 0;
  5965. }
  5966. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5967. return 1;
  5968. }
  5969. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5970. if (!lua_interface)
  5971. return 0;
  5972. Spawn* spawn = lua_interface->GetSpawn(state);
  5973. if (!spawn) {
  5974. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5975. return 0;
  5976. }
  5977. if (!spawn->IsEntity()) {
  5978. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5982. return 1;
  5983. }
  5984. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5985. if (!lua_interface)
  5986. return 0;
  5987. Spawn* spawn = lua_interface->GetSpawn(state);
  5988. if (!spawn) {
  5989. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5990. return 0;
  5991. }
  5992. if (!spawn->IsEntity()) {
  5993. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5997. return 1;
  5998. }
  5999. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6000. if (!lua_interface)
  6001. return 0;
  6002. Spawn* spawn = lua_interface->GetSpawn(state);
  6003. if (!spawn) {
  6004. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6005. return 0;
  6006. }
  6007. if (!spawn->IsEntity()) {
  6008. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6012. return 1;
  6013. }
  6014. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6015. if (!lua_interface)
  6016. return 0;
  6017. Spawn* spawn = lua_interface->GetSpawn(state);
  6018. Spawn* target = lua_interface->GetSpawn(state, 2);
  6019. float distance = lua_interface->GetFloatValue(state, 3);
  6020. if (!spawn) {
  6021. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6022. return 0;
  6023. }
  6024. if (!target) {
  6025. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6026. return 0;
  6027. }
  6028. if (!spawn->IsNPC()) {
  6029. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6030. return 0;
  6031. }
  6032. if (!target->IsEntity()) {
  6033. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6037. return 1;
  6038. }
  6039. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6040. if (!lua_interface)
  6041. return 0;
  6042. Spawn* spawn = lua_interface->GetSpawn(state);
  6043. Spawn* target = lua_interface->GetSpawn(state, 2);
  6044. float distance = lua_interface->GetFloatValue(state, 3);
  6045. if (!spawn) {
  6046. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6047. return 0;
  6048. }
  6049. if (!target) {
  6050. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6051. return 0;
  6052. }
  6053. if (!spawn->IsNPC()) {
  6054. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6055. return 0;
  6056. }
  6057. if (!target->IsEntity()) {
  6058. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6059. return 0;
  6060. }
  6061. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6062. return 0;
  6063. }
  6064. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6065. if (!lua_interface)
  6066. return 0;
  6067. Spawn* spawn = lua_interface->GetSpawn(state);
  6068. if (!spawn) {
  6069. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. if (!spawn->IsNPC()) {
  6073. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6074. return 0;
  6075. }
  6076. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6077. return 1;
  6078. }
  6079. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6080. if (!lua_interface)
  6081. return 0;
  6082. Spawn* spawn = lua_interface->GetSpawn(state);
  6083. if (!spawn) {
  6084. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6085. return 0;
  6086. }
  6087. if (!spawn->IsNPC()) {
  6088. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6089. return 0;
  6090. }
  6091. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6092. return 1;
  6093. }
  6094. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6095. if (!lua_interface)
  6096. return 0;
  6097. Spawn* spawn = lua_interface->GetSpawn(state);
  6098. if (!spawn) {
  6099. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!spawn->IsNPC()) {
  6103. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6104. return 0;
  6105. }
  6106. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6107. if (hated) {
  6108. lua_interface->SetSpawnValue(state, hated);
  6109. return 1;
  6110. }
  6111. return 0;
  6112. }
  6113. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6114. if (!lua_interface)
  6115. return 0;
  6116. Spawn* spawn = lua_interface->GetSpawn(state);
  6117. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6118. if (!spawn) {
  6119. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. if (!spawn->IsNPC()) {
  6123. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. if (!hated) {
  6127. ((NPC*)spawn)->Brain()->ClearHate();
  6128. return 0;
  6129. }
  6130. else
  6131. {
  6132. if (!hated->IsEntity()) {
  6133. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6137. return 0;
  6138. }
  6139. return 0;
  6140. }
  6141. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. if (!spawn) {
  6146. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6147. return 0;
  6148. }
  6149. if (!spawn->IsNPC()) {
  6150. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. ((NPC*)spawn)->Brain()->ClearEncounter();
  6154. return 0;
  6155. }
  6156. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6157. if (!lua_interface)
  6158. return 0;
  6159. Spawn* spawn = lua_interface->GetSpawn(state);
  6160. if (!spawn) {
  6161. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!spawn->IsNPC()) {
  6165. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. // Temp list to store hate list
  6169. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6170. if (encounterList->size() == 0) {
  6171. safe_delete(encounterList);
  6172. return 0;
  6173. }
  6174. lua_createtable(state, encounterList->size(), 0);
  6175. int newTable = lua_gettop(state);
  6176. for (int32 i = 0; i < encounterList->size(); i++) {
  6177. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6178. if (temp)
  6179. lua_interface->SetSpawnValue(state, temp);
  6180. lua_rawseti(state, newTable, i + 1);
  6181. }
  6182. safe_delete(encounterList);
  6183. return 1;
  6184. }
  6185. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6186. if (!lua_interface)
  6187. return 0;
  6188. Spawn* spawn = lua_interface->GetSpawn(state);
  6189. if (!spawn) {
  6190. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6191. return 0;
  6192. }
  6193. if (!spawn->IsNPC()) {
  6194. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6195. return 0;
  6196. }
  6197. // Temp list to store hate list
  6198. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6199. if (hateList->size() == 0) {
  6200. safe_delete(hateList);
  6201. return 0;
  6202. }
  6203. lua_createtable(state, hateList->size(), 0);
  6204. int newTable = lua_gettop(state);
  6205. for (int32 i = 0; i < hateList->size(); i++) {
  6206. lua_interface->SetSpawnValue(state, hateList->at(i));
  6207. lua_rawseti(state, newTable, i + 1);
  6208. }
  6209. safe_delete(hateList);
  6210. return 1;
  6211. }
  6212. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6213. if (!lua_interface)
  6214. return 0;
  6215. Spawn* spawn = lua_interface->GetSpawn(state);
  6216. if (!spawn) {
  6217. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. if (spawn->IsPlayer()) {
  6221. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6222. lua_interface->SetBooleanValue(state, true);
  6223. else
  6224. lua_interface->SetBooleanValue(state, false);
  6225. return 1;
  6226. }
  6227. else {
  6228. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6229. return 1;
  6230. }
  6231. }
  6232. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6233. if (!lua_interface)
  6234. return 0;
  6235. Quest* quest = lua_interface->GetQuest(state);
  6236. if (!quest) {
  6237. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. quest->SetCompletedFlag(true);
  6241. return 0;
  6242. }
  6243. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6244. if (!lua_interface)
  6245. return 0;
  6246. Spawn* spawn = lua_interface->GetSpawn(state);
  6247. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6248. int8 tier = lua_interface->GetInt8Value(state, 3);
  6249. if (!spawn) {
  6250. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6251. return 0;
  6252. }
  6253. if (!spawn->IsEntity()) {
  6254. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6255. return 0;
  6256. }
  6257. if (spellID == 0) {
  6258. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6259. return 0;
  6260. }
  6261. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6262. if (effect) {
  6263. if (tier > 0) {
  6264. // If a tier was passed chec to see if it is the same as the effect
  6265. if (tier == effect->tier)
  6266. lua_interface->SetBooleanValue(state, true);
  6267. else
  6268. lua_interface->SetBooleanValue(state, false);
  6269. return 1;
  6270. }
  6271. else {
  6272. // Have an effect but no tier was passed so return true
  6273. lua_interface->SetBooleanValue(state, true);
  6274. }
  6275. return 1;
  6276. }
  6277. // no effect so return false
  6278. lua_interface->SetBooleanValue(state, false);
  6279. return 1;
  6280. }
  6281. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6282. if (!lua_interface)
  6283. return 0;
  6284. Spawn* spawn = lua_interface->GetSpawn(state);
  6285. int32 id = lua_interface->GetInt32Value(state, 2);
  6286. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6287. Spawn* spawn2 = 0;
  6288. vector<Spawn*> list;
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. //If zone not provided, use spawn's zone
  6294. if (!zone)
  6295. zone = spawn->GetZone();
  6296. list = zone->GetSpawnsByID(id);
  6297. if (list.size() == 0) {
  6298. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. vector<Spawn*>::iterator itr = list.begin();
  6302. for (int8 i = 0; i < list.size(); i++) {
  6303. spawn2 = itr[i];
  6304. if (spawn2)
  6305. spawn2->AddAllowAccessSpawn(spawn);
  6306. }
  6307. return 0;
  6308. }
  6309. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6310. if (!lua_interface)
  6311. return 0;
  6312. Spawn* spawn = lua_interface->GetSpawn(state);
  6313. int32 id = lua_interface->GetInt32Value(state, 2);
  6314. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6315. Spawn* spawn2 = 0;
  6316. if (!spawn) {
  6317. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. //If zone not provided, use spawn's zone
  6321. if (!zone)
  6322. zone = spawn->GetZone();
  6323. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6324. vector<Spawn*>::iterator itr = list.begin();
  6325. if (list.size() == 0) {
  6326. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6327. return 0;
  6328. }
  6329. for (int8 i = 0; i < list.size(); i++) {
  6330. spawn2 = itr[i];
  6331. if (spawn2)
  6332. spawn2->RemoveSpawnAccess(spawn);
  6333. }
  6334. return 0;
  6335. }
  6336. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6337. if (!lua_interface)
  6338. return 0;
  6339. Quest* quest = lua_interface->GetQuest(state);
  6340. if (!quest) {
  6341. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. quest->SetYellowName(true);
  6345. return 0;
  6346. }
  6347. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6348. if (!lua_interface)
  6349. return 0;
  6350. Spawn* spawn = lua_interface->GetSpawn(state);
  6351. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6352. if (!spawn) {
  6353. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6354. return 0;
  6355. }
  6356. if (!spawn->IsPlayer()) {
  6357. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6358. return 0;
  6359. }
  6360. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6361. return 1;
  6362. }
  6363. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6364. if (!lua_interface)
  6365. return 0;
  6366. Spawn* spawn = lua_interface->GetSpawn(state);
  6367. if (!spawn) {
  6368. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6369. return 0;
  6370. }
  6371. if (!spawn->IsPlayer()) {
  6372. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6373. return 0;
  6374. }
  6375. ZoneServer* zone = spawn->GetZone();
  6376. if (!zone) {
  6377. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6378. return 0;
  6379. }
  6380. Instance_Type iType = zone->GetInstanceType();
  6381. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6382. iType == GROUP_LOCKOUT_INSTANCE ||
  6383. iType == RAID_LOCKOUT_INSTANCE ||
  6384. iType == SOLO_PERSIST_INSTANCE ||
  6385. iType == GROUP_PERSIST_INSTANCE ||
  6386. iType == RAID_PERSIST_INSTANCE) {
  6387. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6388. if (data) {
  6389. // Check to see if the timer has already been set, if it has return out.
  6390. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6391. return 0;
  6392. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6393. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6394. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6395. if (client) {
  6396. string time_msg = "";
  6397. int32 time = data->success_lockout_time;
  6398. int16 hour;
  6399. int8 min;
  6400. int8 sec;
  6401. hour = time / 3600;
  6402. time = time % 3600;
  6403. min = time / 60;
  6404. time = time % 60;
  6405. sec = time;
  6406. if (hour > 0) {
  6407. char temp[10];
  6408. sprintf(temp, " %i", hour);
  6409. time_msg.append(temp);
  6410. time_msg.append(" hour");
  6411. time_msg.append((hour > 1) ? "s" : "");
  6412. }
  6413. if (min > 0) {
  6414. char temp[5];
  6415. sprintf(temp, " %i", min);
  6416. time_msg.append(temp);
  6417. time_msg.append(" minute");
  6418. time_msg.append((min > 1) ? "s" : "");
  6419. }
  6420. // Only add seconds if minutes and hours are 0
  6421. if (hour == 0 && min == 0 && sec > 0) {
  6422. char temp[5];
  6423. sprintf(temp, " %i", sec);
  6424. time_msg.append(temp);
  6425. time_msg.append(" second");
  6426. time_msg.append((sec > 1) ? "s" : "");
  6427. }
  6428. 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());
  6429. }
  6430. }
  6431. else
  6432. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6433. }
  6434. else
  6435. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6436. return 0;
  6437. }
  6438. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6439. if (!lua_interface)
  6440. return 0;
  6441. Spawn* spawn = lua_interface->GetSpawn(state);
  6442. if (!spawn) {
  6443. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. if (!spawn->IsPlayer()) {
  6447. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6448. return 0;
  6449. }
  6450. ZoneServer* zone = spawn->GetZone();
  6451. if (!zone) {
  6452. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6453. return 0;
  6454. }
  6455. Instance_Type iType = zone->GetInstanceType();
  6456. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6457. iType == GROUP_LOCKOUT_INSTANCE ||
  6458. iType == RAID_LOCKOUT_INSTANCE ||
  6459. iType == SOLO_PERSIST_INSTANCE ||
  6460. iType == GROUP_PERSIST_INSTANCE ||
  6461. iType == RAID_PERSIST_INSTANCE) {
  6462. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6463. if (data) {
  6464. // Check to see if the timer has already been set, if it has return out.
  6465. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6466. return 0;
  6467. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6468. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6469. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6470. if (client) {
  6471. string time_msg = "";
  6472. int32 time = data->failure_lockout_time;
  6473. int16 hour;
  6474. int8 min;
  6475. int8 sec;
  6476. hour = time / 3600;
  6477. time = time % 3600;
  6478. min = time / 60;
  6479. time = time % 60;
  6480. sec = time;
  6481. if (hour > 0) {
  6482. char temp[10];
  6483. sprintf(temp, " %i", hour);
  6484. time_msg.append(temp);
  6485. time_msg.append(" hour");
  6486. time_msg.append((hour > 1) ? "s" : "");
  6487. }
  6488. if (min > 0) {
  6489. char temp[5];
  6490. sprintf(temp, " %i", min);
  6491. time_msg.append(temp);
  6492. time_msg.append(" minute");
  6493. time_msg.append((min > 1) ? "s" : "");
  6494. }
  6495. // Only add seconds if minutes and hours are 0
  6496. if (hour == 0 && min == 0 && sec > 0) {
  6497. char temp[5];
  6498. sprintf(temp, " %i", sec);
  6499. time_msg.append(temp);
  6500. time_msg.append(" second");
  6501. time_msg.append((sec > 1) ? "s" : "");
  6502. }
  6503. 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());
  6504. }
  6505. }
  6506. else
  6507. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6508. }
  6509. else
  6510. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6511. return 0;
  6512. }
  6513. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6514. if (!lua_interface)
  6515. return 0;
  6516. Spawn* spawn = lua_interface->GetSpawn(state);
  6517. if (!spawn) {
  6518. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6519. return 0;
  6520. }
  6521. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6522. return 1;
  6523. }
  6524. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6525. if (!lua_interface)
  6526. return 0;
  6527. Spawn* player = lua_interface->GetSpawn(state);
  6528. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6529. if (!player) {
  6530. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6531. return 0;
  6532. }
  6533. if (!player->IsPlayer()) {
  6534. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6535. return 0;
  6536. }
  6537. if (!ground) {
  6538. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6539. return 0;
  6540. }
  6541. if (!ground->IsGroundSpawn()) {
  6542. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6546. if (!groundspawn_entries) {
  6547. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6548. return 0;
  6549. }
  6550. Skill* skill = 0;
  6551. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6552. if (collection_skill == "Collecting")
  6553. skill = ((Player*)player)->GetSkillByName("Gathering");
  6554. else
  6555. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6556. if (!skill) {
  6557. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6558. return 0;
  6559. }
  6560. vector<GroundSpawnEntry*>::iterator itr;
  6561. GroundSpawnEntry* entry = 0;
  6562. bool can_harvest = false;
  6563. sint32 min_skill = -1;
  6564. int16 totalSkill = skill->current_val;
  6565. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6566. if(skillID != 0xFFFFFFFF)
  6567. {
  6568. ((Entity*)player)->MStats.lock();
  6569. totalSkill += ((Entity*)player)->stats[skillID];
  6570. ((Entity*)player)->MStats.unlock();
  6571. }
  6572. // first, iterate through groundspawn_entries, discard tables player cannot use
  6573. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6574. {
  6575. entry = *itr;
  6576. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6577. min_skill = entry->min_skill_level;
  6578. // if player lacks skill, skip table
  6579. if (entry->min_skill_level > totalSkill)
  6580. continue;
  6581. // if bonus, but player lacks level, skip table
  6582. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6583. continue;
  6584. can_harvest = true;
  6585. break;
  6586. }
  6587. lua_interface->SetBooleanValue(state, can_harvest);
  6588. // If false, send the message to the client
  6589. if (!can_harvest) {
  6590. Client* client = player->GetZone()->GetClientBySpawn(player);
  6591. if (client) {
  6592. string msg = "You do not have enough skill to ";
  6593. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6594. msg.append("gather");
  6595. else if (collection_skill == "Mining")
  6596. msg.append("mine");
  6597. else if (collection_skill == "Trapping")
  6598. msg.append("trap");
  6599. else if (collection_skill == "Foresting")
  6600. msg.append("forest");
  6601. else if (collection_skill == "Fishing")
  6602. msg.append("catch");
  6603. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6604. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6605. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6606. }
  6607. }
  6608. return 1;
  6609. }
  6610. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6611. if (!lua_interface)
  6612. return 0;
  6613. Spawn* player = lua_interface->GetSpawn(state);
  6614. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6615. if (!player) {
  6616. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6617. return 0;
  6618. }
  6619. if (!player->IsPlayer()) {
  6620. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6621. return 0;
  6622. }
  6623. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6624. lua_interface->SetBooleanValue(state, ret);
  6625. return 1;
  6626. }
  6627. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6628. // Check to see if we have a valid lua_interface
  6629. if (!lua_interface)
  6630. return 0;
  6631. // Get the spawn that is getting the pet
  6632. Spawn* spawn = lua_interface->GetSpawn(state);
  6633. Spawn* target = lua_interface->GetSpawn(state, 2);
  6634. // Get the DB ID of the pet
  6635. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6636. float x = lua_interface->GetFloatValue(state, 4);
  6637. float y = lua_interface->GetFloatValue(state, 5);
  6638. float z = lua_interface->GetFloatValue(state, 6);
  6639. // Get the spell that this command was called from
  6640. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6641. // Check to make sure the spawn pointer is valid
  6642. if (!spawn) {
  6643. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. // Check to make sure the spawn is an entity
  6647. if (!spawn->IsEntity()) {
  6648. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6649. return 0;
  6650. }
  6651. if (!target) {
  6652. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6653. return 0;
  6654. }
  6655. if (!target->IsEntity()) {
  6656. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6657. return 0;
  6658. }
  6659. // Check to see if the DB ID for the pet is set
  6660. if (pet_id == 0) {
  6661. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6662. return 0;
  6663. }
  6664. // Check to see if the pointer to the spell is valid
  6665. if (!luaspell) {
  6666. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6670. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6671. if (!pet) {
  6672. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6673. return 0;
  6674. }
  6675. // Check to make sure the pet is an npc
  6676. if (!pet->IsNPC()) {
  6677. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6678. return 0;
  6679. }
  6680. if (x == 0)
  6681. x = spawn->GetX();
  6682. if (y == 0)
  6683. y = spawn->GetY();
  6684. if (z == 0)
  6685. z = spawn->GetZ();
  6686. // Spawn the pet at the same location as the owner
  6687. pet->SetX(x);
  6688. pet->SetY(y);
  6689. pet->SetZ(z);
  6690. pet->SetLocation(spawn->GetLocation());
  6691. pet->SetHeading(spawn->GetHeading());
  6692. spawn->GetZone()->AddSpawn(pet);
  6693. /*
  6694. const char* spawn_script = world.GetSpawnScript(pet_id);
  6695. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6696. spawn->SetSpawnScript(string(spawn_script));
  6697. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6698. }*/
  6699. // Get a random pet name
  6700. string random_pet_name;
  6701. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6702. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6703. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6704. // Set the pets name
  6705. pet->SetName(random_pet_name.c_str());
  6706. // Set the level of the pet to the owners level
  6707. pet->SetLevel(spawn->GetLevel());
  6708. // Set the faction of the pet to the same faction as the owner
  6709. pet->SetFactionID(spawn->GetFactionID());
  6710. // Set the spawn as a pet
  6711. pet->SetPet(true);
  6712. // Give a pointer of the owner to the pet
  6713. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6714. // Set the pet type
  6715. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6716. // Set the spell id used to create this pet
  6717. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6718. // Set the spell tier used to create this pet
  6719. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6720. // Set the pets spawn type to 6
  6721. pet->SetSpawnType(6);
  6722. // Set the pets brain
  6723. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6724. // Check to see if the pet has a subtitle
  6725. if (strlen(pet->GetSubTitle()) > 0) {
  6726. // Add the players name to the front of the sub title
  6727. string pet_subtitle;
  6728. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6729. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6730. // Set the pets subtitle to the new one
  6731. pet->SetSubTitle(pet_subtitle.c_str());
  6732. }
  6733. // Set the pet as the return value for this function
  6734. lua_interface->SetSpawnValue(state, pet);
  6735. return 1;
  6736. }
  6737. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6738. if (!lua_interface)
  6739. return 0;
  6740. Spawn* spawn = lua_interface->GetSpawn(state);
  6741. Spawn* player = lua_interface->GetSpawn(state, 2);
  6742. float max_distance = lua_interface->GetFloatValue(state, 3);
  6743. string type = lua_interface->GetStringValue(state, 4);
  6744. if (!spawn || (spawn && spawn->IsPlayer())) {
  6745. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. if (!player || (player && !player->IsPlayer())) {
  6749. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6750. return 0;
  6751. }
  6752. Client* client = 0;
  6753. if (player->GetZone())
  6754. client = player->GetZone()->GetClientBySpawn(player);
  6755. if (!client) {
  6756. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6757. return 0;
  6758. }
  6759. //Set max_distance to default if not set or not proper value
  6760. if (max_distance <= 0)
  6761. max_distance = 500;
  6762. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6763. if (packet) {
  6764. float unknown2_3 = 0;
  6765. int8 placement_mode = 0;
  6766. if (type == "wall") {
  6767. placement_mode = 2;
  6768. unknown2_3 = 150;
  6769. }
  6770. else if (type == "ceiling")
  6771. placement_mode = 1;
  6772. packet->setDataByName("placement_mode", placement_mode);
  6773. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6774. packet->setDataByName("model_type", spawn->GetModelType());
  6775. packet->setDataByName("unknown", 1); //size
  6776. packet->setDataByName("unknown2", 1); //size 2
  6777. packet->setDataByName("unknown2", .5, 1); //size 3
  6778. packet->setDataByName("unknown2", 3, 2);
  6779. packet->setDataByName("unknown2", unknown2_3, 3);
  6780. packet->setDataByName("max_distance", max_distance);
  6781. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6782. client->QueuePacket(packet->serialize());
  6783. safe_delete(packet);
  6784. }
  6785. return 0;
  6786. }
  6787. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6788. if (!lua_interface)
  6789. return 0;
  6790. Item* item = lua_interface->GetItem(state);
  6791. if (!item) {
  6792. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6793. return 0;
  6794. }
  6795. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6796. return 1;
  6797. }
  6798. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6799. if (!lua_interface)
  6800. return 0;
  6801. Spawn* spawn = lua_interface->GetSpawn(state);
  6802. if (!spawn) {
  6803. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6804. return 0;
  6805. }
  6806. if (spawn->GetZone())
  6807. spawn->GetZone()->AddTransportSpawn(spawn);
  6808. return 0;
  6809. }
  6810. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Spawn* spawn = lua_interface->GetSpawn(state);
  6814. if (!spawn) {
  6815. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6816. return 0;
  6817. }
  6818. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6819. return 1;
  6820. }
  6821. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6822. if (!lua_interface)
  6823. return 0;
  6824. Skill* skill = lua_interface->GetSkill(state);
  6825. if (!skill) {
  6826. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. lua_interface->SetInt32Value(state, skill->current_val);
  6830. return 1;
  6831. }
  6832. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6833. if (!lua_interface)
  6834. return 0;
  6835. Skill* skill = lua_interface->GetSkill(state);
  6836. if (!skill) {
  6837. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. lua_interface->SetInt32Value(state, skill->max_val);
  6841. return 1;
  6842. }
  6843. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6844. if (!lua_interface)
  6845. return 0;
  6846. Skill* skill = lua_interface->GetSkill(state);
  6847. if (!skill) {
  6848. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6852. return 1;
  6853. }
  6854. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6855. if (!lua_interface)
  6856. return 0;
  6857. Skill* skill = lua_interface->GetSkill(state);
  6858. int16 value = lua_interface->GetInt16Value(state, 2);
  6859. if (!skill) {
  6860. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6861. return 0;
  6862. }
  6863. skill->max_val = value;
  6864. if (skill->max_val < skill->current_val)
  6865. skill->current_val = skill->max_val;
  6866. return 0;
  6867. }
  6868. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6869. if (!lua_interface)
  6870. return 0;
  6871. Skill* skill = lua_interface->GetSkill(state);
  6872. int16 value = lua_interface->GetInt16Value(state, 2);
  6873. if (!skill) {
  6874. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6875. return 0;
  6876. }
  6877. if (value > skill->max_val)
  6878. skill->current_val = skill->max_val;
  6879. else
  6880. skill->current_val = value;
  6881. return 0;
  6882. }
  6883. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6884. if (!lua_interface)
  6885. return 0;
  6886. Spawn* player = lua_interface->GetSpawn(state);
  6887. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6888. if (skill_id > 0 && player && player->IsPlayer()) {
  6889. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6890. return 1;
  6891. }
  6892. return 0;
  6893. }
  6894. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6895. if (!lua_interface)
  6896. return 0;
  6897. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6898. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6899. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6900. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6901. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6902. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6903. if (player_spawn && player_spawn->IsPlayer()) {
  6904. Player* player = (Player*)player_spawn;
  6905. bool added = false;
  6906. if (!player->skill_list.HasSkill(skill_id)) {
  6907. player->AddSkill(skill_id, current_val, max_val, true);
  6908. added = true;
  6909. }
  6910. 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
  6911. Client* client = player->GetClient();
  6912. if (client) {
  6913. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6914. if (packet)
  6915. client->QueuePacket(packet);
  6916. }
  6917. }
  6918. if (added) {
  6919. lua_interface->SetBooleanValue(state, true);
  6920. return 1;
  6921. }
  6922. }
  6923. else {
  6924. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6925. }
  6926. }
  6927. else {
  6928. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6929. }
  6930. lua_interface->SetBooleanValue(state, false);
  6931. return 1;
  6932. }
  6933. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6934. if (!lua_interface)
  6935. return 0;
  6936. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6937. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6938. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6939. if (skill_id > 0) {
  6940. if (player_spawn && player_spawn->IsPlayer()) {
  6941. Player* player = (Player*)player_spawn;
  6942. if (player->skill_list.HasSkill(skill_id)) {
  6943. player->RemovePlayerSkill(skill_id);
  6944. if (!more_to_remove) {
  6945. Client* client = player->GetClient();
  6946. if (client) {
  6947. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6948. if (packet)
  6949. client->QueuePacket(packet);
  6950. }
  6951. }
  6952. }
  6953. }
  6954. else {
  6955. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6956. }
  6957. }
  6958. else {
  6959. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6960. }
  6961. return 0;
  6962. }
  6963. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6964. if (!lua_interface)
  6965. return 0;
  6966. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6967. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6968. int16 amount = lua_interface->GetInt8Value(state, 3);
  6969. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6970. if (amount > 0 && skill_type < 100) {
  6971. if (player_spawn && player_spawn->IsPlayer()) {
  6972. Player* player = (Player*)player_spawn;
  6973. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6974. if (!more_to_increase) {
  6975. Client* client = player->GetClient();
  6976. if (client) {
  6977. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6978. if (packet)
  6979. client->QueuePacket(packet);
  6980. }
  6981. }
  6982. }
  6983. else {
  6984. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6985. }
  6986. }
  6987. else {
  6988. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6989. }
  6990. return 0;
  6991. }
  6992. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6993. if (!lua_interface)
  6994. return 0;
  6995. Spawn* spawn = lua_interface->GetSpawn(state);
  6996. string name = lua_interface->GetStringValue(state, 2);
  6997. if (!spawn) {
  6998. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6999. return 0;
  7000. }
  7001. if (!spawn->IsEntity()) {
  7002. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7003. return 0;
  7004. }
  7005. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7006. if (skill) {
  7007. lua_interface->SetSkillValue(state, skill);
  7008. return 1;
  7009. }
  7010. return 0;
  7011. }
  7012. int EQ2Emu_lua_AddProc(lua_State* state) {
  7013. if (!lua_interface)
  7014. return 0;
  7015. Spawn* spawn = lua_interface->GetSpawn(state);
  7016. int8 type = lua_interface->GetInt8Value(state, 2);
  7017. float chance = lua_interface->GetFloatValue(state, 3);
  7018. Item* item = lua_interface->GetItem(state, 4);
  7019. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7020. LuaSpell* spell = 0;
  7021. if (!spawn && (!spell || !use_all_spelltargets)) {
  7022. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7023. return 0;
  7024. }
  7025. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7026. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7027. return 0;
  7028. }
  7029. if (!item)
  7030. spell = lua_interface->GetCurrentSpell(state);
  7031. if (!item && !spell) {
  7032. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7033. return 0;
  7034. }
  7035. if (spell && use_all_spelltargets) {
  7036. Spawn* target;
  7037. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7038. for (int8 i = 0; i < spell->targets.size(); i++) {
  7039. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7040. if (!target || !target->IsEntity())
  7041. continue;
  7042. ((Entity*)target)->AddProc(type, chance, item, spell);
  7043. }
  7044. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7045. }
  7046. else
  7047. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7048. return 0;
  7049. }
  7050. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7051. if (!lua_interface)
  7052. return 0;
  7053. Spawn* spawn = lua_interface->GetSpawn(state);
  7054. Item* item = lua_interface->GetItem(state, 2);
  7055. LuaSpell* spell = 0;
  7056. if (!spawn) {
  7057. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7058. return 0;
  7059. }
  7060. if (!spawn->IsEntity()) {
  7061. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7062. return 0;
  7063. }
  7064. if (!item)
  7065. spell = lua_interface->GetCurrentSpell(state);
  7066. if (!item && !spell) {
  7067. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7068. return 0;
  7069. }
  7070. if (spell) {
  7071. Spawn* target;
  7072. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7073. for (int8 i = 0; i < spell->targets.size(); i++) {
  7074. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7075. if (!target || !target->IsEntity())
  7076. continue;
  7077. ((Entity*)target)->RemoveProc(item, spell);
  7078. }
  7079. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7080. spell->caster->RemoveProc(item, spell);
  7081. }
  7082. else
  7083. ((Entity*)spawn)->RemoveProc(item, spell);
  7084. return 0;
  7085. }
  7086. int EQ2Emu_lua_Knockback(lua_State* state) {
  7087. if (!lua_interface)
  7088. return 0;
  7089. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7090. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7091. int32 duration = lua_interface->GetInt32Value(state, 3);
  7092. float vertical = lua_interface->GetFloatValue(state, 4);
  7093. float horizontal = lua_interface->GetFloatValue(state, 5);
  7094. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7095. if (!target_spawn) {
  7096. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7097. return 0;
  7098. }
  7099. if (!spawn) {
  7100. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7101. return 0;
  7102. }
  7103. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7104. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7105. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7106. if (packet) {
  7107. packet->setDataByName("target_x", target_spawn->GetX());
  7108. packet->setDataByName("target_y", target_spawn->GetY());
  7109. packet->setDataByName("target_z", target_spawn->GetZ());
  7110. packet->setDataByName("vertical_movement", vertical);
  7111. packet->setDataByName("horizontal_movement", horizontal);
  7112. if (use_heading)
  7113. packet->setDataByName("use_player_heading", 1);
  7114. client->QueuePacket(packet->serialize());
  7115. }
  7116. safe_delete(packet);
  7117. }
  7118. return 0;
  7119. }
  7120. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7121. if (!lua_interface)
  7122. return 0;
  7123. Spawn* spawn = lua_interface->GetSpawn(state);
  7124. if (!spawn) {
  7125. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7129. return 1;
  7130. }
  7131. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7132. if (!lua_interface)
  7133. return 0;
  7134. Spawn* caster = lua_interface->GetSpawn(state);
  7135. Spawn* target = lua_interface->GetSpawn(state, 2);
  7136. string name = lua_interface->GetStringValue(state, 3);
  7137. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7138. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7139. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7140. string success_msg = lua_interface->GetStringValue(state, 7);
  7141. string effect_msg = lua_interface->GetStringValue(state, 8);
  7142. if (!caster) {
  7143. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7144. return 0;
  7145. }
  7146. if (!caster->IsEntity()) {
  7147. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7148. return 0;
  7149. }
  7150. if (!target) {
  7151. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7152. return 0;
  7153. }
  7154. if (!target->IsEntity()) {
  7155. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7156. return 0;
  7157. }
  7158. if (name.length() == 0) {
  7159. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7163. return 0;
  7164. }
  7165. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7166. if (!lua_interface)
  7167. return 0;
  7168. string name = lua_interface->GetStringValue(state);
  7169. if (name.length() == 0) {
  7170. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7171. return 0;
  7172. }
  7173. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7174. if (!skill) {
  7175. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7176. return 0;
  7177. }
  7178. lua_interface->SetInt32Value(state, skill->skill_id);
  7179. return 1;
  7180. }
  7181. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7182. if (!lua_interface)
  7183. return 0;
  7184. Spawn* spawn = lua_interface->GetSpawn(state);
  7185. if (!spawn) {
  7186. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7187. return 0;
  7188. }
  7189. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7190. return 1;
  7191. }
  7192. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7193. if (!lua_interface)
  7194. return 0;
  7195. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7196. if (!luaspell) {
  7197. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7198. return 0;
  7199. }
  7200. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7201. return 1;
  7202. }
  7203. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7204. if (!lua_interface)
  7205. return 0;
  7206. Spawn* spawn = lua_interface->GetSpawn(state);
  7207. Spawn* target = lua_interface->GetSpawn(state, 2);
  7208. if (!spawn) {
  7209. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7210. return 0;
  7211. }
  7212. if (!spawn->IsEntity()) {
  7213. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7214. return 0;
  7215. }
  7216. if (!target) {
  7217. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7218. return 0;
  7219. }
  7220. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7221. return 1;
  7222. }
  7223. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7224. if (!lua_interface)
  7225. return 0;
  7226. Spawn* spawn = lua_interface->GetSpawn(state);
  7227. Spawn* target = lua_interface->GetSpawn(state, 2);
  7228. if (!spawn) {
  7229. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7230. return 0;
  7231. }
  7232. if (!spawn->IsEntity()) {
  7233. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7234. return 0;
  7235. }
  7236. if (!target) {
  7237. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7238. return 0;
  7239. }
  7240. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7241. return 1;
  7242. }
  7243. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7244. if (!lua_interface)
  7245. return 0;
  7246. Item* item = lua_interface->GetItem(state);
  7247. if (!item) {
  7248. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. lua_interface->SetInt32Value(state, item->details.count);
  7252. return 1;
  7253. }
  7254. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7255. if (!lua_interface)
  7256. return 0;
  7257. Item* item = lua_interface->GetItem(state);
  7258. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7259. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7260. if (!item) {
  7261. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7262. return 0;
  7263. }
  7264. if (!owner) {
  7265. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7266. return 0;
  7267. }
  7268. if (!owner->IsPlayer()) {
  7269. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7270. return 0;
  7271. }
  7272. if (item->stack_count < new_count) {
  7273. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7274. return 0;
  7275. }
  7276. if (new_count > 0) {
  7277. item->details.count = new_count;
  7278. item->save_needed = true;
  7279. }
  7280. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7281. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7282. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7283. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7284. else
  7285. {
  7286. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7287. return 0;
  7288. }
  7289. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7290. if (!client)
  7291. return 0;
  7292. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7293. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7294. if (app)
  7295. client->QueuePacket(app);
  7296. return 0;
  7297. }
  7298. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7299. if (!lua_interface)
  7300. return 0;
  7301. int32 time = lua_interface->GetInt32Value(state);
  7302. string function = lua_interface->GetStringValue(state, 2);
  7303. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7304. Spawn* target = lua_interface->GetSpawn(state, 4);
  7305. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7306. if (time == 0) {
  7307. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7308. return 0;
  7309. }
  7310. if (function.length() == 0) {
  7311. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7312. return 0;
  7313. }
  7314. if (!spell) {
  7315. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7316. return 0;
  7317. }
  7318. SpellScriptTimer* timer = new SpellScriptTimer;
  7319. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7320. #ifdef WIN32
  7321. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7322. #else
  7323. bzero(timer, sizeof(SpellScriptTimer));
  7324. #endif*/
  7325. timer->caster = 0;
  7326. timer->deleteWhenDone = false;
  7327. timer->target = 0;
  7328. timer->time = Timer::GetCurrentTime2() + time;
  7329. timer->customFunction = function;
  7330. timer->spell = spell;
  7331. if (caster)
  7332. timer->caster = caster->GetID();
  7333. if (target)
  7334. timer->target = target->GetID();
  7335. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7336. return 0;
  7337. }
  7338. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7339. if (!lua_interface)
  7340. return 0;
  7341. float hp_perc = lua_interface->GetFloatValue(state);
  7342. float power_perc = lua_interface->GetFloatValue(state, 2);
  7343. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7344. Spawn* target = lua_interface->GetSpawn(state, 4);
  7345. string heal_name = lua_interface->GetStringValue(state, 5);
  7346. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7347. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7348. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7349. if (!spell) {
  7350. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7351. return 0;
  7352. }
  7353. Entity* caster = spell->caster;
  7354. if (!caster) {
  7355. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7356. return 0;
  7357. }
  7358. Client* client = 0;
  7359. PendingResurrection* rez = 0;
  7360. ZoneServer* zone = spell->caster->GetZone();
  7361. if (!target) {
  7362. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7363. if (spell->targets.size() > 0) {
  7364. vector<int32> spell_targets = spell->targets;
  7365. for (int8 i = 0; i < spell_targets.size(); i++) {
  7366. target = zone->GetSpawnByID(spell_targets.at(i));
  7367. if (!target)
  7368. continue;
  7369. if (!target->IsPlayer())
  7370. continue;
  7371. client = target->GetZone()->GetClientBySpawn(target);
  7372. if (!client)
  7373. continue;
  7374. rez = client->GetCurrentRez();
  7375. if (rez->active)
  7376. continue;
  7377. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7378. rez->active = true;
  7379. rez->caster = caster;
  7380. rez->expire_timer = new Timer;
  7381. int32 duration = spell->spell->GetSpellDuration();
  7382. rez->expire_timer->Start(duration * 100);
  7383. rez->hp_perc = hp_perc;
  7384. rez->mp_perc = power_perc;
  7385. rez->range = spell->spell->GetSpellData()->range;
  7386. rez->spell_name = spell->spell->GetName();
  7387. if (heal_name.length() > 0)
  7388. rez->heal_name = heal_name;
  7389. else
  7390. rez->heal_name = rez->spell_name;
  7391. rez->no_calcs = no_calcs;
  7392. rez->crit_mod = crit_mod;
  7393. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7394. if (send_window)
  7395. client->SendResurrectionWindow();
  7396. else {
  7397. target->GetZone()->ResurrectSpawn(target, client);
  7398. rez->should_delete = true;
  7399. }
  7400. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7401. }
  7402. }
  7403. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7404. }
  7405. else {
  7406. client = target->GetZone()->GetClientBySpawn(target);
  7407. if (!client)
  7408. return 0;
  7409. rez = client->GetCurrentRez();
  7410. if (rez->active)
  7411. return 0;
  7412. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7413. rez->active = true;
  7414. rez->caster = caster;
  7415. rez->expire_timer = new Timer;
  7416. int32 duration = spell->spell->GetSpellDuration();
  7417. rez->expire_timer->Start(duration * 100);
  7418. rez->hp_perc = hp_perc;
  7419. rez->mp_perc = power_perc;
  7420. rez->range = spell->spell->GetSpellData()->range;
  7421. rez->spell_name = spell->spell->GetName();
  7422. if (heal_name.length() > 0)
  7423. rez->heal_name = heal_name;
  7424. else
  7425. rez->heal_name = rez->spell_name;
  7426. rez->no_calcs = no_calcs;
  7427. rez->crit_mod = crit_mod;
  7428. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7429. if (send_window)
  7430. client->SendResurrectionWindow();
  7431. else {
  7432. target->GetZone()->ResurrectSpawn(target, client);
  7433. rez->should_delete = true;
  7434. }
  7435. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7436. }
  7437. return 0;
  7438. }
  7439. int EQ2Emu_lua_SetVision(lua_State* state) {
  7440. if (!lua_interface)
  7441. return 0;
  7442. Spawn* spawn = lua_interface->GetSpawn(state);
  7443. int8 vision = lua_interface->GetInt8Value(state, 2);
  7444. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7445. if (!spawn) {
  7446. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. if (!spawn->IsEntity()) {
  7450. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. if (spell && spell->targets.size() > 0) {
  7454. ZoneServer* zone = spell->caster->GetZone();
  7455. for (int8 i = 0; i < spell->targets.size(); i++) {
  7456. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7457. if (target && target->IsEntity()) {
  7458. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7459. if (target->IsPlayer())
  7460. ((Player*)target)->SetCharSheetChanged(true);
  7461. }
  7462. }
  7463. }
  7464. else {
  7465. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7466. if (spawn->IsPlayer())
  7467. ((Player*)spawn)->SetCharSheetChanged(true);
  7468. }
  7469. return 0;
  7470. }
  7471. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7472. if (!lua_interface)
  7473. return 0;
  7474. Spawn* spawn = lua_interface->GetSpawn(state);
  7475. float intensity = lua_interface->GetFloatValue(state, 2);
  7476. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7477. if (!spawn) {
  7478. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7479. return 0;
  7480. }
  7481. if (!spawn->IsEntity()) {
  7482. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7483. return 0;
  7484. }
  7485. if (spell && spell->targets.size() > 0) {
  7486. ZoneServer* zone = spell->caster->GetZone();
  7487. for (int8 i = 0; i < spell->targets.size(); i++) {
  7488. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7489. if (target && target->IsEntity()) {
  7490. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7491. if (target->IsPlayer())
  7492. ((Player*)target)->SetCharSheetChanged(true);
  7493. }
  7494. }
  7495. }
  7496. else {
  7497. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7498. if (spawn->IsPlayer())
  7499. ((Player*)spawn)->SetCharSheetChanged(true);
  7500. }
  7501. return 0;
  7502. }
  7503. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7504. if (!lua_interface)
  7505. return 0;
  7506. Spawn* spawn = lua_interface->GetSpawn(state);
  7507. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7508. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7509. if (!spawn) {
  7510. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7511. return 0;
  7512. }
  7513. if (!spawn->IsEntity()) {
  7514. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. if (spell && spell->targets.size() > 0) {
  7518. ZoneServer* zone = spell->caster->GetZone();
  7519. for (int8 i = 0; i < spell->targets.size(); i++) {
  7520. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7521. if (target && target->IsEntity()) {
  7522. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7523. if (target->IsPlayer())
  7524. ((Player*)target)->SetCharSheetChanged(true);
  7525. }
  7526. }
  7527. }
  7528. else {
  7529. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7530. if (spawn->IsPlayer())
  7531. ((Player*)spawn)->SetCharSheetChanged(true);
  7532. }
  7533. return 0;
  7534. }
  7535. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7536. if (!lua_interface)
  7537. return 0;
  7538. Item* item = lua_interface->GetItem(state);
  7539. int8 type = lua_interface->GetInt32Value(state, 2);
  7540. if (!item) {
  7541. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7542. return 0;
  7543. }
  7544. if (type == 1)
  7545. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7546. else if (type == 2)
  7547. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7548. return 1;
  7549. }
  7550. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7551. if (!lua_interface)
  7552. return 0;
  7553. Spawn* target = lua_interface->GetSpawn(state);
  7554. float val = lua_interface->GetFloatValue(state, 2);
  7555. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7556. // Added from Gangrenous post
  7557. if (spell && spell->resisted)
  7558. return 0;
  7559. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7560. if (val > 1.0f)
  7561. val = 1.0f - (val / 100.0f);
  7562. if (spell && spell->spell && spell->targets.size() > 0) {
  7563. ZoneServer* zone = spell->caster->GetZone();
  7564. for (int32 i = 0; i != spell->targets.size(); i++) {
  7565. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7566. if (spawn && spawn->IsEntity()) {
  7567. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7568. if (spawn->IsPlayer())
  7569. ((Player*)spawn)->SetCharSheetChanged(true);
  7570. }
  7571. }
  7572. }
  7573. else {
  7574. if (target && target->IsEntity()) {
  7575. ((Entity*)target)->SetSpeedMultiplier(val);
  7576. if (target->IsPlayer())
  7577. ((Player*)target)->SetCharSheetChanged(true);
  7578. }
  7579. }
  7580. return 0;
  7581. }
  7582. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7583. if (!lua_interface)
  7584. return 0;
  7585. Spawn* spawn = lua_interface->GetSpawn(state);
  7586. int16 model = lua_interface->GetInt16Value(state, 2);
  7587. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7588. if (spell && spell->spell && spell->targets.size() > 0) {
  7589. ZoneServer* zone = spell->caster->GetZone();
  7590. for (int32 i = 0; i < spell->targets.size(); i++) {
  7591. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7592. if (target)
  7593. target->SetIllusionModel(model);
  7594. }
  7595. }
  7596. else {
  7597. if (!spawn) {
  7598. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7599. return 0;
  7600. }
  7601. spawn->SetIllusionModel(model);
  7602. }
  7603. return 0;
  7604. }
  7605. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7606. if (!lua_interface)
  7607. return 0;
  7608. Spawn* spawn = lua_interface->GetSpawn(state);
  7609. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7610. if (spell && spell->spell && spell->targets.size() > 0) {
  7611. ZoneServer* zone = spell->caster->GetZone();
  7612. for (int32 i = 0; i < spell->targets.size(); i++) {
  7613. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7614. if (target)
  7615. target->SetIllusionModel(0);
  7616. }
  7617. }
  7618. else {
  7619. if (!spawn) {
  7620. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7621. return 0;
  7622. }
  7623. spawn->SetIllusionModel(0);
  7624. }
  7625. return 0;
  7626. }
  7627. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7628. if (!lua_interface)
  7629. return 0;
  7630. Spawn* caster = lua_interface->GetSpawn(state);
  7631. Spawn* target = lua_interface->GetSpawn(state, 2);
  7632. float chance = lua_interface->GetFloatValue(state, 3);
  7633. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7634. if (!caster) {
  7635. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7636. return 0;
  7637. }
  7638. if (!caster->IsEntity()) {
  7639. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7640. return 0;
  7641. }
  7642. if (!target) {
  7643. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7644. return 0;
  7645. }
  7646. if (!target->IsEntity()) {
  7647. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7648. return 0;
  7649. }
  7650. if (chance <= 0) {
  7651. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7652. return 0;
  7653. }
  7654. if (!spell) {
  7655. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7656. return 0;
  7657. }
  7658. if (((Entity*)caster)->GetThreatTransfer()) {
  7659. return 0;
  7660. }
  7661. ThreatTransfer* transfer = new ThreatTransfer;
  7662. transfer->Target = target->GetID();
  7663. transfer->Amount = chance;
  7664. transfer->Spell = spell;
  7665. ((Entity*)caster)->SetThreatTransfer(transfer);
  7666. return 0;
  7667. }
  7668. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7669. if (!lua_interface)
  7670. return 0;
  7671. Spawn* spawn = lua_interface->GetSpawn(state);
  7672. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7673. if (!spawn) {
  7674. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7675. return 0;
  7676. }
  7677. if (!spell) {
  7678. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7682. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7683. ((Entity*)spawn)->SetThreatTransfer(0);
  7684. safe_delete(transfer);
  7685. }
  7686. return 0;
  7687. }
  7688. int EQ2Emu_lua_CureByType(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7692. if (!spell) {
  7693. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7694. return 0;
  7695. }
  7696. int8 cure_count = lua_interface->GetInt8Value(state);
  7697. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7698. string cure_name = lua_interface->GetStringValue(state, 3);
  7699. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7700. Spawn* target = lua_interface->GetSpawn(state, 5);
  7701. if (target) {
  7702. if (!target->IsEntity()) {
  7703. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7704. return 0;
  7705. }
  7706. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7707. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7708. }
  7709. else {
  7710. ZoneServer* zone = spell->caster->GetZone();
  7711. vector<int32> targets = spell->targets;
  7712. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7713. for (int8 i = 0; i < targets.size(); i++) {
  7714. target = zone->GetSpawnByID(targets.at(i));
  7715. if (!target || !target->IsEntity())
  7716. continue;
  7717. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7718. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7719. }
  7720. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7721. }
  7722. return 0;
  7723. }
  7724. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7725. if (!lua_interface)
  7726. return 0;
  7727. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7728. if (!spell) {
  7729. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7730. return 0;
  7731. }
  7732. int8 cure_count = lua_interface->GetInt8Value(state);
  7733. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7734. string cure_name = lua_interface->GetStringValue(state, 3);
  7735. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7736. Spawn* target = lua_interface->GetSpawn(state, 5);
  7737. if (target) {
  7738. if (!target->IsEntity()) {
  7739. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7740. return 0;
  7741. }
  7742. if (((Entity*)target)->GetDetCount() > 0)
  7743. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7744. }
  7745. else {
  7746. ZoneServer* zone = spell->caster->GetZone();
  7747. vector<int32> targets = spell->targets;
  7748. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7749. for (int8 i = 0; i < targets.size(); i++) {
  7750. target = zone->GetSpawnByID(targets.at(i));
  7751. if (!target || !target->IsEntity())
  7752. continue;
  7753. if (((Entity*)target)->GetDetCount() > 0)
  7754. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7755. }
  7756. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7757. }
  7758. return 0;
  7759. }
  7760. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7761. if (!lua_interface)
  7762. return 0;
  7763. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7764. if (!spell) {
  7765. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7766. return 0;
  7767. }
  7768. if (!spell->caster) {
  7769. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. if (!spell->caster->GetZone()) {
  7773. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7774. return 0;
  7775. }
  7776. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7777. return 0;
  7778. }
  7779. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7780. if (!lua_interface)
  7781. return 0;
  7782. Spawn* spawn = lua_interface->GetSpawn(state);
  7783. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7784. if (!spell) {
  7785. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7786. return 0;
  7787. }
  7788. if (spawn && spawn->IsEntity())
  7789. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7790. else {
  7791. ZoneServer* zone = spell->caster->GetZone();
  7792. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7793. for (int32 i = 0; i < spell->targets.size(); i++) {
  7794. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7795. if (!spawn || !spawn->IsEntity())
  7796. continue;
  7797. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7798. }
  7799. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7800. }
  7801. return 0;
  7802. }
  7803. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* spawn = lua_interface->GetSpawn(state);
  7807. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7808. if (!spell) {
  7809. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. if (spawn && spawn->IsEntity())
  7813. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7814. else {
  7815. ZoneServer* zone = spell->caster->GetZone();
  7816. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7817. for (int32 i = 0; i < spell->targets.size(); i++) {
  7818. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7819. if (!spawn || !spawn->IsEntity())
  7820. continue;
  7821. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7822. }
  7823. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7824. }
  7825. return 0;
  7826. }
  7827. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7828. if (!lua_interface)
  7829. return 0;
  7830. Spawn* caster = lua_interface->GetSpawn(state);
  7831. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7832. if (!caster) {
  7833. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7834. return 0;
  7835. }
  7836. if (!caster->IsPlayer()) {
  7837. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7838. return 0;
  7839. }
  7840. Spawn* target = caster->GetTarget();
  7841. if (!target) {
  7842. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7846. if (!client) {
  7847. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7848. return 0;
  7849. }
  7850. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7851. if (ho) {
  7852. ho->SetTarget(target->GetID());
  7853. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7854. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7855. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7856. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7857. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7858. deque<GroupMemberInfo*>::iterator itr;
  7859. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7860. if (group)
  7861. {
  7862. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7863. deque<GroupMemberInfo*>* members = group->GetMembers();
  7864. for (itr = members->begin(); itr != members->end(); itr++) {
  7865. if ((*itr)->client)
  7866. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7867. }
  7868. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7869. }
  7870. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7871. }
  7872. else
  7873. safe_delete(ho);
  7874. }
  7875. else {
  7876. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7877. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7878. }
  7879. else
  7880. safe_delete(ho);
  7881. }
  7882. }
  7883. return 0;
  7884. }
  7885. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7886. if (!lua_interface)
  7887. return 0;
  7888. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7889. if (!spell) {
  7890. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7891. return 0;
  7892. }
  7893. int16 triggerCount = lua_interface->GetInt16Value(state);
  7894. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7895. if (!triggerCount) {
  7896. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. spell->num_triggers = triggerCount;
  7900. spell->had_triggers = true;
  7901. spell->cancel_after_all_triggers = cancel_after_triggers;
  7902. return 0;
  7903. }
  7904. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7905. if (!lua_interface)
  7906. return 0;
  7907. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7908. if (!spell) {
  7909. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7910. return 0;
  7911. }
  7912. lua_interface->SetInt32Value(state, spell->num_triggers);
  7913. return 1;
  7914. }
  7915. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7916. if (!lua_interface)
  7917. return 0;
  7918. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7919. if (!spell) {
  7920. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7921. return 0;
  7922. }
  7923. int16 remove_count = lua_interface->GetInt16Value(state);
  7924. if (!remove_count)
  7925. remove_count = 1;
  7926. if (remove_count >= spell->num_triggers) {
  7927. spell->num_triggers = 0;
  7928. if (spell->cancel_after_all_triggers)
  7929. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7930. }
  7931. else {
  7932. spell->num_triggers -= remove_count;
  7933. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7934. }
  7935. return 0;
  7936. }
  7937. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7938. if (!lua_interface)
  7939. return 0;
  7940. Spawn* spawn = lua_interface->GetSpawn(state);
  7941. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7942. if (!spawn) {
  7943. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. if (!copy_spawn) {
  7947. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7948. return 0;
  7949. }
  7950. spawn->CopySpawnAppearance(copy_spawn);
  7951. return 0;
  7952. }
  7953. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7954. Spawn* spawn = lua_interface->GetSpawn(state);
  7955. int8 type = lua_interface->GetInt8Value(state, 2);
  7956. if (!spawn) {
  7957. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7958. return 0;
  7959. }
  7960. else if (!spawn->IsEntity()) {
  7961. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7962. return 0;
  7963. }
  7964. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7965. return 1;
  7966. }
  7967. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7968. if (!lua_interface)
  7969. return 0;
  7970. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7971. int8 type = lua_interface->GetInt8Value(state);
  7972. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7973. if (!spell) {
  7974. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7975. return 0;
  7976. }
  7977. if (spawn) {
  7978. if (!spawn->IsEntity()) {
  7979. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7980. return 0;
  7981. }
  7982. Entity* entity = ((Entity*)spawn);
  7983. entity->AddImmunity(spell, type);
  7984. }
  7985. else {
  7986. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7987. for (int8 i = 0; i < spell->targets.size(); i++) {
  7988. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7989. if (!spawn || !spawn->IsEntity())
  7990. continue;
  7991. Entity* entity = ((Entity*)spawn);
  7992. entity->AddImmunity(spell, type);
  7993. }
  7994. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7995. }
  7996. return 0;
  7997. }
  7998. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7999. if (!lua_interface)
  8000. return 0;
  8001. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8002. int8 type = lua_interface->GetInt8Value(state);
  8003. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8004. if (!spell) {
  8005. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8006. return 0;
  8007. }
  8008. if (spawn) {
  8009. if (!spawn->IsEntity()) {
  8010. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. Entity* entity = ((Entity*)spawn);
  8014. entity->RemoveImmunity(spell, type);
  8015. }
  8016. else {
  8017. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8018. for (int8 i = 0; i < spell->targets.size(); i++) {
  8019. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8020. if (!spawn || !spawn->IsEntity())
  8021. continue;
  8022. Entity* entity = ((Entity*)spawn);
  8023. entity->RemoveImmunity(spell, type);
  8024. }
  8025. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8026. }
  8027. return 0;
  8028. }
  8029. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8030. if (!lua_interface)
  8031. return 0;
  8032. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8033. if (!spell) {
  8034. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. float snare = lua_interface->GetFloatValue(state);
  8038. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8039. // convert the val to the speed multipler value (100 - val)
  8040. float val = 100.0 - snare;
  8041. val /= 100.0;
  8042. if (spawn) {
  8043. if (!spawn->IsEntity()) {
  8044. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8045. return 0;
  8046. }
  8047. ((Entity*)spawn)->SetSnareValue(spell, val);
  8048. }
  8049. else {
  8050. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8051. for (int8 i = 0; i < spell->targets.size(); i++) {
  8052. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8053. if (!spawn || !spawn->IsEntity())
  8054. continue;
  8055. ((Entity*)spawn)->SetSnareValue(spell, val);
  8056. }
  8057. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8058. }
  8059. return 0;
  8060. }
  8061. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8062. if (!lua_interface)
  8063. return 0;
  8064. Spawn* spawn = lua_interface->GetSpawn(state);
  8065. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8066. if (!spawn) {
  8067. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. if (race_id == 0) {
  8071. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8075. return 1;
  8076. }
  8077. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8078. if (!lua_interface)
  8079. return 0;
  8080. Spawn* spawn = lua_interface->GetSpawn(state);
  8081. if (!spawn) {
  8082. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8086. return 1;
  8087. }
  8088. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8089. if (!lua_interface)
  8090. return 0;
  8091. Spawn* spawn = lua_interface->GetSpawn(state);
  8092. if (!spawn) {
  8093. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8097. return 1;
  8098. }
  8099. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8100. if (!lua_interface)
  8101. return 0;
  8102. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8103. if (!spell) {
  8104. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8105. return 0;
  8106. }
  8107. lua_interface->SetStringValue(state, spell->spell->GetName());
  8108. return 1;
  8109. }
  8110. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8111. if (!lua_interface)
  8112. return 0;
  8113. Quest* quest = lua_interface->GetQuest(state);
  8114. if (!quest) {
  8115. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8119. return 1;
  8120. }
  8121. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8122. if (!lua_interface)
  8123. return 0;
  8124. Quest* quest = lua_interface->GetQuest(state);
  8125. int32 flags = lua_interface->GetInt32Value(state, 2);
  8126. if (!quest) {
  8127. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8128. return 0;
  8129. }
  8130. quest->SetQuestFlags(flags);
  8131. return 0;
  8132. }
  8133. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8134. if (!lua_interface)
  8135. return 0;
  8136. Quest* quest = lua_interface->GetQuest(state);
  8137. Spawn* player = lua_interface->GetSpawn(state, 2);
  8138. int32 step = lua_interface->GetInt32Value(state, 3);
  8139. int32 duration = lua_interface->GetInt32Value(state, 4);
  8140. string action = lua_interface->GetStringValue(state, 5);
  8141. if (!quest) {
  8142. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8143. return 0;
  8144. }
  8145. if (!player) {
  8146. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. if (!player->IsPlayer()) {
  8150. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8151. return 0;
  8152. }
  8153. if (step == 0) {
  8154. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8155. return 0;
  8156. }
  8157. if (duration == 0) {
  8158. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8159. return 0;
  8160. }
  8161. if (action.length() == 0) {
  8162. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8163. return 0;
  8164. }
  8165. Client* client = player->GetZone()->GetClientBySpawn(player);
  8166. if (!client) {
  8167. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8168. return 0;
  8169. }
  8170. quest->SetTimerStep(step);
  8171. quest->AddFailedAction(step, action);
  8172. quest->SetStepTimer(duration);
  8173. client->AddQuestTimer(quest->GetQuestID());
  8174. return 0;
  8175. }
  8176. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8177. if (!lua_interface)
  8178. return 0;
  8179. Quest* quest = lua_interface->GetQuest(state);
  8180. Spawn* player = lua_interface->GetSpawn(state, 2);
  8181. if (!quest) {
  8182. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8183. return 0;
  8184. }
  8185. if (!player) {
  8186. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. if (!player->IsPlayer()) {
  8190. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. Client* client = player->GetZone()->GetClientBySpawn(player);
  8194. if (!client) {
  8195. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8196. return 0;
  8197. }
  8198. quest->SetTimerStep(0);
  8199. quest->SetStepTimer(0);
  8200. client->RemoveQuestTimer(quest->GetQuestID());
  8201. return 0;
  8202. }
  8203. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8204. if (!lua_interface)
  8205. return 0;
  8206. Spawn* player = lua_interface->GetSpawn(state);
  8207. Quest* quest = lua_interface->GetQuest(state, 2);
  8208. int32 step = lua_interface->GetInt32Value(state, 3);
  8209. if (!player) {
  8210. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8211. return 0;
  8212. }
  8213. if (!player->IsPlayer()) {
  8214. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8215. return 0;
  8216. }
  8217. if (!quest) {
  8218. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8219. return 0;
  8220. }
  8221. if (step == 0) {
  8222. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8223. return 0;
  8224. }
  8225. Client* client = player->GetZone()->GetClientBySpawn(player);
  8226. if (!client) {
  8227. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8228. return 0;
  8229. }
  8230. if (quest->RemoveQuestStep(step, client)) {
  8231. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8232. client->GetCurrentZone()->SendQuestUpdates(client);
  8233. }
  8234. else
  8235. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8236. return 0;
  8237. }
  8238. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8239. if (!lua_interface)
  8240. return 0;
  8241. Quest* quest = lua_interface->GetQuest(state, 1);
  8242. int32 step = lua_interface->GetInt32Value(state, 2);
  8243. string desc = lua_interface->GetStringValue(state, 3);
  8244. string task_group = lua_interface->GetStringValue(state, 4);
  8245. if (!quest) {
  8246. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8247. return 0;
  8248. }
  8249. if (step == 0) {
  8250. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8251. return 0;
  8252. }
  8253. QuestStep* quest_step = quest->GetQuestStep(step);
  8254. if (!quest_step) {
  8255. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8256. return 0;
  8257. }
  8258. quest_step->SetStepProgress(0);
  8259. quest_step->SetTaskGroup(task_group);
  8260. quest_step->SetDescription(desc);
  8261. return 0;
  8262. }
  8263. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8264. if (!lua_interface)
  8265. return 0;
  8266. Quest* quest = lua_interface->GetQuest(state);
  8267. int32 step = lua_interface->GetInt32Value(state, 2);
  8268. string action = lua_interface->GetStringValue(state, 3);
  8269. if (!quest) {
  8270. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8271. return 0;
  8272. }
  8273. if (step == 0) {
  8274. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8275. return 0;
  8276. }
  8277. if (action.length() == 0) {
  8278. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. quest->AddFailedAction(step, action);
  8282. return 0;
  8283. }
  8284. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8285. if (!lua_interface)
  8286. return 0;
  8287. Spawn* player = lua_interface->GetSpawn(state);
  8288. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8289. int32 step = lua_interface->GetInt32Value(state, 3);
  8290. if (!player) {
  8291. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8292. return 0;
  8293. }
  8294. if (!player->IsPlayer()) {
  8295. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8296. return 0;
  8297. }
  8298. if (quest_id == 0) {
  8299. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8300. return 0;
  8301. }
  8302. if (step == 0) {
  8303. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8304. return 0;
  8305. }
  8306. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8307. if (!quest) {
  8308. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8309. return 0;
  8310. }
  8311. quest->StepFailed(step);
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* player = lua_interface->GetSpawn(state);
  8318. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8319. if (!player) {
  8320. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. if (!player->IsPlayer()) {
  8324. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. if (quest_id == 0) {
  8328. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8329. return 0;
  8330. }
  8331. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8332. if (!quest) {
  8333. lua_interface->SetInt32Value(state, 0);
  8334. return 1;
  8335. }
  8336. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8337. return 1;
  8338. }
  8339. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8340. if (!lua_interface)
  8341. return 0;
  8342. string name = lua_interface->GetStringValue(state);
  8343. string value = lua_interface->GetStringValue(state, 2);
  8344. string comment = lua_interface->GetStringValue(state, 3);
  8345. if (name.length() == 0) {
  8346. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. if (value.length() == 0) {
  8350. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8351. return 0;
  8352. }
  8353. string varname = string("lua_").append(name);
  8354. Variable* var = variables.FindVariable(varname);
  8355. if (var)
  8356. var->SetValue(value.c_str());
  8357. else {
  8358. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8359. variables.AddVariable(var);
  8360. }
  8361. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8362. return 0;
  8363. }
  8364. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8365. if (!lua_interface)
  8366. return 0;
  8367. string name = lua_interface->GetStringValue(state);
  8368. if (name.length() == 0) {
  8369. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. string varname = string("lua_").append(name);
  8373. Variable* var = variables.FindVariable(varname);
  8374. if (var)
  8375. lua_interface->SetStringValue(state, var->GetValue());
  8376. else
  8377. lua_interface->SetStringValue(state, "NULL");
  8378. return 1;
  8379. }
  8380. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8381. if (!lua_interface)
  8382. return 0;
  8383. Spawn* player = lua_interface->GetSpawn(state);
  8384. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8385. if (!player) {
  8386. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (!player->IsPlayer()) {
  8390. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8394. return 1;
  8395. }
  8396. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8397. if (!lua_interface)
  8398. return 0;
  8399. Spawn* player = lua_interface->GetSpawn(state);
  8400. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8401. if (!player) {
  8402. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8403. return 0;
  8404. }
  8405. if (!player->IsPlayer()) {
  8406. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8407. return 0;
  8408. }
  8409. Language* language = master_languages_list.GetLanguage(language_id);
  8410. if (language)
  8411. {
  8412. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8413. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8414. }
  8415. return 0;
  8416. }
  8417. int EQ2Emu_lua_IsNight(lua_State* state) {
  8418. if (!lua_interface)
  8419. return 0;
  8420. ZoneServer* zone = lua_interface->GetZone(state);
  8421. if (!zone) {
  8422. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8426. return 1;
  8427. }
  8428. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8429. if (!lua_interface)
  8430. return 0;
  8431. Spawn* spawn = lua_interface->GetSpawn(state);
  8432. if (!spawn) {
  8433. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8434. return 0;
  8435. }
  8436. if (!spawn->IsWidget()) {
  8437. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8438. return 0;
  8439. }
  8440. ((Widget*)spawn)->SetMultiFloorLift(true);
  8441. if (spawn->GetZone())
  8442. spawn->GetZone()->AddTransportSpawn(spawn);
  8443. return 0;
  8444. }
  8445. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8446. if (!lua_interface)
  8447. return 0;
  8448. Spawn* player = lua_interface->GetSpawn(state);
  8449. int32 path = lua_interface->GetInt32Value(state, 2);
  8450. if (!player) {
  8451. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!player->IsPlayer()) {
  8455. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. if (path == 0) {
  8459. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8460. return 0;
  8461. }
  8462. Client* client = player->GetZone()->GetClientBySpawn(player);
  8463. if (!client) {
  8464. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8465. return 0;
  8466. }
  8467. client->SendFlightAutoMount(path);
  8468. return 0;
  8469. }
  8470. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8471. if (!lua_interface)
  8472. return 0;
  8473. Spawn* player = lua_interface->GetSpawn(state);
  8474. if (!player) {
  8475. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. if (!player->IsPlayer()) {
  8479. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8480. return 0;
  8481. }
  8482. Client* client = player->GetZone()->GetClientBySpawn(player);
  8483. if (!client) {
  8484. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8485. return 0;
  8486. }
  8487. client->EndAutoMount();
  8488. return 0;
  8489. }
  8490. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8491. if (!lua_interface)
  8492. return 0;
  8493. Spawn* player = lua_interface->GetSpawn(state);
  8494. if (!player) {
  8495. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (!player->IsPlayer()) {
  8499. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. Client* client = player->GetZone()->GetClientBySpawn(player);
  8503. if (!client) {
  8504. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8505. return 0;
  8506. }
  8507. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8508. return 1;
  8509. }
  8510. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8511. if (!lua_interface)
  8512. return 0;
  8513. Spawn* player = lua_interface->GetSpawn(state);
  8514. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8515. int32 value = lua_interface->GetInt32Value(state, 3);
  8516. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8517. if (!player) {
  8518. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8519. return 0;
  8520. }
  8521. if (!player->IsPlayer()) {
  8522. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8523. return 0;
  8524. }
  8525. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8526. return 0;
  8527. }
  8528. int EQ2Emu_lua_GetPlayerHistory(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. if (!player) {
  8534. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8535. return 0;
  8536. }
  8537. if (!player->IsPlayer()) {
  8538. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8539. return 0;
  8540. }
  8541. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8542. if (!hd)
  8543. return 0;
  8544. lua_interface->SetInt32Value(state, hd->Value);
  8545. lua_interface->SetInt32Value(state, hd->Value2);
  8546. return 2;
  8547. }
  8548. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8549. if (!lua_interface)
  8550. return 0;
  8551. Spawn* spawn = lua_interface->GetSpawn(state);
  8552. int32 grid = lua_interface->GetInt32Value(state, 2);
  8553. if (!spawn) {
  8554. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. if (grid == 0) {
  8558. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8559. return 0;
  8560. }
  8561. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8562. return 0;
  8563. }
  8564. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8565. if (!lua_interface)
  8566. return 0;
  8567. Spawn* spawn = lua_interface->GetSpawn(state);
  8568. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8569. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8570. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8571. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8572. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8573. if (!spawn) {
  8574. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8575. return 0;
  8576. }
  8577. //Add this quest to the list of required quests for this spawn
  8578. spawn->SetRequiredHistory(event_id, value1, value2);
  8579. //If private spawn value set
  8580. if (private_spawn) {
  8581. //Set the spawn to be private when not granted access via history
  8582. spawn->AddAllowAccessSpawn(spawn);
  8583. spawn->SetPrivateQuestSpawn(true);
  8584. }
  8585. //This value will override vis_flags in the vis packet
  8586. if (flag_override > 0)
  8587. spawn->SetQuestsRequiredOverride(flag_override);
  8588. return 0;
  8589. }
  8590. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8591. if (!lua_interface)
  8592. return 0;
  8593. Spawn* player = lua_interface->GetSpawn(state);
  8594. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8595. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8596. if (!player) {
  8597. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8598. return 0;
  8599. }
  8600. if (!player->IsPlayer()) {
  8601. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8605. return 1;
  8606. }
  8607. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8608. if (!lua_interface)
  8609. return 0;
  8610. Spawn* player = lua_interface->GetSpawn(state);
  8611. int8 level = lua_interface->GetInt8Value(state, 2);
  8612. if (!player) {
  8613. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8614. return 0;
  8615. }
  8616. if (!player->IsPlayer()) {
  8617. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8618. return 0;
  8619. }
  8620. if (level == 0) {
  8621. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8622. return 0;
  8623. }
  8624. Client* client = player->GetZone()->GetClientBySpawn(player);
  8625. if (!client) {
  8626. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8627. return 0;
  8628. }
  8629. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8630. return 0;
  8631. }
  8632. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8633. if (!lua_interface)
  8634. return 0;
  8635. Spawn* player = lua_interface->GetSpawn(state);
  8636. int32 amount = lua_interface->GetInt32Value(state, 2);
  8637. if (!player) {
  8638. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8639. return 0;
  8640. }
  8641. if (!player->IsPlayer()) {
  8642. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8643. return 0;
  8644. }
  8645. if (amount == 0) {
  8646. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8647. return 0;
  8648. }
  8649. ((Player*)player)->AddCoins(amount);
  8650. return 0;
  8651. }
  8652. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8653. if (!lua_interface)
  8654. return 0;
  8655. Spawn* player = lua_interface->GetSpawn(state);
  8656. int32 amount = lua_interface->GetInt32Value(state, 2);
  8657. if (!player) {
  8658. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8659. return 0;
  8660. }
  8661. if (!player->IsPlayer()) {
  8662. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. if (amount == 0) {
  8666. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8670. return 1;
  8671. }
  8672. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8673. if (!lua_interface)
  8674. return 0;
  8675. ZoneServer* zone = lua_interface->GetZone(state);
  8676. if (!zone) {
  8677. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8678. return 0;
  8679. }
  8680. vector<Entity*> players = zone->GetPlayers();
  8681. if (players.size() == 0)
  8682. return 0;
  8683. lua_createtable(state, players.size(), 0);
  8684. int newTable = lua_gettop(state);
  8685. for (int32 i = 0; i < players.size(); i++) {
  8686. lua_interface->SetSpawnValue(state, players.at(i));
  8687. lua_rawseti(state, newTable, i + 1);
  8688. }
  8689. return 1;
  8690. }
  8691. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8692. if (!lua_interface)
  8693. return 0;
  8694. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8695. if (!zone) {
  8696. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8697. return 0;
  8698. }
  8699. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8700. //Map of <placement_id, location_id>
  8701. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8702. map<int32, int32>::iterator itr;
  8703. vector<Spawn*> group;
  8704. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8705. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8706. if (!location) {
  8707. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8708. return 0;
  8709. }
  8710. Spawn* spawn = 0;
  8711. if (location->entities[0]) {
  8712. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8713. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8714. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8715. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8716. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8717. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8718. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8719. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8720. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8721. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8722. if(spawn && spawn->IsOmittedByDBFlag())
  8723. {
  8724. 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);
  8725. safe_delete(spawn);
  8726. continue;
  8727. }
  8728. if (spawn) {
  8729. const char* script = 0;
  8730. for (int x = 0; x < 3; x++) {
  8731. switch (x) {
  8732. case 0:
  8733. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8734. break;
  8735. case 1:
  8736. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8737. break;
  8738. case 2:
  8739. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8740. break;
  8741. }
  8742. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8743. spawn->SetSpawnScript(string(script));
  8744. break;
  8745. }
  8746. }
  8747. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8748. lua_interface->SetSpawnValue(state, spawn);
  8749. group.push_back(spawn);
  8750. }
  8751. else {
  8752. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8753. safe_delete(spawn);
  8754. }
  8755. }
  8756. }
  8757. if (!group.empty()) {
  8758. lua_createtable(state, group.size(), 0);
  8759. int newTable = lua_gettop(state);
  8760. for (int32 i = 0; i < group.size(); i++) {
  8761. lua_interface->SetSpawnValue(state, group[i]);
  8762. lua_rawseti(state, newTable, i + 1);
  8763. }
  8764. }
  8765. else
  8766. lua_pushnil(state);
  8767. return 1;
  8768. }
  8769. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8770. if (!lua_interface)
  8771. return 0;
  8772. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8773. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8774. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8775. if (!spawn) {
  8776. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. if (anim_id == 0) {
  8780. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. if (leeway == 0)
  8784. leeway = 5000;
  8785. spawn->SetSpawnAnim(anim_id);
  8786. spawn->SetSpawnAnimLeeway(leeway);
  8787. return 0;
  8788. }
  8789. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8790. if (!lua_interface)
  8791. return 0;
  8792. Spawn* player = lua_interface->GetSpawn(state);
  8793. if (!player) {
  8794. return 0;
  8795. }
  8796. Client* client = player->GetZone()->GetClientBySpawn(player);
  8797. if (!client) {
  8798. return 0;
  8799. }
  8800. lua_interface->SetInt32Value(state, client->GetVersion());
  8801. return 1;
  8802. }
  8803. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8804. if (!lua_interface)
  8805. return 0;
  8806. Item* item = lua_interface->GetItem(state);
  8807. if (!item) {
  8808. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8809. return 0;
  8810. }
  8811. lua_interface->SetInt32Value(state, item->details.item_id);
  8812. return 1;
  8813. }
  8814. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8815. if (!lua_interface)
  8816. return 0;
  8817. Spawn* spawn = lua_interface->GetSpawn(state);
  8818. if (!spawn) {
  8819. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8820. return 0;
  8821. }
  8822. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8823. return 1;
  8824. }
  8825. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8826. if (!lua_interface)
  8827. return 0;
  8828. Spawn* spawn = lua_interface->GetSpawn(state);
  8829. if (!spawn) {
  8830. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8831. return 0;
  8832. }
  8833. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8834. return 1;
  8835. }
  8836. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8837. if (!lua_interface)
  8838. return 0;
  8839. Spawn* spawn = lua_interface->GetSpawn(state);
  8840. if (!spawn) {
  8841. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8842. return 0;
  8843. }
  8844. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8845. return 1;
  8846. }
  8847. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8848. if (!lua_interface)
  8849. return 0;
  8850. Spawn* spawn = lua_interface->GetSpawn(state);
  8851. if (!spawn) {
  8852. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8853. return 0;
  8854. }
  8855. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8856. return 1;
  8857. }
  8858. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8859. if (!lua_interface)
  8860. return 0;
  8861. Spawn* spawn = lua_interface->GetSpawn(state);
  8862. float pct = lua_interface->GetFloatValue(state, 2);
  8863. if (!spawn) {
  8864. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. if (pct == 0) {
  8868. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8869. return 0;
  8870. }
  8871. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8872. lua_interface->SetInt32Value(state, amount);
  8873. return 1;
  8874. }
  8875. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8876. if (!lua_interface)
  8877. return 0;
  8878. Spawn* spawn = lua_interface->GetSpawn(state);
  8879. float pct = lua_interface->GetFloatValue(state, 2);
  8880. if (!spawn) {
  8881. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8882. return 0;
  8883. }
  8884. if (pct == 0) {
  8885. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8886. return 0;
  8887. }
  8888. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8889. lua_interface->SetInt32Value(state, amount);
  8890. return 1;
  8891. }
  8892. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8893. if (!lua_interface)
  8894. return 0;
  8895. Spawn* spawn = lua_interface->GetSpawn(state);
  8896. if (!spawn) {
  8897. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. if (!spawn->IsPlayer()) {
  8901. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8902. return 0;
  8903. }
  8904. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8905. return 1;
  8906. }
  8907. int EQ2Emu_lua_Evac(lua_State* state) {
  8908. if (!lua_interface)
  8909. return 0;
  8910. Spawn* target = lua_interface->GetSpawn(state);
  8911. if (target) {
  8912. float x = target->GetZone()->GetSafeX();
  8913. float y = target->GetZone()->GetSafeY();
  8914. float z = target->GetZone()->GetSafeZ();
  8915. float h = target->GetZone()->GetSafeHeading();
  8916. target->SetX(x);
  8917. target->SetY(y);
  8918. target->SetZ(z);
  8919. target->SetHeading(h);
  8920. target->SetSpawnOrigX(target->GetX());
  8921. target->SetSpawnOrigY(target->GetY());
  8922. target->SetSpawnOrigZ(target->GetZ());
  8923. target->SetSpawnOrigHeading(target->GetHeading());
  8924. if (target->IsPlayer()) {
  8925. Client* client = target->GetZone()->GetClientBySpawn(target);
  8926. if (client) {
  8927. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8928. if (packet)
  8929. {
  8930. packet->setDataByName("x", x);
  8931. packet->setDataByName("y", y);
  8932. packet->setDataByName("z", z);
  8933. client->QueuePacket(packet->serialize());
  8934. safe_delete(packet);
  8935. }
  8936. }
  8937. }
  8938. }
  8939. else {
  8940. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8941. ZoneServer* zone = spell->caster->GetZone();
  8942. float x = spell->caster->GetZone()->GetSafeX();
  8943. float y = spell->caster->GetZone()->GetSafeY();
  8944. float z = spell->caster->GetZone()->GetSafeZ();
  8945. float h = spell->caster->GetZone()->GetSafeHeading();
  8946. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8947. for (int32 i = 0; i < spell->targets.size(); i++) {
  8948. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8949. if (!target2)
  8950. continue;
  8951. target2->SetX(x);
  8952. target2->SetY(y);
  8953. target2->SetZ(z);
  8954. target2->SetHeading(h);
  8955. target2->SetSpawnOrigX(target2->GetX());
  8956. target2->SetSpawnOrigY(target2->GetY());
  8957. target2->SetSpawnOrigZ(target2->GetZ());
  8958. target2->SetSpawnOrigHeading(target2->GetHeading());
  8959. if (target2->IsPlayer()) {
  8960. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8961. if (client) {
  8962. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8963. if (packet)
  8964. {
  8965. client->SetReloadingZone(true);
  8966. packet->setDataByName("x", x);
  8967. packet->setDataByName("y", y);
  8968. packet->setDataByName("z", z);
  8969. client->QueuePacket(packet->serialize());
  8970. safe_delete(packet);
  8971. }
  8972. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8973. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8974. }
  8975. }
  8976. }
  8977. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8978. }
  8979. return 0;
  8980. }
  8981. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8982. if (!lua_interface)
  8983. return 0;
  8984. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8985. if (!luaspell) {
  8986. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8987. return 0;
  8988. }
  8989. int8 tier = luaspell->spell->GetSpellTier();
  8990. lua_interface->SetInt32Value(state, tier);
  8991. return 1;
  8992. }
  8993. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8994. if (!lua_interface)
  8995. return 0;
  8996. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8997. if (!luaspell) {
  8998. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8999. return 0;
  9000. }
  9001. int32 spell_id = luaspell->spell->GetSpellID();
  9002. lua_interface->SetInt32Value(state, spell_id);
  9003. return 1;
  9004. }
  9005. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9006. if (!lua_interface)
  9007. return 0;
  9008. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9009. if (!spawn) {
  9010. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. if (!spawn->IsPlayer()) {
  9014. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. ZoneServer* zone = spawn->GetZone();
  9018. if (!zone) {
  9019. return 0;
  9020. }
  9021. Client* client = zone->GetClientBySpawn(spawn);
  9022. if (!client) {
  9023. return 0;
  9024. }
  9025. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9026. return 0;
  9027. }
  9028. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9029. if (!lua_interface)
  9030. return 0;
  9031. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9032. if (!spawn) {
  9033. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9034. return 0;
  9035. }
  9036. if (!spawn->IsPlayer()) {
  9037. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9038. return 0;
  9039. }
  9040. ZoneServer* zone = spawn->GetZone();
  9041. if (!zone) {
  9042. return 0;
  9043. }
  9044. Client* client = zone->GetClientBySpawn(spawn);
  9045. if (!client) {
  9046. return 0;
  9047. }
  9048. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9049. return 0;
  9050. }
  9051. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9052. if (!lua_interface)
  9053. return 0;
  9054. Spawn* caster = lua_interface->GetSpawn(state);
  9055. Spawn* target = lua_interface->GetSpawn(state, 2);
  9056. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9057. string spell_name = lua_interface->GetStringValue(state, 4);
  9058. if (!caster) {
  9059. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9060. return 0;
  9061. }
  9062. if (!caster->IsEntity()) {
  9063. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9064. return 0;
  9065. }
  9066. if (!target) {
  9067. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9068. return 0;
  9069. }
  9070. if (!target->IsEntity()) {
  9071. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9072. return 0;
  9073. }
  9074. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9075. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9076. return 0;
  9077. }
  9078. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9079. if (!lua_interface)
  9080. return 0;
  9081. Spawn* player = lua_interface->GetSpawn(state);
  9082. int32 amount = lua_interface->GetInt32Value(state, 2);
  9083. if (player && player->IsPlayer() && amount > 0) {
  9084. ((Player*)player)->AddXP(amount);
  9085. ((Player*)player)->SetCharSheetChanged(true);
  9086. Client* client = player->GetZone()->GetClientBySpawn(player);
  9087. if (client) {
  9088. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9089. }
  9090. }
  9091. return 0;
  9092. }
  9093. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9094. if (!lua_interface)
  9095. return 0;
  9096. Spawn* player = lua_interface->GetSpawn(state);
  9097. int8 type = lua_interface->GetInt8Value(state, 2);
  9098. string text = lua_interface->GetStringValue(state, 3);
  9099. Client* client = 0;
  9100. if (player && player->IsPlayer())
  9101. client = player->GetZone()->GetClientBySpawn(player);
  9102. if (!client || text.length() == 0) {
  9103. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9104. return 0;
  9105. }
  9106. client->SimpleMessage(type, text.c_str());
  9107. return 0;
  9108. }
  9109. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9110. if (!lua_interface)
  9111. return 0;
  9112. Spawn* player = lua_interface->GetSpawn(state);
  9113. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9114. Client* client = 0;
  9115. if (player && player->IsPlayer())
  9116. client = player->GetZone()->GetClientBySpawn(player);
  9117. if (!client || !spawn) {
  9118. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9119. return 0;
  9120. }
  9121. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9122. if (!items) {
  9123. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9124. return 0;
  9125. }
  9126. client->Loot(spawn->GetLootCoins(), items, spawn);
  9127. return 0;
  9128. }
  9129. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9130. if (!lua_interface)
  9131. return 0;
  9132. Spawn* spawnref = lua_interface->GetSpawn(state);
  9133. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9134. if (spawn_id > 0 && spawnref) {
  9135. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9136. if (spawns.size() == 0) {
  9137. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9138. return 0;
  9139. }
  9140. Spawn* spawn = 0;
  9141. int16 index = MakeRandomInt(0, spawns.size());
  9142. if (index >= spawns.size() || index < 0)
  9143. index = 0;
  9144. spawn = spawns[index];
  9145. lua_interface->SetSpawnValue(state, spawn);
  9146. return 1;
  9147. }
  9148. else {
  9149. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9150. }
  9151. return 0;
  9152. }
  9153. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9154. Spawn* player = lua_interface->GetSpawn(state);
  9155. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9156. string name = lua_interface->GetStringValue(state, 3);
  9157. float distance = lua_interface->GetFloatValue(state, 4);
  9158. string command = lua_interface->GetStringValue(state, 5);
  9159. string error_text = lua_interface->GetStringValue(state, 6);
  9160. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9161. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9162. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9163. if (distance == 0)
  9164. distance = 10.0f;
  9165. if (command.length() == 0)
  9166. command = name;
  9167. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9168. if (spawns.size() == 0) {
  9169. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9170. return 0;
  9171. }
  9172. Spawn* spawn = 0;
  9173. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9174. spawn = *itr;
  9175. if (spawn) {
  9176. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9177. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9178. }
  9179. }
  9180. }
  9181. return 0;
  9182. }
  9183. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9184. if (!lua_interface)
  9185. return 0;
  9186. Client* client = 0;
  9187. Spawn* player = lua_interface->GetSpawn(state);
  9188. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9189. if (player && player->IsPlayer() && player->GetZone())
  9190. client = player->GetZone()->GetClientBySpawn(player);
  9191. else{
  9192. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9193. return 0;
  9194. }
  9195. if (client) {
  9196. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9197. if (packet) {
  9198. packet->setDataByName("goal_num", goal_num);
  9199. client->QueuePacket(packet->serialize());
  9200. safe_delete(packet);
  9201. }
  9202. }
  9203. return 0;
  9204. }
  9205. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9206. if (!lua_interface)
  9207. return 0;
  9208. Client* client = 0;
  9209. Spawn* player = lua_interface->GetSpawn(state);
  9210. if (player && player->IsPlayer() && player->GetZone())
  9211. client = player->GetZone()->GetClientBySpawn(player);
  9212. else {
  9213. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9214. return 0;
  9215. }
  9216. if (client) {
  9217. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9218. }
  9219. return 0;
  9220. }
  9221. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9222. if (!lua_interface)
  9223. return 0;
  9224. Client* client = 0;
  9225. Spawn* player = lua_interface->GetSpawn(state);
  9226. float duration = lua_interface->GetFloatValue(state, 2);
  9227. string text = lua_interface->GetStringValue(state, 3);
  9228. string voice = lua_interface->GetStringValue(state, 4);
  9229. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9230. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9231. string signal = lua_interface->GetStringValue(state, 7);
  9232. string goal1 = lua_interface->GetStringValue(state, 8);
  9233. string task1 = lua_interface->GetStringValue(state, 9);
  9234. string goal2 = lua_interface->GetStringValue(state, 10);
  9235. string task2 = lua_interface->GetStringValue(state, 11);
  9236. string goal3 = lua_interface->GetStringValue(state, 12);
  9237. string task3 = lua_interface->GetStringValue(state, 13);
  9238. string goal4 = lua_interface->GetStringValue(state, 14);
  9239. string task4 = lua_interface->GetStringValue(state, 15);
  9240. if (!player) {
  9241. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9242. return 0;
  9243. }
  9244. if (!player->IsPlayer()) {
  9245. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9246. return 0;
  9247. }
  9248. else
  9249. client = ((Player*)player)->GetClient();
  9250. if (!client) {
  9251. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9252. return 0;
  9253. }
  9254. if (text.length() == 0) {
  9255. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9256. return 0;
  9257. }
  9258. if (duration >= 0 && duration < 2)
  9259. duration = 2;
  9260. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9261. if (packet) {
  9262. packet->setDataByName("open_seconds_max", duration);
  9263. packet->setDataByName("text", text.c_str());
  9264. packet->setDataByName("voice", voice.c_str());
  9265. int8 num_goals = 1;
  9266. if (task2.length() > 0)
  9267. num_goals++;
  9268. if (task3.length() > 0)
  9269. num_goals++;
  9270. if (task4.length() > 0)
  9271. num_goals++;
  9272. packet->setArrayLengthByName("num_goals", num_goals);
  9273. for (int8 i = 0; i < num_goals; i++) {
  9274. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9275. }
  9276. if (goal1.length() > 0)
  9277. packet->setArrayDataByName("goal_text", goal1.c_str());
  9278. if (goal2.length() > 0)
  9279. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9280. if (goal3.length() > 0)
  9281. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9282. if (goal4.length() > 0)
  9283. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9284. packet->setSubArrayDataByName("task_text", task1.c_str());
  9285. if (task2.length() > 0)
  9286. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9287. if (task3.length() > 0)
  9288. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9289. if (task4.length() > 0)
  9290. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9291. packet->setDataByName("complete_sound", "click");
  9292. packet->setDataByName("signal", signal.c_str());
  9293. packet->setDataByName("voice_key1", voice_key1);
  9294. packet->setDataByName("voice_key2", voice_key2);
  9295. client->QueuePacket(packet->serialize());
  9296. safe_delete(packet);
  9297. }
  9298. return 0;
  9299. }
  9300. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9301. if (!lua_interface)
  9302. return 0;
  9303. Client* client = 0;
  9304. Spawn* player = lua_interface->GetSpawn(state);
  9305. string window = lua_interface->GetStringValue(state, 2);
  9306. int8 show = lua_interface->GetInt8Value(state, 3);
  9307. if (!player) {
  9308. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9309. return 0;
  9310. }
  9311. if (!player->IsPlayer()) {
  9312. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9313. return 0;
  9314. }
  9315. else
  9316. client = ((Player*)player)->GetClient();
  9317. if (!client) {
  9318. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9319. return 0;
  9320. }
  9321. if (window.length() == 0) {
  9322. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9323. return 0;
  9324. }
  9325. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9326. if (packet) {
  9327. packet->setDataByName("window", window.c_str());
  9328. packet->setDataByName("show", show);
  9329. client->QueuePacket(packet->serialize());
  9330. safe_delete(packet);
  9331. }
  9332. return 0;
  9333. }
  9334. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9335. //See GameEvents.txt for options that can be used for this function
  9336. if (!lua_interface)
  9337. return 0;
  9338. Client* client = 0;
  9339. Spawn* player = lua_interface->GetSpawn(state);
  9340. string event_name = lua_interface->GetStringValue(state, 2);
  9341. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9342. if (!player || !player->IsPlayer()) {
  9343. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9344. return 0;
  9345. }
  9346. if (player->GetZone())
  9347. client = player->GetZone()->GetClientBySpawn(player);
  9348. if (!client) {
  9349. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9350. return 0;
  9351. }
  9352. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9353. if (packet) {
  9354. packet->setDataByName("event_name", event_name.c_str());
  9355. packet->setDataByName("enabled", enabled);
  9356. client->QueuePacket(packet->serialize());
  9357. safe_delete(packet);
  9358. }
  9359. return 0;
  9360. }
  9361. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9362. if (!lua_interface)
  9363. return 0;
  9364. Spawn* player = lua_interface->GetSpawn(state);
  9365. if (player && player->IsPlayer()) {
  9366. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9367. return 1;
  9368. }
  9369. return 0;
  9370. }
  9371. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9372. if (!lua_interface)
  9373. return 0;
  9374. Spawn* player = lua_interface->GetSpawn(state);
  9375. int8 step = lua_interface->GetInt8Value(state, 2);
  9376. if (player && player->IsPlayer() && step > 0) {
  9377. ((Player*)player)->SetTutorialStep(step);
  9378. }
  9379. return 0;
  9380. }
  9381. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9382. if (!lua_interface)
  9383. return 0;
  9384. Client* client = 0;
  9385. Spawn* player = lua_interface->GetSpawn(state);
  9386. string window = lua_interface->GetStringValue(state, 2);
  9387. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9388. if (!player) {
  9389. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9390. return 0;
  9391. }
  9392. if (!player->IsPlayer()) {
  9393. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9394. return 0;
  9395. }
  9396. else
  9397. client = ((Player*)player)->GetClient();
  9398. if (!client) {
  9399. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9400. return 0;
  9401. }
  9402. if (window.length() == 0) {
  9403. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9404. return 0;
  9405. }
  9406. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9407. if (packet) {
  9408. packet->setDataByName("window", window.c_str());
  9409. packet->setDataByName("flash_seconds", flash_seconds);
  9410. client->QueuePacket(packet->serialize());
  9411. safe_delete(packet);
  9412. }
  9413. return 0;
  9414. }
  9415. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9416. if (!lua_interface)
  9417. return 0;
  9418. Spawn* spawn = lua_interface->GetSpawn(state);
  9419. Spawn* target = lua_interface->GetSpawn(state, 2);
  9420. if (spawn && target)
  9421. return spawn->CheckLoS(target);
  9422. return 0;
  9423. }
  9424. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9425. if (!lua_interface)
  9426. return 0;
  9427. Spawn* spawn = lua_interface->GetSpawn(state);
  9428. float x = lua_interface->GetFloatValue(state, 2);
  9429. float y = lua_interface->GetFloatValue(state, 3);
  9430. float z = lua_interface->GetFloatValue(state, 4);
  9431. if (spawn)
  9432. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9433. return 0;
  9434. }
  9435. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9436. if (!lua_interface)
  9437. return 0;
  9438. ZoneServer* zone = lua_interface->GetZone(state);
  9439. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9440. if (zone)
  9441. zone->SetExpansionFlag(xpackFlag);
  9442. return 0;
  9443. }
  9444. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9445. if (!lua_interface)
  9446. return 0;
  9447. ZoneServer* zone = lua_interface->GetZone(state);
  9448. if (zone) {
  9449. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9450. return 1;
  9451. }
  9452. return 0;
  9453. }
  9454. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9455. if (!lua_interface)
  9456. return 0;
  9457. ZoneServer* zone = lua_interface->GetZone(state);
  9458. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9459. if (zone)
  9460. zone->SetHolidayFlag(holidayFlag);
  9461. return 0;
  9462. }
  9463. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9464. if (!lua_interface)
  9465. return 0;
  9466. ZoneServer* zone = lua_interface->GetZone(state);
  9467. if (zone) {
  9468. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9469. return 1;
  9470. }
  9471. return 0;
  9472. }
  9473. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. Spawn* spawn = lua_interface->GetSpawn(state);
  9477. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9478. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9479. float distance = lua_interface->GetFloatValue(state, 4);
  9480. string in_range_function = lua_interface->GetStringValue(state, 5);
  9481. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9482. if (spawn && distance > 0 && in_range_function.length() > 0)
  9483. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9484. return 0;
  9485. }
  9486. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9487. if (!lua_interface)
  9488. return 0;
  9489. Spawn* spawn = lua_interface->GetSpawn(state);
  9490. Spawn* target = lua_interface->GetSpawn(state, 2);
  9491. if (spawn && target)
  9492. {
  9493. if (spawn->IsPlayer() && target->IsEntity())
  9494. {
  9495. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9496. return 1;
  9497. }
  9498. else if (spawn->IsEntity() && target->IsEntity())
  9499. {
  9500. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9501. return 1;
  9502. }
  9503. }
  9504. return 0;
  9505. }
  9506. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9507. if (!lua_interface)
  9508. return 0;
  9509. Spawn* spawn = lua_interface->GetSpawn(state);
  9510. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9511. if (spawn && spawn->IsEntity())
  9512. {
  9513. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9514. if (spawn->IsPlayer())
  9515. {
  9516. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9517. if (client)
  9518. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9519. }
  9520. }
  9521. return 0;
  9522. }
  9523. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9524. if (!lua_interface)
  9525. return 0;
  9526. Spawn* spawn = lua_interface->GetSpawn(state);
  9527. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9528. if (spawn && spawn->IsEntity())
  9529. {
  9530. ((Entity*)spawn)->SetSeeHideSpell(val);
  9531. if (spawn->IsPlayer())
  9532. {
  9533. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9534. if (client)
  9535. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9536. }
  9537. }
  9538. return 0;
  9539. }
  9540. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9541. {
  9542. if (!lua_interface)
  9543. return 0;
  9544. Spawn* player = lua_interface->GetSpawn(state);
  9545. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9546. string command = lua_interface->GetStringValue(state, 3);
  9547. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9548. lua_interface->ResetFunctionStack(state);
  9549. if (spawn && player && player->IsPlayer())
  9550. {
  9551. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9552. bool res = false;
  9553. if (cmd)
  9554. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9555. lua_interface->SetBooleanValue(state, res);
  9556. return 1;
  9557. }
  9558. return 0;
  9559. }
  9560. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9561. {
  9562. if (!lua_interface)
  9563. return 0;
  9564. Spawn* spawn = lua_interface->GetSpawn(state);
  9565. int32 charID = lua_interface->GetInt32Value(state, 2);
  9566. string command = lua_interface->GetStringValue(state, 3);
  9567. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9568. lua_interface->ResetFunctionStack(state);
  9569. if (spawn && charID)
  9570. {
  9571. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9572. bool res = false;
  9573. if (cmd)
  9574. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9575. lua_interface->SetBooleanValue(state, res);
  9576. return 1;
  9577. }
  9578. return 0;
  9579. }
  9580. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9581. {
  9582. if (!lua_interface)
  9583. return 0;
  9584. Spawn* spawn = lua_interface->GetSpawn(state);
  9585. string command = lua_interface->GetStringValue(state, 2);
  9586. lua_interface->ResetFunctionStack(state);
  9587. if (spawn && command.length() > 0)
  9588. spawn->RemovePrimaryEntityCommand(command.c_str());
  9589. return 0;
  9590. }
  9591. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9592. if (!lua_interface)
  9593. return 0;
  9594. Spawn* spawn = lua_interface->GetSpawn(state);
  9595. float distance = lua_interface->GetFloatValue(state, 2);
  9596. string command = lua_interface->GetStringValue(state, 3);
  9597. Spawn* player = lua_interface->GetSpawn(state, 4);
  9598. lua_interface->ResetFunctionStack(state);
  9599. if (spawn) {
  9600. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9601. }
  9602. return 0;
  9603. }
  9604. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9605. if (!lua_interface)
  9606. return 0;
  9607. Spawn* spawn = lua_interface->GetSpawn(state);
  9608. Spawn* player = lua_interface->GetSpawn(state, 2);
  9609. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9610. lua_interface->ResetFunctionStack(state);
  9611. if (spawn && player && transport_id && player->IsPlayer()) {
  9612. Client* client = 0;
  9613. if (player && player->IsPlayer())
  9614. client = player->GetZone()->GetClientBySpawn(player);
  9615. if (!client)
  9616. return 0;
  9617. vector<TransportDestination*> destinations;
  9618. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9619. if (destinations.size())
  9620. {
  9621. client->SetTemporaryTransportID(transport_id);
  9622. client->ProcessTeleport(spawn, &destinations, transport_id);
  9623. }
  9624. else
  9625. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9626. }
  9627. return 0;
  9628. }
  9629. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9630. if (!lua_interface)
  9631. return 0;
  9632. Spawn* player = lua_interface->GetSpawn(state);
  9633. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9634. lua_interface->ResetFunctionStack(state);
  9635. if (player && player->IsPlayer()) {
  9636. Client* client = 0;
  9637. if (player && player->IsPlayer())
  9638. client = player->GetZone()->GetClientBySpawn(player);
  9639. if (!client)
  9640. return 0;
  9641. client->SetTemporaryTransportID(transport_id);
  9642. }
  9643. return 0;
  9644. }
  9645. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9646. if (!lua_interface)
  9647. return 0;
  9648. Spawn* player = lua_interface->GetSpawn(state);
  9649. lua_interface->ResetFunctionStack(state);
  9650. if (player && player->IsPlayer()) {
  9651. Client* client = 0;
  9652. if (player && player->IsPlayer())
  9653. client = player->GetZone()->GetClientBySpawn(player);
  9654. if (!client)
  9655. return 0;
  9656. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9657. return 1;
  9658. }
  9659. return 0;
  9660. }
  9661. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9662. if (!lua_interface)
  9663. return 0;
  9664. Spawn* spawn = lua_interface->GetSpawn(state);
  9665. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9666. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9667. if (!spawn) {
  9668. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9669. return 0;
  9670. }
  9671. if (!spawn->IsEntity()) {
  9672. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9673. return 0;
  9674. }
  9675. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9676. {
  9677. 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);
  9678. return 0;
  9679. }
  9680. lua_interface->ResetFunctionStack(state);
  9681. if (spell && spell->targets.size() > 0) {
  9682. ZoneServer* zone = spell->caster->GetZone();
  9683. for (int8 i = 0; i < spell->targets.size(); i++) {
  9684. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9685. if (target && target->IsEntity()) {
  9686. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9687. if (target->IsPlayer())
  9688. ((Player*)target)->SetCharSheetChanged(true);
  9689. }
  9690. }
  9691. }
  9692. else {
  9693. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9694. if (spawn->IsPlayer())
  9695. ((Player*)spawn)->SetCharSheetChanged(true);
  9696. }
  9697. return 0;
  9698. }
  9699. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9700. if (!lua_interface)
  9701. return 0;
  9702. Spawn* spawn = lua_interface->GetSpawn(state);
  9703. lua_interface->ResetFunctionStack(state);
  9704. if (!spawn) {
  9705. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9706. return 0;
  9707. }
  9708. if (!spawn->IsEntity()) {
  9709. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9710. return 0;
  9711. }
  9712. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9713. return 1;
  9714. }
  9715. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9716. if (!lua_interface)
  9717. return 0;
  9718. int32 spell_id = lua_interface->GetInt32Value(state);
  9719. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9720. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9721. if (spell_id > 0) {
  9722. if (spell_tier == 0)
  9723. spell_tier = 1;
  9724. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9725. LuaSpell* lua_spell = 0;
  9726. if(custom_lua_script.size() > 0)
  9727. {
  9728. // attempt to load the custom script since it isn't already loaded
  9729. // we will re-obtain the lua_spell further below
  9730. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9731. {
  9732. 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());
  9733. lua_interface->LoadLuaSpell(custom_lua_script);
  9734. }
  9735. }
  9736. else
  9737. custom_lua_script = spell->GetSpellData()->lua_script;
  9738. if (!lua_spell && lua_interface)
  9739. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9740. if (!lua_spell)
  9741. {
  9742. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9743. return 0;
  9744. }
  9745. lua_spell->spell = new Spell(spell);
  9746. lua_interface->AddCustomSpell(lua_spell);
  9747. lua_interface->SetSpellValue(state, lua_spell);
  9748. return 1;
  9749. }
  9750. return 0;
  9751. }
  9752. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9753. if (!lua_interface)
  9754. return 0;
  9755. LuaSpell* spell = lua_interface->GetSpell(state);
  9756. string field = lua_interface->GetStringValue(state, 2);
  9757. if (!spell) {
  9758. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9759. return 0;
  9760. }
  9761. if (!spell->spell || !spell->spell->GetSpellData()) {
  9762. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9763. return 0;
  9764. }
  9765. boost::to_lower(field);
  9766. return spell->spell->GetSpellData(state, field);
  9767. }
  9768. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9769. if (!lua_interface)
  9770. return 0;
  9771. LuaSpell* spell = lua_interface->GetSpell(state);
  9772. string field = lua_interface->GetStringValue(state, 2);
  9773. int8 fieldArg = 3; // field value after the initial set
  9774. if (!spell) {
  9775. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9776. return 0;
  9777. }
  9778. if (!spell->spell || !spell->spell->GetSpellData()) {
  9779. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9780. return 0;
  9781. }
  9782. boost::to_lower(field);
  9783. bool valSet = false;
  9784. spell->spell->SetSpellData(state, field, fieldArg);
  9785. return valSet;
  9786. }
  9787. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9788. if (!lua_interface)
  9789. return 0;
  9790. LuaSpell* spell = lua_interface->GetSpell(state);
  9791. int8 idx = lua_interface->GetInt32Value(state, 2);
  9792. if (!spell) {
  9793. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9794. return 0;
  9795. }
  9796. if (!spell->spell || !spell->spell->GetSpellData()) {
  9797. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9798. return 0;
  9799. }
  9800. if (spell->spell->lua_data.size() <= idx)
  9801. {
  9802. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9803. return 0;
  9804. }
  9805. bool setVal = true;
  9806. LUAData* data = spell->spell->lua_data[idx];
  9807. switch (data->type)
  9808. {
  9809. case 0:
  9810. {
  9811. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9812. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9813. data->int_value = value;
  9814. data->int_value2 = value2;
  9815. break;
  9816. }
  9817. case 1:
  9818. {
  9819. float value = lua_interface->GetFloatValue(state, 3);
  9820. float value2 = lua_interface->GetFloatValue(state, 4);
  9821. data->float_value = value;
  9822. data->float_value2 = value2;
  9823. break;
  9824. }
  9825. case 2:
  9826. {
  9827. bool value = lua_interface->GetBooleanValue(state, 3);
  9828. data->bool_value = value;
  9829. break;
  9830. }
  9831. case 3:
  9832. {
  9833. string value = lua_interface->GetStringValue(state, 3);
  9834. string value2 = lua_interface->GetStringValue(state, 4);
  9835. data->string_value = value;
  9836. data->string_value2 = value2;
  9837. break;
  9838. }
  9839. default:
  9840. setVal = false;
  9841. }
  9842. return setVal;
  9843. }
  9844. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9845. if (!lua_interface)
  9846. return 0;
  9847. LuaSpell* spell = lua_interface->GetSpell(state);
  9848. int8 idx = lua_interface->GetInt32Value(state, 2);
  9849. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9850. if (!spell) {
  9851. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9852. return 0;
  9853. }
  9854. if (!spell->spell || !spell->spell->GetSpellData()) {
  9855. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9856. return 0;
  9857. }
  9858. if (spell->spell->lua_data.size() <= idx)
  9859. {
  9860. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9861. return 0;
  9862. }
  9863. bool setVal = true;
  9864. LUAData* data = spell->spell->lua_data[idx];
  9865. switch (data->type)
  9866. {
  9867. case 0:
  9868. {
  9869. if(!secondfield)
  9870. lua_interface->SetSInt32Value(state, data->int_value);
  9871. else
  9872. lua_interface->SetSInt32Value(state, data->int_value2);
  9873. break;
  9874. }
  9875. case 1:
  9876. {
  9877. if (!secondfield)
  9878. lua_interface->SetFloatValue(state, data->float_value);
  9879. else
  9880. lua_interface->SetFloatValue(state, data->float_value2);
  9881. break;
  9882. }
  9883. case 2:
  9884. {
  9885. lua_interface->SetBooleanValue(state, data->bool_value);
  9886. break;
  9887. }
  9888. case 3:
  9889. {
  9890. if (!secondfield)
  9891. lua_interface->SetStringValue(state, data->string_value.c_str());
  9892. else
  9893. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9894. break;
  9895. }
  9896. default:
  9897. setVal = false;
  9898. }
  9899. return setVal;
  9900. }
  9901. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9902. if (!lua_interface)
  9903. return 0;
  9904. LuaSpell* spell = lua_interface->GetSpell(state);
  9905. int8 idx = lua_interface->GetInt32Value(state, 2);
  9906. string field = lua_interface->GetStringValue(state, 3);
  9907. boost::to_lower(field);
  9908. if (!spell) {
  9909. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9910. return 0;
  9911. }
  9912. if (!spell->spell || !spell->spell->GetSpellData()) {
  9913. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9914. return 0;
  9915. }
  9916. if (spell->spell->effects.size() <= idx)
  9917. {
  9918. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9919. return 0;
  9920. }
  9921. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9922. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9923. if (field == "description")
  9924. effect->description = string(lua_interface->GetStringValue(state, 4));
  9925. else if (field == "bullet")
  9926. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9927. else if (field == "percentage")
  9928. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9929. else // no match
  9930. return 0;
  9931. return 1;
  9932. }
  9933. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9934. if (!lua_interface)
  9935. return 0;
  9936. LuaSpell* spell = lua_interface->GetSpell(state);
  9937. int8 idx = lua_interface->GetInt32Value(state, 2);
  9938. string field = lua_interface->GetStringValue(state, 3);
  9939. boost::to_lower(field);
  9940. if (!spell) {
  9941. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9942. return 0;
  9943. }
  9944. if (!spell->spell || !spell->spell->GetSpellData()) {
  9945. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9946. return 0;
  9947. }
  9948. if (spell->spell->effects.size() <= idx)
  9949. {
  9950. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9951. return 0;
  9952. }
  9953. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9954. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9955. if (field == "description")
  9956. lua_interface->SetStringValue(state, effect->description.c_str());
  9957. else if (field == "bullet")
  9958. lua_interface->SetInt32Value(state, effect->subbullet);
  9959. else if (field == "percentage")
  9960. lua_interface->SetInt32Value(state, effect->percentage);
  9961. else // no match
  9962. return 0;
  9963. return 1;
  9964. }
  9965. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9966. if (!lua_interface)
  9967. return 0;
  9968. LuaSpell* spell = lua_interface->GetSpell(state);
  9969. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9970. Spawn* target = lua_interface->GetSpawn(state, 3);
  9971. if (!target) {
  9972. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9973. return 0;
  9974. }
  9975. if (!target->IsEntity()) {
  9976. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9977. return 0;
  9978. }
  9979. if (!spell) {
  9980. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9981. return 0;
  9982. }
  9983. if (caster && !caster->IsEntity()) {
  9984. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9985. return 0;
  9986. }
  9987. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9988. return 0;
  9989. }
  9990. int EQ2Emu_lua_InWater(lua_State* state) {
  9991. if (!lua_interface)
  9992. return 0;
  9993. Spawn* spawn = lua_interface->GetSpawn(state);
  9994. lua_interface->ResetFunctionStack(state);
  9995. if (spawn) {
  9996. lua_interface->SetBooleanValue(state, spawn->InWater());
  9997. return 1;
  9998. }
  9999. return 0;
  10000. }
  10001. int EQ2Emu_lua_InLava(lua_State* state) {
  10002. if (!lua_interface)
  10003. return 0;
  10004. Spawn* spawn = lua_interface->GetSpawn(state);
  10005. lua_interface->ResetFunctionStack(state);
  10006. if (spawn) {
  10007. lua_interface->SetBooleanValue(state, spawn->InLava());
  10008. return 1;
  10009. }
  10010. return 0;
  10011. }
  10012. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10013. if (!lua_interface)
  10014. return 0;
  10015. Spawn* attacker = lua_interface->GetSpawn(state);
  10016. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10017. int8 type = lua_interface->GetInt8Value(state, 3);
  10018. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10019. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10020. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10021. string spell_name = lua_interface->GetStringValue(state, 7);
  10022. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10023. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10024. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10025. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10026. lua_interface->ResetFunctionStack(state);
  10027. if (!attacker) {
  10028. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10029. return 0;
  10030. }
  10031. if (!attacker->IsEntity()) {
  10032. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10033. return 0;
  10034. }
  10035. if (!victim) {
  10036. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10037. return 0;
  10038. }
  10039. if (!victim->IsEntity()) {
  10040. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10041. return 0;
  10042. }
  10043. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10044. return 0;
  10045. }
  10046. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10047. if (!lua_interface)
  10048. return 0;
  10049. Spawn* spawn = lua_interface->GetSpawn(state);
  10050. lua_interface->ResetFunctionStack(state);
  10051. if (spawn) {
  10052. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10053. return 1;
  10054. }
  10055. return 0;
  10056. }
  10057. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10058. if (!lua_interface)
  10059. return 0;
  10060. Spawn* spawn = lua_interface->GetSpawn(state);
  10061. bool invul = lua_interface->GetBooleanValue(state, 2);
  10062. lua_interface->ResetFunctionStack(state);
  10063. if (spawn) {
  10064. spawn->SetInvulnerable(invul);
  10065. }
  10066. return 0;
  10067. }
  10068. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10069. if (!lua_interface)
  10070. return 0;
  10071. string category = lua_interface->GetStringValue(state);
  10072. string name = lua_interface->GetStringValue(state, 2);
  10073. lua_interface->ResetFunctionStack(state);
  10074. Rule *ret = 0;
  10075. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10076. lua_interface->SetBooleanValue(state, ret->GetBool());
  10077. return 1;
  10078. }
  10079. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10080. return 0;
  10081. }
  10082. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10083. if (!lua_interface)
  10084. return 0;
  10085. string category = lua_interface->GetStringValue(state);
  10086. string name = lua_interface->GetStringValue(state, 2);
  10087. lua_interface->ResetFunctionStack(state);
  10088. Rule *ret = 0;
  10089. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10090. lua_interface->SetInt32Value(state, ret->GetInt32());
  10091. return 1;
  10092. }
  10093. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10094. return 0;
  10095. }
  10096. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10097. if (!lua_interface)
  10098. return 0;
  10099. string category = lua_interface->GetStringValue(state);
  10100. string name = lua_interface->GetStringValue(state, 2);
  10101. lua_interface->ResetFunctionStack(state);
  10102. Rule *ret = 0;
  10103. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10104. lua_interface->SetFloatValue(state, ret->GetFloat());
  10105. return 1;
  10106. }
  10107. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10108. return 0;
  10109. }
  10110. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10111. if (!lua_interface)
  10112. return 0;
  10113. Spawn* spawn = lua_interface->GetSpawn(state);
  10114. string type = lua_interface->GetStringValue(state, 2);
  10115. lua_interface->ResetFunctionStack(state);
  10116. if (spawn) {
  10117. int res = 1;
  10118. boost::to_lower(type);
  10119. if(type == "assigned_aa")
  10120. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10121. else if ( type == "unassigned_aa")
  10122. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10123. else if ( type == "assigned_tradeskill_aa")
  10124. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10125. else if ( type == "unassigned_tradeskill_aa")
  10126. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10127. else if ( type == "assigned_prestige_aa")
  10128. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10129. else if ( type == "unassigned_prestige_aa")
  10130. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10131. else if ( type == "assigned_tradeskill_prestige_aa")
  10132. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10133. else if ( type == "unassigned_tradeskill_prestige_aa")
  10134. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10135. else
  10136. res = 0;
  10137. return res;
  10138. }
  10139. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10140. return 0;
  10141. }
  10142. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10143. if (!lua_interface)
  10144. return 0;
  10145. Spawn* spawn = lua_interface->GetSpawn(state);
  10146. string type = lua_interface->GetStringValue(state, 2);
  10147. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10148. lua_interface->ResetFunctionStack(state);
  10149. if (spawn) {
  10150. boost::to_lower(type);
  10151. if(type == "assigned_aa")
  10152. spawn->SetAssignedAA((sint16)value);
  10153. else if ( type == "unassigned_aa")
  10154. spawn->SetUnassignedAA((sint16)value);
  10155. else if ( type == "assigned_tradeskill_aa")
  10156. spawn->SetTradeskillAA((sint16)value);
  10157. else if ( type == "unassigned_tradeskill_aa")
  10158. spawn->SetUnassignedTradeskillAA((sint16)value);
  10159. else if ( type == "assigned_prestige_aa")
  10160. spawn->SetPrestigeAA((sint16)value);
  10161. else if ( type == "unassigned_prestige_aa")
  10162. spawn->SetUnassignedPrestigeAA((sint16)value);
  10163. else if ( type == "assigned_tradeskill_prestige_aa")
  10164. spawn->SetTradeskillPrestigeAA((sint16)value);
  10165. else if ( type == "unassigned_tradeskill_prestige_aa")
  10166. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10167. if(spawn->IsPlayer())
  10168. ((Player*)spawn)->SetCharSheetChanged(true);
  10169. }
  10170. return 0;
  10171. }
  10172. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10173. if (!lua_interface)
  10174. return 0;
  10175. string titleName = lua_interface->GetStringValue(state);
  10176. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10177. lua_interface->ResetFunctionStack(state);
  10178. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10179. lua_interface->SetSInt32Value(state, index);
  10180. return 1;
  10181. }
  10182. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10183. if (!lua_interface)
  10184. return 0;
  10185. Spawn* spawn = lua_interface->GetSpawn(state);
  10186. string titleName = lua_interface->GetStringValue(state, 2);
  10187. lua_interface->ResetFunctionStack(state);
  10188. if(!spawn->IsPlayer())
  10189. {
  10190. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10191. lua_interface->SetSInt32Value(state, -1);
  10192. return 1;
  10193. }
  10194. Player* player = (Player*)spawn;
  10195. // check if player already has the title, don't need to add twice
  10196. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10197. if ( playerHasTitle)
  10198. {
  10199. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10200. return 1;
  10201. }
  10202. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10203. if(!title)
  10204. {
  10205. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10206. lua_interface->SetSInt32Value(state, -1);
  10207. return 1;
  10208. }
  10209. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10210. if(returnIdx < 0)
  10211. {
  10212. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10213. }
  10214. lua_interface->SetSInt32Value(state, returnIdx);
  10215. player->GetClient()->SendTitleUpdate();
  10216. return 1;
  10217. }
  10218. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10219. if (!lua_interface)
  10220. return 0;
  10221. Spawn* spawn = lua_interface->GetSpawn(state);
  10222. string titleName = lua_interface->GetStringValue(state, 2);
  10223. lua_interface->ResetFunctionStack(state);
  10224. if(!spawn->IsPlayer())
  10225. {
  10226. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10227. return 0;
  10228. }
  10229. Player* player = (Player*)spawn;
  10230. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10231. if(!title)
  10232. {
  10233. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10234. return 0;
  10235. }
  10236. if(title->GetPrefix())
  10237. {
  10238. 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());
  10239. return 0;
  10240. }
  10241. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10242. player->GetClient()->SendTitleUpdate();
  10243. return 1;
  10244. }
  10245. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10246. if (!lua_interface)
  10247. return 0;
  10248. Spawn* spawn = lua_interface->GetSpawn(state);
  10249. string titleName = lua_interface->GetStringValue(state, 2);
  10250. lua_interface->ResetFunctionStack(state);
  10251. if(!spawn->IsPlayer())
  10252. {
  10253. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10254. return 0;
  10255. }
  10256. Player* player = (Player*)spawn;
  10257. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10258. if(!title)
  10259. {
  10260. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10261. return 0;
  10262. }
  10263. if(!title->GetPrefix())
  10264. {
  10265. 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());
  10266. return 0;
  10267. }
  10268. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10269. player->GetClient()->SendTitleUpdate();
  10270. return 1;
  10271. }
  10272. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10273. if (!lua_interface)
  10274. return 0;
  10275. Spawn* spawn = lua_interface->GetSpawn(state);
  10276. lua_interface->ResetFunctionStack(state);
  10277. if(!spawn->IsPlayer())
  10278. {
  10279. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10280. return 0;
  10281. }
  10282. Player* player = (Player*)spawn;
  10283. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10284. player->GetClient()->SendTitleUpdate();
  10285. return 1;
  10286. }
  10287. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10288. if (!lua_interface)
  10289. return 0;
  10290. Spawn* spawn = lua_interface->GetSpawn(state);
  10291. lua_interface->ResetFunctionStack(state);
  10292. if(!spawn->IsPlayer())
  10293. {
  10294. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10295. return 0;
  10296. }
  10297. Player* player = (Player*)spawn;
  10298. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10299. player->GetClient()->SendTitleUpdate();
  10300. return 1;
  10301. }
  10302. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10303. if (!lua_interface)
  10304. return 0;
  10305. Spawn* spawn = lua_interface->GetSpawn(state);
  10306. string field = lua_interface->GetStringValue(state, 2);
  10307. lua_interface->ResetFunctionStack(state);
  10308. if(!spawn || !spawn->IsEntity())
  10309. {
  10310. 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));
  10311. return 0;
  10312. }
  10313. Entity* ent = (Entity*)spawn;
  10314. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10315. return 1;
  10316. }
  10317. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10318. if (!lua_interface)
  10319. return 0;
  10320. Spawn* spawn = lua_interface->GetSpawn(state);
  10321. string field = lua_interface->GetStringValue(state, 2);
  10322. lua_interface->ResetFunctionStack(state);
  10323. if(!spawn || !spawn->IsEntity())
  10324. {
  10325. 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));
  10326. return 0;
  10327. }
  10328. Entity* ent = (Entity*)spawn;
  10329. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10330. return 1;
  10331. }
  10332. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10333. if (!lua_interface)
  10334. return 0;
  10335. Spawn* spawn = lua_interface->GetSpawn(state);
  10336. string field = lua_interface->GetStringValue(state, 2);
  10337. lua_interface->ResetFunctionStack(state);
  10338. if(!spawn || !spawn->IsEntity())
  10339. {
  10340. 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));
  10341. return 0;
  10342. }
  10343. Entity* ent = (Entity*)spawn;
  10344. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10345. return 1;
  10346. }
  10347. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10348. if (!lua_interface)
  10349. return 0;
  10350. Spawn* spawn = lua_interface->GetSpawn(state);
  10351. string field = lua_interface->GetStringValue(state, 2);
  10352. lua_interface->ResetFunctionStack(state);
  10353. if(!spawn || !spawn->IsEntity())
  10354. {
  10355. 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));
  10356. return 0;
  10357. }
  10358. Entity* ent = (Entity*)spawn;
  10359. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10360. return 1;
  10361. }
  10362. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10363. if (!lua_interface)
  10364. return 0;
  10365. Spawn* spawn = lua_interface->GetSpawn(state);
  10366. string field = lua_interface->GetStringValue(state, 2);
  10367. string value = lua_interface->GetStringValue(state, 3);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if(!spawn || !spawn->IsEntity())
  10370. {
  10371. 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));
  10372. return 0;
  10373. }
  10374. Entity* ent = (Entity*)spawn;
  10375. bool set_ = ent->SetInfoStructString(field, value);
  10376. lua_interface->SetBooleanValue(state, set_);
  10377. return 1;
  10378. }
  10379. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10380. if (!lua_interface)
  10381. return 0;
  10382. Spawn* spawn = lua_interface->GetSpawn(state);
  10383. string field = lua_interface->GetStringValue(state, 2);
  10384. int64 value = lua_interface->GetInt64Value(state, 3);
  10385. lua_interface->ResetFunctionStack(state);
  10386. if(!spawn || !spawn->IsEntity())
  10387. {
  10388. 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));
  10389. return 0;
  10390. }
  10391. Entity* ent = (Entity*)spawn;
  10392. bool set_ = ent->SetInfoStructUInt(field, value);
  10393. lua_interface->SetBooleanValue(state, set_);
  10394. return 1;
  10395. }
  10396. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10397. if (!lua_interface)
  10398. return 0;
  10399. Spawn* spawn = lua_interface->GetSpawn(state);
  10400. string field = lua_interface->GetStringValue(state, 2);
  10401. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10402. lua_interface->ResetFunctionStack(state);
  10403. if(!spawn || !spawn->IsEntity())
  10404. {
  10405. 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));
  10406. return 0;
  10407. }
  10408. Entity* ent = (Entity*)spawn;
  10409. bool set_ = ent->SetInfoStructSInt(field, value);
  10410. lua_interface->SetBooleanValue(state, set_);
  10411. return 1;
  10412. }
  10413. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10414. if (!lua_interface)
  10415. return 0;
  10416. Spawn* spawn = lua_interface->GetSpawn(state);
  10417. string field = lua_interface->GetStringValue(state, 2);
  10418. float value = lua_interface->GetFloatValue(state, 3);
  10419. lua_interface->ResetFunctionStack(state);
  10420. if(!spawn || !spawn->IsEntity())
  10421. {
  10422. 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));
  10423. return 0;
  10424. }
  10425. Entity* ent = (Entity*)spawn;
  10426. bool set_ = ent->SetInfoStructFloat(field, value);
  10427. lua_interface->SetBooleanValue(state, set_);
  10428. return 1;
  10429. }
  10430. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10431. if (!lua_interface)
  10432. return 0;
  10433. Spawn* spawn = lua_interface->GetSpawn(state);
  10434. bool value = lua_interface->GetBooleanValue(state, 2);
  10435. lua_interface->ResetFunctionStack(state);
  10436. if(!spawn || !spawn->IsPlayer())
  10437. {
  10438. 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));
  10439. return 0;
  10440. }
  10441. ((Player*)spawn)->SetCharSheetChanged(value);
  10442. return 0;
  10443. }
  10444. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10445. if (!lua_interface)
  10446. return 0;
  10447. Spawn* spawn = lua_interface->GetSpawn(state);
  10448. std::string fromName = lua_interface->GetStringValue(state, 2);
  10449. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10450. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10451. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10452. int32 copper = lua_interface->GetInt32Value(state, 6);
  10453. int32 silver = lua_interface->GetInt32Value(state, 7);
  10454. int32 gold = lua_interface->GetInt32Value(state, 8);
  10455. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10456. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10457. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10458. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10459. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10460. lua_interface->ResetFunctionStack(state);
  10461. if(!spawn || !spawn->IsPlayer())
  10462. {
  10463. 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));
  10464. lua_interface->SetBooleanValue(state, false);
  10465. return 1;
  10466. }
  10467. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10468. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10469. lua_interface->SetBooleanValue(state, true);
  10470. return 1;
  10471. }
  10472. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10473. if (!lua_interface)
  10474. return 0;
  10475. int32 char_id = lua_interface->GetInt32Value(state);
  10476. std::string fromName = lua_interface->GetStringValue(state, 2);
  10477. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10478. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10479. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10480. int32 copper = lua_interface->GetInt32Value(state, 6);
  10481. int32 silver = lua_interface->GetInt32Value(state, 7);
  10482. int32 gold = lua_interface->GetInt32Value(state, 8);
  10483. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10484. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10485. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10486. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10487. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10488. lua_interface->ResetFunctionStack(state);
  10489. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10490. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10491. lua_interface->SetBooleanValue(state, true);
  10492. return 1;
  10493. }
  10494. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10495. Spawn* widget;
  10496. if (lua_interface) {
  10497. widget = lua_interface->GetSpawn(state);
  10498. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10499. lua_interface->ResetFunctionStack(state);
  10500. if (widget && widget->IsWidget())
  10501. {
  10502. ((Widget*)widget)->OpenDoor();
  10503. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10504. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10505. }
  10506. else
  10507. 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));
  10508. }
  10509. return 0;
  10510. }
  10511. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10512. Spawn* widget;
  10513. if (lua_interface) {
  10514. widget = lua_interface->GetSpawn(state);
  10515. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10516. lua_interface->ResetFunctionStack(state);
  10517. if (widget && widget->IsWidget())
  10518. {
  10519. ((Widget*)widget)->CloseDoor();
  10520. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10521. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10522. }
  10523. else
  10524. 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));
  10525. }
  10526. return 0;
  10527. }
  10528. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10529. if (!lua_interface)
  10530. return 0;
  10531. Spawn* widget = lua_interface->GetSpawn(state);
  10532. lua_interface->ResetFunctionStack(state);
  10533. if (widget && widget->IsWidget())
  10534. {
  10535. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10536. return 1;
  10537. }
  10538. return 0;
  10539. }
  10540. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10541. if (!lua_interface)
  10542. return 0;
  10543. sint32 min = lua_interface->GetSInt32Value(state);
  10544. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10545. lua_interface->ResetFunctionStack(state);
  10546. sint32 result = MakeRandomInt(min, max);
  10547. lua_interface->SetSInt32Value(state, result);
  10548. return 1;
  10549. }
  10550. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10551. if (!lua_interface)
  10552. return 0;
  10553. float min = lua_interface->GetFloatValue(state);
  10554. float max = lua_interface->GetFloatValue(state, 2);
  10555. lua_interface->ResetFunctionStack(state);
  10556. float result = MakeRandomFloat(min, max);
  10557. lua_interface->SetFloatValue(state, result);
  10558. return 1;
  10559. }
  10560. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10561. if (!lua_interface)
  10562. return 0;
  10563. Spawn* spawn = lua_interface->GetSpawn(state);
  10564. int32 value = lua_interface->GetInt32Value(state, 2);
  10565. lua_interface->ResetFunctionStack(state);
  10566. if(!spawn)
  10567. {
  10568. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10569. lua_interface->SetBooleanValue(state, false);
  10570. return 1;
  10571. }
  10572. spawn->AddIconValue(value);
  10573. lua_interface->SetBooleanValue(state, true);
  10574. return 1;
  10575. }
  10576. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10577. if (!lua_interface)
  10578. return 0;
  10579. Spawn* spawn = lua_interface->GetSpawn(state);
  10580. int32 value = lua_interface->GetInt32Value(state, 2);
  10581. lua_interface->ResetFunctionStack(state);
  10582. if(!spawn)
  10583. {
  10584. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10585. lua_interface->SetBooleanValue(state, false);
  10586. return 1;
  10587. }
  10588. spawn->RemoveIconValue(value);
  10589. lua_interface->SetBooleanValue(state, true);
  10590. return 1;
  10591. }
  10592. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10593. Spawn* npc = lua_interface->GetSpawn(state);
  10594. lua_interface->ResetFunctionStack(state);
  10595. if (npc && npc->IsNPC()) {
  10596. NPC* shard = (NPC*)npc;
  10597. int32 shardid = shard->GetShardID();
  10598. lua_interface->SetInt32Value(state, shardid);
  10599. return 1;
  10600. }
  10601. lua_interface->SetInt32Value(state, 0);
  10602. return 1;
  10603. }
  10604. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10605. Spawn* npc = lua_interface->GetSpawn(state);
  10606. lua_interface->ResetFunctionStack(state);
  10607. if (npc && npc->IsNPC()) {
  10608. NPC* shard = (NPC*)npc;
  10609. int32 charid = shard->GetShardCharID();
  10610. lua_interface->SetInt32Value(state, charid);
  10611. return 1;
  10612. }
  10613. lua_interface->SetInt32Value(state, 0);
  10614. return 1;
  10615. }
  10616. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10617. Spawn* npc = lua_interface->GetSpawn(state);
  10618. lua_interface->ResetFunctionStack(state);
  10619. if (npc && npc->IsNPC()) {
  10620. NPC* shard = (NPC*)npc;
  10621. int64 timestamp = shard->GetShardCreatedTimestamp();
  10622. lua_interface->SetSInt64Value(state, timestamp);
  10623. return 1;
  10624. }
  10625. lua_interface->SetSInt64Value(state, 0);
  10626. return 1;
  10627. }
  10628. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10629. if (!lua_interface)
  10630. return 0;
  10631. int32 shardid = lua_interface->GetInt32Value(state);
  10632. lua_interface->ResetFunctionStack(state);
  10633. if(shardid < 1)
  10634. lua_interface->SetBooleanValue(state, false);
  10635. else
  10636. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10637. return 1;
  10638. }
  10639. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10640. if (!lua_interface)
  10641. return 0;
  10642. Spawn* spawn = lua_interface->GetSpawn(state);
  10643. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10644. if (spawn) {
  10645. spawn->PauseMovement(delay_in_ms);
  10646. }
  10647. lua_interface->ResetFunctionStack(state);
  10648. return 0;
  10649. }
  10650. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10651. if (!lua_interface)
  10652. return 0;
  10653. Spawn* spawn = lua_interface->GetSpawn(state);
  10654. if (spawn) {
  10655. spawn->StopMovement();
  10656. }
  10657. lua_interface->ResetFunctionStack(state);
  10658. return 0;
  10659. }
  10660. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10661. Player* player = (Player*)lua_interface->GetSpawn(state);
  10662. int8 level = lua_interface->GetInt8Value(state, 2);
  10663. lua_interface->ResetFunctionStack(state);
  10664. if (player && player->IsPlayer() && level > 0) {
  10665. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10666. return 1;
  10667. }
  10668. return 0;
  10669. }
  10670. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10671. Player* player = (Player*)lua_interface->GetSpawn(state);
  10672. int8 level = lua_interface->GetInt8Value(state, 2);
  10673. lua_interface->ResetFunctionStack(state);
  10674. if (player && player->IsPlayer() && level > 0) {
  10675. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10676. return 1;
  10677. }
  10678. return 0;
  10679. }
  10680. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10681. ZoneServer* zone = lua_interface->GetZone(state);
  10682. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10683. lua_interface->ResetFunctionStack(state);
  10684. if (zone) {
  10685. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10686. if (spawn) {
  10687. lua_interface->SetSpawnValue(state, spawn);
  10688. return 1;
  10689. }
  10690. }
  10691. return 0;
  10692. }
  10693. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10694. if (!lua_interface)
  10695. return 0;
  10696. Spawn* spawn = lua_interface->GetSpawn(state);
  10697. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10698. lua_interface->ResetFunctionStack(state);
  10699. bool res = false;
  10700. if(spawn && spawn->IsTransportSpawn())
  10701. {
  10702. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10703. spawn->SetRailID(rail_id);
  10704. res = true;
  10705. }
  10706. else if (!spawn) {
  10707. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10708. }
  10709. else if(!spawn->IsTransportSpawn()) {
  10710. 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());
  10711. }
  10712. lua_interface->SetBooleanValue(state, res);
  10713. return 1;
  10714. }
  10715. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10716. if (!lua_interface)
  10717. return 0;
  10718. ZoneServer* zone = lua_interface->GetZone(state);
  10719. lua_interface->ResetFunctionStack(state);
  10720. if (zone) {
  10721. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10722. return 1;
  10723. }
  10724. return 0;
  10725. }
  10726. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10727. if (!lua_interface)
  10728. return 0;
  10729. Spawn* spawn = lua_interface->GetSpawn(state);
  10730. lua_interface->ResetFunctionStack(state);
  10731. if (spawn) {
  10732. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10733. return 1;
  10734. }
  10735. return 0;
  10736. }
  10737. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10738. if (!lua_interface)
  10739. return 0;
  10740. Spawn* player = lua_interface->GetSpawn(state);
  10741. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10742. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10743. lua_interface->ResetFunctionStack(state);
  10744. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10745. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10746. }
  10747. else if(!zoneID) {
  10748. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10749. }
  10750. else
  10751. {
  10752. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10753. return 1;
  10754. }
  10755. return 0;
  10756. }
  10757. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10758. if (!lua_interface)
  10759. return 0;
  10760. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10761. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10762. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10763. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10764. lua_interface->ResetFunctionStack(state);
  10765. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10766. world.GetWorldTimeStruct()->year = newYear;
  10767. world.GetWorldTimeStruct()->month = newMonth;
  10768. world.GetWorldTimeStruct()->hour = newHour;
  10769. world.GetWorldTimeStruct()->minute = newMinute;
  10770. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10771. return 0;
  10772. }
  10773. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10774. if (!lua_interface)
  10775. return 0;
  10776. lua_interface->ResetFunctionStack(state);
  10777. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10778. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10779. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10780. return 1;
  10781. }
  10782. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  10783. if (!lua_interface)
  10784. return 0;
  10785. lua_interface->ResetFunctionStack(state);
  10786. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10787. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  10788. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10789. return 1;
  10790. }
  10791. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  10792. if (!lua_interface)
  10793. return 0;
  10794. lua_interface->ResetFunctionStack(state);
  10795. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10796. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  10797. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10798. return 1;
  10799. }
  10800. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  10801. if (!lua_interface)
  10802. return 0;
  10803. lua_interface->ResetFunctionStack(state);
  10804. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10805. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  10806. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10807. return 1;
  10808. }
  10809. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  10810. if (!lua_interface)
  10811. return 0;
  10812. lua_interface->ResetFunctionStack(state);
  10813. world.SendTimeUpdate();
  10814. return 0;
  10815. }